ESP8266 with mega and ThingSpeak | ThingSpeak Projects | 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
ESP8266 with mega and ThingSpeak
No permission to create posts
June 11, 2018
8:12 pm
Avatar
matheusdeop
New Member
Members
Forum Posts: 3
Member Since:
June 11, 2018
sp_UserOfflineSmall Offline

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)+")");
}
}

June 12, 2018
8:46 am
Avatar
cstapels
Moderator
Members


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

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

June 12, 2018
9:01 am
Avatar
matheusdeop
New Member
Members
Forum Posts: 3
Member Since:
June 11, 2018
sp_UserOfflineSmall Offline

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...

June 13, 2018
4:37 pm
Avatar
matheusdeop
New Member
Members
Forum Posts: 3
Member Since:
June 11, 2018
sp_UserOfflineSmall Offline

I am not understanding what is happening, yesterday it started updating again and today stopped. Do you have any clue about the root problem?

When I use a TCP conection the serial monitor do not print SUCCESS, but when I use UDP it prints but do not update thingspeak.

Forum Timezone: America/New_York

Most Users Ever Online: 114

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

gwenbk2, eloisedq3, AEtedesar, RichardWosus, Kellynapse, tejomaya

Administrators: Hans: 387, lee: 457