coding connection issue | ThingSpeak API | Forum


Please consider registering

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
coding connection issue
No permission to create posts
February 11, 2018
2:21 pm
New Member
Forum Posts: 3
Member Since:
February 8, 2018
sp_UserOfflineSmall Offline

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:

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.

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

February 13, 2018
3:21 pm

Forum Posts: 258
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

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.


February 17, 2018
11:46 am
New Member
Forum Posts: 3
Member Since:
February 8, 2018
sp_UserOfflineSmall Offline


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:

// 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("User-Agent: mw.doc.bulk-update (Arduino ESP8266)");
client.println("Connection: close");
client.println("Content-Type: application/json");
client.println("Content-Length: "+data_length);
else {
Serial.println("Failure: Failed to connect to ThingSpeak");
delay(250); //Wait to receive the response
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:
22 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

JamesVex, meghanfr69, raqueldk69, soniafw2, vitalijDrine, JosephAmapy

Administrators: Hans: 387, lee: 457