8:12 pm

June 11, 2018

I'm using an ESP8266 connected to a mega and sending data to ThingSpeak. However from a week ago the code stopped working, it was completely ok before.
The code I'm using is below. I updated the esp firmware to the latest version (2.2.1) and still is not updating my channel, even the return on the serial monitor show as successful.
I already tried to change the channel and the account but didn't work.
#define SSID "Matheus"
#define PASSWORD "XXXXXXX"
char thingSpeakAddress[] = "api.thingspeak.com";
String writeAPIKey = "XXXXXXXXXXXXXXX";
unsigned long intervalo = 15000;
unsigned long lastconection=0;
int failedCounter = 0;
#include "uartWIFI.h"
WIFI wifi;
void setup()
{
wifi.begin();
bool b = wifi.Initialize(STA, SSID, PASSWORD);
if(!b)
{
DebugSerial.println("Init error");
}
delay(8000);
String ipstring = wifi.showIP();
DebugSerial.println("My IP address:");
DebugSerial.println(ipstring);
String wifistring = wifi.showJAP();
DebugSerial.println(wifistring);
}
void loop()
{
if (lastconection+intervalo <= millis())
{
long tim = (millis()-lastconection);
Serial.println(tim);
lastconection=millis();
DebugSerial.println("thingspeak connect");
updateThingSpeak("field1=22");
}
}
void updateThingSpeak(String tsData)
{
if (wifi.newMux(1,thingSpeakAddress, 80))
{
wifi.Send("POST /update HTTP/1.1
");
wifi.Send("Host: api.thingspeak.com
");
wifi.Send("Connection: close
");
wifi.Send("X-THINGSPEAKAPIKEY: "+writeAPIKey+"
");
wifi.Send("Content-Type: application/x-www-form-urlencoded
");
wifi.Send("Content-Length: ");
wifi.Send(String(tsData.length()));
wifi.Send("
");
wifi.Send(tsData);
Serial.println("Success");
wifi.closeMux();
}
else
{
failedCounter++;
Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");
}
}
8:46 am


Moderators
March 7, 2017

The code looks fine to me, unfortunately I don't have the exact hardware to test with. I have several channels that update from a ESP8266, some from an -01 or some from node MCU, and they are all still working.
Using the same network, are you able to update the channel from your computer, for example in a browser window? Use the Write API key.
Try this format: https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXXXXX&field1=123
9:01 am

June 11, 2018

cstapels said
The code looks fine to me, unfortunately I don't have the exact hardware to test with. I have several channels that update from a ESP8266, some from an -01 or some from node MCU, and they are all still working.
Using the same network, are you able to update the channel from your computer, for example in a browser window? Use the Write API key.
Try this format: https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXXXXX&field1=123
Yes, I tried this yesterday and thingspeak received the data. I really don't know what is happening...
Most Users Ever Online: 166
Currently Online:
17 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:
Zain-Ul-Abidin, wellbeingcentresuk, Vamsi, frankmehlhop, bhumin, dennysrodialahModerators: cstapels: 460
Administrators: Hans: 405, lee: 457