Sending data to ThingSpeak API from device but channel is not updated -- what changed? | Page 2 | Announcements | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Sending data to ThingSpeak API from device but channel is not updated -- what changed?
No permission to create posts
January 23, 2019
4:10 pm
Avatar
Vinod

MathWorks
Members
Forum Posts: 305
Member Since:
May 1, 2016
sp_UserOfflineSmall Offline

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.

January 24, 2019
1:24 am
Avatar
Supawan
New Member
Members
Forum Posts: 3
Member Since:
January 23, 2019
sp_UserOfflineSmall Offline

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.

January 24, 2019
8:20 am
Avatar
algorythm
New Member
Members
Forum Posts: 1
Member Since:
January 24, 2019
sp_UserOfflineSmall Offline

Will likely take longer to fix them if they stop working, too bad I guess...

___________________________
This space for rent - not that you would rent it.

January 25, 2019
5:41 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 691
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

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/

January 28, 2019
7:52 am
Avatar
Supawan
New Member
Members
Forum Posts: 3
Member Since:
January 23, 2019
sp_UserOfflineSmall Offline

Hi estapels,

Thank you for your comment. There is no any number after CME ERROR:. There is comment „operation not allowed „. Anyway i will learn from your link.

Thank you

January 28, 2019
5:58 pm
Avatar
Vinod

MathWorks
Members
Forum Posts: 305
Member Since:
May 1, 2016
sp_UserOfflineSmall Offline

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.

February 8, 2019
11:18 am
Avatar
mikekgr

Silver
Members
Forum Posts: 5
Member Since:
January 4, 2019
sp_UserOfflineSmall Offline

Dear @Vinod are the new ThingSpeak rules are already in effect? I am asking this because I following your suggestions to comply with and all seams fine, so I need to know if we are now with the new environment...

Thanks!

February 8, 2019
12:01 pm
Avatar
Vinod

MathWorks
Members
Forum Posts: 305
Member Since:
May 1, 2016
sp_UserOfflineSmall Offline

@Mike : Yes, the infrastructural change went in on Tuesday, 02/05. If your channels are showing data being collected, you don't need to do anything more.

February 10, 2019
7:23 am
Avatar
mikekgr

Silver
Members
Forum Posts: 5
Member Since:
January 4, 2019
sp_UserOfflineSmall Offline

@Vinod very nice, yes all are working fine. Thanks for your instructions given.
Best Regards,
Mike Kranidis

No permission to create posts
Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
26 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:

Sahil Nair, ahancity, samexpert, Senseworks, h-kasiri, kleifimmakly

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457