Hi,
I suggest you to do one thing at a time and give up only if you can not make it work.
So, after making the changes in the shematic what have you observed?
Regarding the code, you have to take care of all the language specific issues yourselves, I may not be able to help you in this area.
For testing purpose, reduce your code, to send string " AT '' followed by 0x0d and check if you get "ok". This will show if the interface is working or not. Also for first testing, use only character level send receive functions.
Also note the following regarding your code:
After determining the switch is closed, and finishing the subsequent functions, you need to also wait for the switch to be opened as other wise for the same single closing, the functions may be done many times.
You also have to clear ok and ok1 after they are tested true.
I suppose you need to assign the strings to be sent to a character array to get '\0' character added at the end.
Regards,
Laktronics