The recording to Thingspeak suddenly stopped working. | ThingSpeak API | 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
The recording to Thingspeak suddenly stopped working.
No permission to create posts
February 7, 2019
1:09 pm
Avatar
pier
New Member
Members
Forum Posts: 2
Member Since:
February 7, 2019
sp_UserOfflineSmall Offline

My weather station on esp8266 saves data every 30 minutes to the Thingspeak server.
Today I noticed that the last data I have from 05-02-2019.
I did not change anything in the layout of the station or in the program.
Today I tried only with the new Write API Key but it did not do anything.
I do not know if this is a problem with Thingspeak server or my device, but as I wrote anything from my side I did not change.
You suggest where to look for a problem.

February 7, 2019
1:39 pm
Avatar
Vinod

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

We've seen several examples of code that did something like this:

void loop()
{
// read sensor value
if (client.connect(server,80))
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(h);
postStr += "&field2=";
postStr += String(t);
postStr += "

";
client.print("POST /update HTTP/1.1
");
client.print("Host: api.thingspeak.com
");
client.print("Connection: close
");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"
");
client.print("Content-Type: application/x-www-form-urlencoded
");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("
");
client.print(postStr);
}
client.stop();
delay(10000);
}

This code closes the TCPIP socket without waiting for a response from ThingSpeak or confirming that the data was indeed written. At the minimum, the code needs to be modified to something like this:

void loop()
if (client.connect(server,80))
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(h);
postStr += "&field2=";
postStr += String(t);
postStr += "

";
client.print("POST /update HTTP/1.1
");
client.print("Host: api.thingspeak.com
");
client.print("Connection: close
");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"
");
client.print("Content-Type: application/x-www-form-urlencoded
");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("
");
client.print(postStr);
}
delay(500); //<--- NOTICE NEW LINE OF CODE HERE !!!. YOU MAY NEED TO MODIFY THE DELAY BASED ON YOUR NETWORK CONNECTIVITY.
client.stop();
delay(10000);
}

Ideally, your code should be using the ThingSpeak library here: https://github.com/mathworks/thingspeak-arduino .
See installation instructions here: https://github.com/mathworks/thingspeak-arduino
Built in examples for ESP2866, NodeMCU, etc. here: https://github.com/mathworks/thingspeak-arduino/tree/master/examples/ESP32

February 8, 2019
12:48 pm
Avatar
pier
New Member
Members
Forum Posts: 2
Member Since:
February 7, 2019
sp_UserOfflineSmall Offline

Thank you for your help.
Of course, it works after the change.
I wonder just why so many months worked properly and now it stopped suddenly?

February 8, 2019
1:00 pm
Avatar
Vinod

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

pier said
I wonder just why so many months worked properly and now it stopped suddenly?  

You can see details in this post.

February 13, 2019
1:43 am
Avatar
esridhar59
New Member
Members
Forum Posts: 2
Member Since:
February 13, 2019
sp_UserOfflineSmall Offline

Hi Vinod, Still I am facing the error, Not updated to thinkspeak, even after changes made as per your suggestion.
One thing i didn't do is, i am not using "thinkspeak.h" library. instead i am using
what to change here.

here is my code

#include "DHTesp.h"
#include
#include
DHTesp dht;

String apiKey = "88888888888888";
const char* ssid = "******";
const char* pass = "************";
const char* server = "api.thingspeak.com";
float humidity = dht.getHumidity();
float temperature = dht.getTemperature();

unsigned long previousMillis = 0;
const long interval = 2000;
WiFiClient client;

void setup()
{

previousMillis = millis();

Serial.begin(9600);
Serial.println();
Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");
dht.setup(5, DHTesp::DHT22);

Serial.print("Connecting to: ");
Serial.println(ssid);

WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED)
{
delay(100);
Serial.print("*");
}
Serial.println("");
Serial.println("***WiFi connected***");

}

void loop()
{
float humidity = dht.getHumidity();
float temperature = dht.getTemperature();

if ((millis () - previousMillis) >= interval) {

if(temperature >= 20)
{
Serial.println("10secs");
cloud();

previousMillis = millis();

}
}
}

void cloud()
{
float humidity = dht.getHumidity();
float temperature = dht.getTemperature();

if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
//String sendData = apiKey+"&field1="+String(temperature)+"

";
//String sendData = apiKey+"&field2="+String(humidity)+"

";
String sendData = apiKey;
sendData +="&field1=";
sendData += String(temperature);
sendData +="&field2=";
sendData += String(humidity);
sendData += "

";

//Serial.println(sendData);

client.print("POST /update HTTP/1.1
");
client.print("Host: api.thingspeak.com
");
client.print("Connection: close
");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"
");
client.print("Content-Type: application/x-www-form-urlencoded
");
client.print("Content-Length: ");
//client.print(sendData.length());
client.print(sendData.length());
client.print("

");
client.print(sendData);

Serial.print("temp: ");
Serial.print(temperature);
Serial.print("Humi: ");
Serial.print(humidity);
Serial.println("deg C. Connecting to Thingspeak..");
}
delay(500);
client.stop();

Serial.println("Sending....");

delay(10000);
}

February 13, 2019
3:01 pm
Avatar
Vinod

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

Sridhar,

Your code looks like one of the examples in the library:

https://github.com/mathworks/thingspeak-arduino/tree/master/examples/ESP8266/WriteMultipleFields

Why don't you try starting from there?

If you are unable to make that change, try increasing the delay(500) just before client.stop().

-Vinod

February 14, 2019
2:20 am
Avatar
esridhar59
New Member
Members
Forum Posts: 2
Member Since:
February 13, 2019
sp_UserOfflineSmall Offline

Thanks, the above code itself working, after increasing the delay(500) and i used delay as delay(1000) before client.stop().

Same code, i didn't use thinkspeak.h

-Sridhar

Forum Timezone: America/New_York

Most Users Ever Online: 166

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

porosh2019, KellyBrise, sunainakhanna, flail, sathwik, samlewis02

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457