NodeMCU Esp8266 uploading the sketch fine but crashing at client.sendAll(true);

Simple code:

void loop()
{
    float value = analogRead(A0);
    client.add("ANALOG PIN A0", value);
    client.sendAll(true);
    Serial.println("Completed loop, now going to pause for 1 minute");
    delay(60000);
}

I can see in the serial monitor that when it processes the line client.sendAll(true);, it throws the following exception.

Exception (28):
epc1=0x4000bf64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x000206fd depc=0x00000000

Hello @roquito

We are looking for helping you with your problem.

1 Like

Thanks. Here is a bit more detail which I think is relevant. This code, that essentialy does the same thing (but supports ArduinoOTA) works fine:

```

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include "UbidotsMicroESP8266.h"
#define TOKEN  "xlNJ" 

const char* ssid = "XYZ";
const char* password = "oij";
Ubidots client(TOKEN);
void setup() {
  Serial.begin(9600);
  Serial.println("Booting");
   WiFi.mode(WIFI_STA);
   WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
  Serial.println("Connection Failed! Rebooting...");
   delay(5000);
   ESP.restart();
 }

  ArduinoOTA.onStart([]() {
    Serial.println("Start");
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nEnd");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("End Failed");
  });
  ArduinoOTA.begin();
  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  ArduinoOTA.handle();
    float value = analogRead(A0);
    client.add("ANALOG PIN A0", value);
    client.sendAll(true);
    Serial.println("Completed loop, now going to pause for 1 minute");
    delay(60000);
}

Hello @roquito i was searching for the error with the exception(28), it is an error when there is a infinite loop in any location. In our labrary we delete all infinite loops (while, for, etc) that errer is possible that is caused before to sendAll function, i think that the problem is with OTA library, try to run the code without that lib and if it works then the problem is with the another lib or the size of the two libs in the same sketch.

By the way the link of that exeption is this one: https://github.com/esp8266/Arduino/issues/1329
Best regards,
Metavix

No, it is actually quite the contrary. The sketch that includes the OTA (and all the other libraries) works fine! while the simple one does not! to be clear, this is the one that does not work:

#include "UbidotsMicroESP8266.h"
#define TOKEN  "xlAtJF"  // Put here your Ubidots TOKEN
#define WIFISSID "Gni"
#define PASSWORD "ju"

Ubidots client(TOKEN);

void setup(){
Serial.begin(9600);
delay(10);
client.wifiConnection(WIFISSID, PASSWORD);
Serial.println("All done with the setup function");
}
void loop(){
    float value = analogRead(A0);
    client.add("ANALOG PIN A0", value);
    client.sendAll(true);
    Serial.println("Completed loop, now going to pause for 1 minute");
    delay(60000);
}

@roquito When you upload that simple code it crashes? or what show you the serial terminal?

@Metavix the sketch loads fine but the serial monitor reports a bunch of garbage (serial output.txt (44.5 KB)

Now, I ordered a brand new NodeMCU and loaded the simple code as soon as I opened the package and it worked. Here is the serial output:

I can confirm that if I load another sketch (For_ubidots.ino (2.4 KB) ) and then try to load the simple sketch back, it will “break” the NodeMCU to where it would give me the same serial output as the txt file above.

I suspect your library has a dependency on something that the .ino file above is permanently altering. Looking forward to get this solved!

@Metavix Hi, any ideas?

So same problem here.

Found the cause of this issue, the solution is to comment out these lines in UbitdotsMicroEsp8266.cpp
> if ((val+currentValue)->timestamp != NULL) {

        sprintf(data, "%s@%s", data, (val+currentValue)->timestamp);
    }
    if ((val+currentValue)->context != NULL) {
        sprintf(data, "%s$%s", data, (val+i)->context);
    }

I wonder, if Ubidots ever tested their code!

As an alternative, you can use HTTP upload via

client.sendAll(false);

bit thats terrible slow… :frowning: Takes about 5sec. or more.
Any ideas how to speed up the upload or retrieve via http?

Hello everybody, for NodeMCU we recommend to use our new MQTT Library, is faster for sending values and easier to understand for developers.

Please take a look here: