coding connection issue | ThingSpeak API | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





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

Register Lost password?
sp_Feed sp_TopicIcon
coding connection issue
Avatar
mtmtntop
New Member
Forum Posts: 3
sp_UserOfflineSmall Offline
1
February 11, 2018 - 2:21 pm
sp_Permalink sp_Print

I am looking for some help with the coding to post to my channel.  This is a sketch to post a single value from a one wire network.  I have cut and pasted the code from here:

http://internetofthinking.blogspot.com/2016/02/upload-ds18b20-temperature-sensor-data.html

My serial monitor shows the temperature correctly and that the wifi is connected. It is just not posting to my channel on thingspeak

I know I can establish the connection from my sparkfun esp8266 because i ran this sketch from thingspeak and it posts correctly on the field 1 graph.  

https://www.mathworks.com/help/thingspeak/continuously-collect-data-and-bulk-update-a-thingspeak-channel-using-an-arduino-mkr1000-board-or-an-esp8266-board.html

Although these do entirely different things, I am not able to see why the temperature is not being posted to my channel from the first sketch I have listed above.  I have double (triple) checked my write api key, even tried resetting it with no success.  

Does anyone see any coding issues?  thanks

Avatar
cstapels
Moderator
Forum Posts: 158
sp_UserOfflineSmall Offline
2
February 13, 2018 - 3:21 pm
sp_Permalink sp_Print

Have a look at the soil monitor example, which shows how to use client commands to make HTTP requests. 

The ThingSpeak communication library makes it even easier to interact with ThingSpeak using your devices.  The proximity sensor example shows both reading and writing with ThingSpeak using the library.

The sample code you posted has an oddly formed POST string, but I tested your code removing the OneWire and DallasTemperature libraries and it still works for me.  I'm pretty sure I have tested using these libraries as well, but I did not test with your code.

In your sample code, postStr contains the API Key and then "field1=" and then data.  According to the doc page on writing data, the post string should begin with "field1=".  I have tested with an & in front, and this works too.  Even with the API key in the postStr, it worked for me to post to. my channel

 ... String postStr = apiKey;
   postStr += "&field1=";
....
Does the number of entries increase on your channel view?  You may be accidentally posting data that ThingSpeak thinks is a string and that is why you do not see it in your plot.

You can try exporting your data is there are entries that you do not see on the plot.

Also you can try removing the dallas libraries and posting a constant as a test.

"temp=123;"

Avatar
mtmtntop
New Member
Forum Posts: 3
sp_UserOfflineSmall Offline
3
February 17, 2018 - 11:46 am
sp_Permalink sp_Print

SOLVED WITH COMMENTS ABOUT LEARNING THE HARD WAY

You were right.  There wasn't anything wrong with the code taken from the website I referred to.  In the end, I started all  over, cut and pasted it and it worked.  Here are 2 things I came across that may help other totally inexperienced code writers like me.

1.  the thingspeak read and write keys USE BOTH "O" (the letter o) AND 0 (ZERO).  I only found this out by accident resetting my api codes and the new one had both characters.  If you work in the world of VIN numbers for cars, for example, the letter o is never used.  if it looks like an o its really a zero.  But as I found out, this is not a universal truth.

2.  If you are getting a "wifi connected " message on the serial monitor but nothing is happening on thingspeak, try inserting a piece of code that returns the response from thingspeak.  this may help point you in the right direction.  an example is below, taken from here:

https://www.mathworks.com/help/thingspeak/continuously-collect-data-and-bulk-update-a-thingspeak-channel-using-an-arduino-mkr1000-board-or-an-esp8266-board.html

// POST data to ThingSpeak
if (client.connect(server, 80)) {
client.println("POST /channels/418168/bulk_update.json HTTP/1.1"); //Replace YOUR-CHANNEL-ID with your ThingSpeak channel ID
client.println("Host: api.thingspeak.com");
client.println("User-Agent: mw.doc.bulk-update (Arduino ESP8266)");
client.println("Connection: close");
client.println("Content-Type: application/json");
client.println("Content-Length: "+data_length);
client.println();
client.println(data);
}
else {
Serial.println("Failure: Failed to connect to ThingSpeak");
}
delay(250); //Wait to receive the response
client.parseFloat();
String resp = String(client.parseInt());
Serial.println("Response code:"+resp); // Print the response code. 202 indicates that the server has accepted the response
jsonBuffer[0] = '['; // Reinitialize the jsonBuffer for next batch of data
jsonBuffer[1] = '\0';
lastConnectionTime = millis(); // Update the last connection time
}

thanks for the help

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
32 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

aogomaeqaza

ureomug

itixuwidouzuv

eilimir

memozupi

isejfujajku

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee