4:10 pm


MathWorks
May 1, 2016

A lot of the code pattern that we see the problem with looks like this:
WiFiClient client;
...
void loop() {
if (client.connect(server, 80)) {
// Read some sensor
// Construct API request body
String body = "field1=";
body += String(sensorValue);
client.println("POST /update HTTP/1.1");
client.println("Host: api.thingspeak.com");
client.println("Connection: close");
client.println("X-THINGSPEAKAPIKEY: " + writeAPIKey);
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Content-Length: " + String(body.length()));
client.println("");
client.print(body);
}
client.stop();
}
Notice the problem is that there is zero time between the POST request and the closing of the connection using client.stop(). Ideally, the code would read back the response and confirm it is a HTTP 200 status code.
This is done in the ThingSpeak library (https://github.com/mathworks/thingspeak-arduino) in the getHTTPResponse() method. See https://github.com/mathworks/thingspeak-arduino/blob/master/src/ThingSpeak.h for the implementation.
If that is not do-able, a simple insertion of delay(250); immediately after client.print(body); should suffice. Again, the delay is not the solution I would recommend, but, it is the smallest code change required to prevent the above code pattern from running into trouble.
1:24 am

January 23, 2019

Hello Vinod,
Thank you for your suggestion. For the first suggestion I purchased license already. I use SIM900 module and AT command to send data to platform it is reconnected every loop so sometimes I got +CME ERROR: operation not allowed in the state of "mySerial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");". I use dalay time 2000 sec. i tried to figure out this issue but i still got this error somtimes. Please give me any recommend.
Thank you.
8:20 am
January 24, 2019

5:41 pm


Moderators
March 7, 2017

Hi Supawan,
I think there is supposed to be an error number after +CME ERROR:
That will tell you what the problem is. It could be that your cell service is not reliable.
Here is a list of error codes: https://www.smssolutions.net/tutorials/gsm/gsmerrorcodes/
7:52 am

January 23, 2019

5:58 pm


MathWorks
May 1, 2016

Supawan,
I think you will need to contact your SIM card vendor. Everything I find on Google (https://www.google.com/search?q=%2BCME+ERROR%3A+operation+not+allowed) tells me that this is likely from your GSM service or modem.
11:18 am


Silver
January 4, 2019

Most Users Ever Online: 166
Currently Online:
19 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
rw950431: 272
Vinod: 240
piajola: 95
turgo: 70
vespapierre: 63
Adarsh_Murthy: 62
Member Stats:
Guest Posters: 1
Members: 8665
Moderators: 1
Admins: 2
Forum Stats:
Groups: 3
Forums: 14
Topics: 1600
Posts: 5760
Newest Members:
estebanmateo93, mikewrite, onlinebusiness, winzy99, Zark_zeugan, StefanWiModerators: cstapels: 460
Administrators: Hans: 405, lee: 457