I am sending temperature values to the adafruit server and its working fine. By using TCP/IP commands I’m continuously sending these commands by using Arduino to see values/data on the server.
My question is, when I’m sending some values or data from the server to sim900A then I’m not able to see data on my Arduino. Which AT commands are used to see whether sim900A receives data or not?
I know how to send data to the server but don’t know how to retrieve data that is coming on sim900A.
Your help is appreciable.
If you are using TCP/IP commands, those detailed in this document, after you send all your characters to the AT+CIPSEND, you’ll get the following responses in order:
- “SEND OK” (followed by an enter)
- “THE SERVER RESPONSE” (followed by another enter)
You can see an example in page 7 of the mentioned document.
Thank you for your reply.
But still confusion, I’m explaining my project. Let me know your opinion about that I really want help from you.
In my project I’m sending pressure sensor value to the server and as soon as any condition match the server will send particular data to the gsm module in order to do a particular task but I’m not able to write code to receive data from the server. I read the document suggested by you and I found command on page no 24. but I don’t know how to write a program for that in Arduino UNO. In a document on-page, no 24 both automatic and manual methods are shown but not able to understand how to do that.
my question is if server sends data to the GSM module then that data will come to module but if suppose controller doing other tasks then how the controller would know data is available or not? As soon as data come to the GSM module then it will generate an interrupt or something else?
I m really confused here, please suggest me a correct way to do that.
your any help is appreciable.
Ok, for what you are trying to do, it would be easier to use the HTTP commands detailed in this document (examples of GET on page 8 and POST on page 9, but you’ll need to first establish a connection following the “bearer configure” steps detailed on page 8).
You can check the tutorials of @RaviPujar for example, he has made lots of tutorials on the SIM800/SIM900. There you can get the details, but the general idea would be something like:
- Connect the GSM module and the Arduino by a Serial connection. Considerations on this regard:
- Since the Arduino has only one serial port, and it is conneted to the USB port, you’ll have to use the SoftwareSerial library to create a virtual or “fake” serial port that you can use with the GSM Module.
- The Arduino uses a 5v logic, and your module probably uses a 2.8v logic, this two are not directly compatible, you’ll have to put a circuit that converts the voltages in between the two ports. A good example of such a circuit is proposed by the manufacturer of the SIM800/900 in this document, on page 32 (figures 22 and 23). What that document refers to as “VDDEXT” is any 2.8v source, “Module” would be the GSM module, and “DTE” would be your Arduino UNO.
- Operate the GSM module using the Arduino to send AT commands and waiting for the response of the module at each step. This is done by just writing to, and reading from, the virtual serial port created with the SoftwareSerial library.
- By writing and reading to and from the SIM800/900, you’ll do the following actions:
- Connect to the cellular network.
- Initialize the HTTP interface of the GSM module.
- Define the header properties of the request you are trying to make to the server. Such as URL, port, etc.
- If you are doing a GET request, just send the request. The GSM module will store the server response as soon as it finishes downloading it.
- If you are doing a POST request, you’ll first need to write the body of your request, then you send it. The rest is exactly the same as with a GET request.
- You read the response from the server stored in the GSM module. This is done with its own AT commands, and there is no need to hurry, as it is stored in the module for you to access whenever you see fit.
- Finally, close the HTTP interface so it can be ready to start a new request.
- Rinse and repeat.
I have an algorithm regarding the sim808 module and want to convert that code in pure c or c++ code.
- send “AT” command to module.
- wait until valid “OK” response from the module.
- If a response is valid then execute code otherwise do nothing.
My purpose of c or c++ code is when I switch to another controller I have to change only serial (usart ) setting and the rest of the code will remain same.
As a beginnner i need suggestion on it. I tried it on Arduino UNO but not able to write proper code.
SoftwareSerial sim(6,7);//rx tx
char received_data; //variable to store read data
if(sim.available()>0) //check for any data received
received_data = sim.read(); //read received data
Serial.print("received data is: ");
Serial.println(received_data); //display received data
I tried this code to write in c but not successful in it. Above code working but output response is not proper I dont know why reponse goes to another line each time?
I was thinking like this function to write,
void send_command_response(“AT”, “OK”);
Whenever I want to send command I just need to change command and response from function void send_command_response(“AT”, “OK”); and the rest of the work will be done by a controller according to condition.
Your help would be appreciated.
Hello, sorry for the delayed response…
Your problem happens because you are using
Serial.println(), which does write a new line after sending the content you pass to the function.
Keep in mind that your
received_data variable is of type char, this means that you can only store a single ASCII character in it, not a whole string. Since you are working with an Arduino UNO (which has very limited memory), I suggest you to work with what is called “C style strings”; that is, a char array. An example of a declaration of such a string is
#define MAX_LENGTH 128
Working with C-style strings is pretty involved, so I strongly recommend you to search and learn about it first, then come back to your project. Some tips that might help you:
- Check this Wiki with general info on C-style string manipulation functions
This is a pretty good website with concise references to all the functions you’ll need.
- The most practical way to pass any array in C++ is generally to pass a pointer to that array. Please check some tutorials on working with pointers, as the syntax is a little confusing at first.
- If your function expects a pointer and you give it an array, C++ will automatically convert or “degrade” it to a pointer. This mainly means that inside the function you have no built-in way to know how long the array is, so you’ll have to pass the length as a second parameter.
- Although the C-style array “way of working” expects the last character to be a
'\0', some functions return strings without it, so read carefully the documentation on each function to avoid problems.
- C-style strings require that you define a clear upper limit on how many characters it can hold. This is defined by the
MAX_LENGTH macro in the example above. This upper limit is usually refered to as the “size” of the array. The actual string might be shorter than this size, as its end is only defined by the first
'\0' character. The amount of characters the actual string has is refered to as the “length” of the string. DO NOT confuse both terms.
- Typical problems when working with C-style strings (due to human error) include:
- Reading beyond the length of the string, usually because there is a lack of a terminating
'\0' character or you are trying to read an index on the string that is larger than the actual size of the string.
- Missed-by-one errors, usually because one manually moves the pointer back or forward, or you forget to account for the terminating
That should be all to start with C-strings, let us know how you go from there.