NodeMCU gets disconnected to Thinger.io, as showed in dashboard and devices API, but somehow still sending data to bucket

Hi, community. I am using NodeMCU which acts as a master device which allows data to be collected from a slave device using Bluetooth.

However, I faced with an issue. Which is that the NodeMCU will display disconnected status, either in dashboard or in device API. But it somehow still collects and send data (actual data, not floating values) to the Bucket. The debug did not state that it is disconnected, but it displays

[THINGER] Writing bytes: 2 [OK]
[THINGER] Available bytes: 2

these messages about once every minute in the debug output. I have to press the reset button of nodeMCU just to get it connected again.

Debug output is like this… (I used Serial Monitor to see the sensor values I get also, so it will look cluttered a bit)
image

Have you guys met with this problem before?

I have seen this post, Disconnect and reconnect ESP8266 - Hardware - The Internet of Thinger, not sure if they are similar issues.

Hi,

That weird behaviour could be caused by a long time without calling the thing.handle(); instruction, I’ve had similar issues using the delay(); instruction and that’s why it must be used another strategy to handle the timers and time counters into the code, maybe you have a function that is avoiding the call of the thing.handle(); instruction as often as it needs to be called.

Hope this helps.

Here is a snippet of my void loop(), in which I have added a line which is to light up an internal LED in front of the thing.handle(); instruction, just to ensure that the whole void loop() is properly executed. I do not use delay() in all my codes as I know it will lead to problems.

The light does light up, so as the other functions of receiving data using bluetooth, but sending data does not work because obviously it receives data to turn on from thinger. I am wondering, is there any function that I can use to check the WiFi connection status? Or should I include thing.handle() in some sort of millis functions?

void loop() 
{
  //LED light up if connected. 
  digitalWrite(LED_BUILTIN, LOW);
  
  thing.handle();

/*---------------------sending to slave-------------------------*/
  sendtoarduino();

  //MASTER LOCAL CONTROL
  //turn on pin on MEGA to indicate data is sent. 
  digitalWrite(ledpin1, ledState1);
  digitalWrite(ledpin2, ledState2);

  //led to indicate motor is turned on
  digitalWrite(motorpin, motorState);

/*-------------------------receiving from slave---------------------------*/
  recvWithStartEndMarkers();
  if (newData == true)
  {
    strcpy(tempChars, receivedChars);
    parseData();
    showNewData();
    calculation();
    newData = false;
  }
  
/*------------------EMAIL ENDPOINT CALL-------------------*/

    currentmillis=millis();
    if(currentmillis - emailpreviousmillis >= emailinterval)
      {
    emailpreviousmillis = currentmillis;
    if (h>=95 || t>=30.50)      //too hot
          {
          trigger1();     
         }

     if (h<=40 || t<= 25)       //too cold
          {
          trigger2();
          }       
      }
}

Hi,

Into the loop code everything seems to be ok, but any (or several) of the functions that are called into the loop may cause the issue.

You need to check all the functions that are being called, and make sure that none of them keeps stuck waiting for an answer or something that may cause the uC not executes the thing.handle() instruction so often.

Hope this helps.

Hi, I have checked the other functions that are being called. They do not contain the delay function that will ruin the real-time transmission to Thinger.io

However, when I hook up the NodeMCU to the SM, I notice this message quite a few times when it sometimes restarts on its own.

`Exception 28: LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads
PC: 0x4020c16e
EXCVADDR: 0x00000000

*Decoding stack results* 
0x4020881c: **__multiply** at /workdir/repo/newlib/newlib/libc/stdlib/**mprec.c** line **391** 
0x4020410d: **__register_frame** at /workdir/repo/gcc-gnu/libgcc/**unwind-dw2-fde.c** line **136** 
0x401005d8: **umm_init_common(size_t, void*, size_t, bool)** at C:\Users\USER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\umm_malloc\**umm_malloc.cpp** line **445** 
0x4020384c: **get_cie_encoding** at /workdir/repo/gcc-gnu/libgcc/**unwind-dw2-fde.c** line **347** 
0x40203fe0: **search_object** at /workdir/repo/gcc-gnu/libgcc/**unwind-dw2-fde.c** line **1034** 
0x401005d8: **umm_init_common(size_t, void*, size_t, bool)** at C:\Users\USER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\umm_malloc\**umm_malloc.cpp** line **445** 
0x4020c2c8: **udp_bind** at core/**udp.c** line **959** 
0x40209fa4: **ethernet_input_LWIP2** at netif/**ethernet.c** line **191** 
0x40201de9: **_GLOBAL__sub_I__ZN12UpdaterClassC2Ev()** at C:\Users\USER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\**Updater.cpp** line **582** 
0x40203776: **get_cie_encoding** at /workdir/repo/gcc-gnu/libgcc/**unwind-dw2-fde.c** line **312** 
0x40206660: **strtof** at /workdir/repo/newlib/newlib/libc/stdlib/**strtod.c** line **1311**`

None of which is related to the code I wrote. Idk am I supposed to bring this problem to this forum lol…

Hi,

Not just a delay() may cause the unwanted behaviour, if some function get stuck waiting for any response or something, causes the same effect that the delay() function to thinger.handle();, ie if you have a while(a==0) it will get stuck into that loop unitl the value of the variable “a” changes.

Wish you luck debugging your code.

Hope this helps.

I have found out that this Exception 28 case is related to problems in pointer. So it is a problem with my code (I guess so). After changing the code a bit, I think I will observe the performance of my setup and see if there are any problems. Now I only can see that sometimes thinger displays my NodeMCU as disconnected in Device there, but after several refreshes it displays connected. I dont know why :sweat_smile:

Can I know what is the purpose of thing.handle()?

Can I also suggest something? like maybe can include a real-time clock that is connected to an NTP server, which can enable some automation. Also, can I know is it just me who cannot use TLS on my NodeMCU or is it a feature that is not available on nodeMCU yet?

According my experience (have not digged into the library), this command handles all the bidirectional communication, if you don’t call it, the device is not able to establish communication to and from the cloud, haven’t tested (I never had the need to), but I guess that in this command is executed the instruction when the device needs to send info to the cloud.

I can use the TLS with the NodeMCU example, I have arduino 1.8.12 and thinger 2.15.0.

Hope this helps.