B4R Question b4xlib based on MQTT Library - Project reboots on periodically checking of connection to broker

hatzisn

Expert
Licensed User
Longtime User
Good evening everybody,

happy holidays. I am facing a problem with the atouched project.

It is a B4R b4xlib that allows you to add directly mqtt in the B4R projects without writing any code. It is initialized either with the IP (Initialize) or a host (Initialize2).
Everything works perfectly except the following: Recently I decided to add a selfcheck if the module is still connected to the MQTT broker since if the WiFi goes offline it stops also the communications inside the local network in my router and no mqtt_disconnected event is fired. What I did to overcome this was trying to publish something in a given topic at regular time intervals and receive also the answer if it is connected to the broker. If it receives the message it sets a boolean to true and the next time the timer fires it does not enter the code block to be executed if it is not connected and resets the boolean to false again and this goes around at regular intervals (set boolean false -> publish -> receive -> set boolean true if received-> get in the next interval in the timer and if boolean is false execute the not connected code block otherwise loop in the next interval).

It constantly reboots at the timer execution and I cannot figure out why, since no logs are printed to see what is wrong... Can anyone of you figure it out?
I tried to increase the StackBufferSize and also add Delay(1) in tim_Tick to emulate the yield(); command in ESP 8266 but not a chance...
I am using an ESP8266 (a WeMos D1 Mini R3).

Thanks in advance
 

Attachments

  • DHQIMQTTLib.zip
    3.5 KB · Views: 166

hatzisn

Expert
Licensed User
Longtime User
If I comment out all the lines except from the first which is "Log(...)" and the last which is also "Log(...)" the same thing happens exactly.
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Post the logs. Are you sure that the crash happens inside tim_Tick?

Here are the logs. At the bottom you can see the reboot with no trackable error...

Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: bc:ff:4d:4d:22:31
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 287328 bytes to 210945...
Writing at 0x00000000... (7 %)
Writing at 0x00004000... (15 %)
Writing at 0x00008000... (23 %)
Writing at 0x0000c000... (30 %)
Writing at 0x00010000... (38 %)
Writing at 0x00014000... (46 %)
Writing at 0x00018000... (53 %)
Writing at 0x0001c000... (61 %)
Writing at 0x00020000... (69 %)
Writing at 0x00024000... (76 %)
Writing at 0x00028000... (84 %)
Writing at 0x0002c000... (92 %)
Writing at 0x00030000... (100 %)
Wrote 287328 bytes (210945 compressed) at 0x00000000 in 4.7 seconds (effective 484.0 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
New upload port: COM4 (serial)
�$NxG�hlD�@xOht�Connected to network
Got in initialize
Got in ConnectMQTT
--
connected to MQTT Broker
,�)�J)��)��Connected to network
Got in initialize
Got in ConnectMQTT
--
connected to MQTT Broker


Don't call Delay with 10 seconds. Use CallSubPlus instead.

Thanks for this. I have completely forgotten about it...
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Post the logs with this sub:
B4X:
Sub tim_Tick
    Delay(1)
    Log("In sub tim_Tick")
    Delay(1)
    If bTestConnection = False Then
        iCountTest = iCountTest + 1
        Log("TestConnection=False - ", iCountTest)
        'If iCountTest = 5 Then
            'esp.Restart
       ' Else
            'Reconnect
        'End If
    End If
    bTestConnection = False
    Log("memClientID: ", memClientID)
'    mq.Publish("DHQIMQTTTest1", memClientID)
    Delay(1)
    Log("Exiting sub tim_Tick")
    Delay(1)
End Sub

If it doesn't crash then uncomment lines until you find the one that causes the crash.

I recommend using GlobalStore to store the client id.
[module] GlobalStore - Global objects storage
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Hi, thanks for checking this out...

The same things happen. Here are the logs (no error messages - just reboot). I tried also with a different board (another WeMos D1 Mini R3) to check the case of a corrupted board.

Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: bc:ff:4d:4d:77:2e
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 286272 bytes to 210214...
Writing at 0x00000000... (7 %)
Writing at 0x00004000... (15 %)
Writing at 0x00008000... (23 %)
Writing at 0x0000c000... (30 %)
Writing at 0x00010000... (38 %)
Writing at 0x00014000... (46 %)
Writing at 0x00018000... (53 %)
Writing at 0x0001c000... (61 %)
Writing at 0x00020000... (69 %)
Writing at 0x00024000... (76 %)
Writing at 0x00028000... (84 %)
Writing at 0x0002c000... (92 %)
Writing at 0x00030000... (100 %)
Wrote 286272 bytes (210214 compressed) at 0x00000000 in 4.9 seconds (effective 468.4 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
New upload port: COM4 (serial)
"ol+)��Xt�Connected to network
Got in initialize
Got in ConnectMQTT
--
connected to MQTT Broker
g�I�i9JE4�Connected to network
Got in initialize
Got in ConnectMQTT
--
connected to MQTT Broker
 
Upvote 0
Top