Go Down

Topic: ESP8266 with mega and ThingSpeak (Read 695 times) previous topic - next topic

matheusdeop

  I'm using an ESP8266 connected and a mega to send 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.

#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(0,thingSpeakAddress, 80))
{
wifi.Send("POST /update HTTP/1.1\n");
wifi.Send("Host: api.thingspeak.com\n");
wifi.Send("Connection: close\n");
wifi.Send("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n");
wifi.Send("Content-Type: application/x-www-form-urlencoded\n");
wifi.Send("Content-Length: ");
wifi.Send(String(tsData.length()));
wifi.Send("\n\n");
wifi.Send(tsData);
Serial.println("Success");
wifi.closeMux();
}
else
{
failedCounter++;
Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");
}
}





matheusdeop

I am sorry, instead:
if (wifi.newMux(0,thingSpeakAddress, 80))

I am using:
if (wifi.newMux(1,thingSpeakAddress, 80))

Nick_Pyner

However from a week ago the code stopped working, it was completely ok before.
So, have you made any change to the code to cause that?
Have you tried a reset to see if it would work OK again?
If so, what does failedCounter say?
Is that code complete?
What is the objective?

matheusdeop

So, have you made any change to the code to cause that? Nope, I've used the same code.
Have you tried a reset to see if it would work OK again? A reset button of arduino?
If so, what does failedCounter say?
Is that code complete? Yes, it just include uartWIFI, in which I modified the baudrate to 115200
What is the objective? It is just a test, when it works well I am going to insert this in another sketch to measure particulate matter.
Thanks  in advance, Nick.


Nick_Pyner


matheusdeop

Yes, a reset button on an Arduino.
Yeah, I did it a thousand times. I changed the port "80" to "8080" and didn't work but when I changed it back it started to send data, I really don't know how to explain this.
Many thanks, Nick!

Nick_Pyner

You still haven't said if it works again after a reset. If it does, how long does it take to fail? Is the time taken to fail more or less the same time every time? If so, you may be clogging up the memeory with String class stuff.

matheusdeop

You still haven't said if it works again after a reset. If it does, how long does it take to fail? Is the time taken to fail more or less the same time every time? If so, you may be clogging up the memeory with String class stuff.
I pressed the reset button and didn't solve the problem, the data was not send to thing speak. And today the same error still happening with the same code as yesterday.

Go Up