B4R Question MQTT disconnect

derez

Expert
Licensed User
Using two NodeMcu and one Wemos D1 with the same problem...
The mqtt broker is on a b4j server and works fine. The micros are clients for the same topic which is a date and time string like this : "18 07 19 16 37 00 5" . After about 20 (+-2) received messages the clients report MQTT disconnect, try to reconnect but without success, and usually restarts.
It does not matter if the rate is one message every 1.5 minute or 30 minutes.
Looks like a buildup of used memory. Any idea how to clean it while still working to prevent the disconnection ?
Thanks.
 

Erel

Administrator
Staff member
Licensed User
Check the available ram and stack usage.
B4X:
Log(AvailableRAM)
Log(StackBufferUsage)
Also check your code and make sure that you are not building too many strings with JoinStrings.
 

derez

Expert
Licensed User
Check the available ram and stack usage.
B4X:
Log(AvailableRAM)
Log(StackBufferUsage)
Also check your code and make sure that you are not building too many strings with JoinStrings.
StackbufferUsage is 16 , not changing.
The available ram starts with 48912 and reduces in each received message by 2640. After 19 messages there is none left...
The JoinString is done every second but without effect on the available ram. The ram is reduced by the received message !
 

derez

Expert
Licensed User
The available ram is reduced like this, see what happens below 1000 :
Connected to wifi 192.168.0.118
Connected to broker
available ram = 48912
Topic=time payload: 19 07 19 08 33 49 6 length= 19
available ram = 45576
Topic=time payload: 19 07 19 08 33 49 6 length= 19
available ram = 43608
Topic=time payload: 19 07 19 08 34 45 6 length= 19
available ram = 40920
Topic=time payload: 19 07 19 08 36 10 6 length= 19
available ram = 38280
Topic=time payload: 19 07 19 08 37 35 6 length= 19
available ram = 35640
Topic=time payload: 19 07 19 08 39 00 6 length= 19
available ram = 33000
Topic=time payload: 19 07 19 08 40 25 6 length= 19
available ram = 30360
Topic=time payload: 19 07 19 08 41 50 6 length= 19
available ram = 27504
Topic=time payload: 19 07 19 08 43 15 6 length= 19
count= 9
Connected to broker
available ram = 24864
Topic=time payload: 19 07 19 08 43 49 6 length= 19
available ram = 22224
Topic=time payload: 19 07 19 08 44 40 6 length= 19
available ram = 19536
Topic=time payload: 19 07 19 08 46 05 6 length= 19
available ram = 16896
Topic=time payload: 19 07 19 08 47 30 6 length= 19
available ram = 14256
Topic=time payload: 19 07 19 08 48 55 6 length= 19
available ram = 11568
Topic=time payload: 19 07 19 08 50 20 6 length= 19
available ram = 8928
Topic=time payload: 19 07 19 08 51 45 6 length= 19
available ram = 6288
Topic=time payload: 19 07 19 08 53 10 6 length= 19
count= 17
Connected to broker
available ram = 3648
Topic=time payload: 19 07 19 08 53 49 6 length= 19
available ram = 1008
Topic=time payload: 19 07 19 08 54 35 6 length= 19
available ram = 936
Topic=time payload: 19 07 19 08 56 00 6 length= 19
available ram = 864
Topic=time payload: 19 07 19 08 57 25 6 length= 19
available ram = 792
Topic=time payload: 19 07 19 08 58 50 6 length= 19
Exception (29):
epc1=0x4021c9f7 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000004 depc=0x00000000
>>>stack>>>
ctx: sys
sp: 3fffed50 end: 3fffffb0 offset: 01a0
3fffeef0: 3ffec438 40221184 3ffec438 3ffe92fc
3fffef00: 3ffe92fc 00000066 00000000 00000016
3fffef10: 00000002 00000018 4022a957 3ffec438
3fffef20: 3ffe92f0 3fffdcc0 3ffe8b20 3ffe8b20
3fffef30: 00000000 3ffec438 00000000 3fffdcb0
3fffef40: 4022a217 3fffdab0 00000000 40205de7
3fffef50: 3ffe8b20 40000f49 3fffdab0 40000f49
3fffef60: 40000e19 40001878 00000002 00000000
3fffef70: 3fffff10 aa55aa55 000000b4 40104a3c
3fffef80: 40104a42 00000002 00000000 91876452
3fffef90: 4010000d 0020c0f9 80422252 20c02055
3fffefa0: 40100c08 3fffef3c 40100bb5 3ffffec8
3fffefb0: 3fffffc0 00000000 00000000 feefeffe
3fffefc0: feefeffe feefeffe feefeffe feefeffe
3fffefd0: feefeffe feefeffe feefeffe feefeffe
3fffefe0: feefeffe feefeffe feefeffe feefeffe
3fffeff0: feefeffe feefeffe feefeffe feefeffe
3ffff000: feefeffe feefeffe feefeffe feefeffe
3ffff010: feefeffe feefeffe feefeffe feefeffe
3ffff020: feefeffe feefeffe feefeffe feefeffe
3ffff030: feefeffe feefeffe feefeffe feefeffe
3ffff040: feefeffe feefeffe feefeffe feefeffe
3ffff050: feefeffe feefeffe feefeffe feefeffe
3ffff060: feefeffe feefeffe feefeffe feefeffe
3ffff070: feefeffe feefeffe feefeffe feefeffe
3ffff080: feefeffe feefeffe feefeffe feefeffe
3ffff090: feefeffe feefeffe feefeffe feefeffe
3ffff0a0: feefeffe feefeffe feefeffe feefeffe
3ffff0b0: feefeffe feefeffe feefeffe feefeffe
3ffff0c0: feefeffe feefeffe feefeffe feefeffe
3ffff0d0: feefeffe feefeffe feefeffe feefeffe
3ffff0e0: feefeffe feefeffe feefeffe feefeffe
3ffff0f0: feefeffe feefeffe feefeffe feefeffe
3ffff100: feefeffe feefeffe feefeffe feefeffe
3ffff110: feefeffe feefeffe feefeffe feefeffe
3ffff120: feefeffe feefeffe feefeffe feefeffe
3ffff130: feefeffe feefeffe feefeffe feefeffe
3ffff140: feefeffe feefeffe feefeffe feefeffe
3ffff150: feefeffe feefeffe feefeffe feefeffe
3ffff160: feefeffe feefeffe feefeffe feefeffe
3ffff170: feefeffe feefeffe feefeffe feefeffe
3ffff180: feefeffe feefeffe feefeffe feefeffe
3ffff190: feefeffe feefeffe feefeffe feefeffe
3ffff1a0: feefeffe feefeffe feefeffe feefeffe
3ffff1b0: feefeffe feefeffe feefeffe feefeffe
3ffff1c0: feefeffe feefeffe feefeffe feefeffe
3ffff1d0: feefeffe feefeffe feefeffe feefeffe
3ffff1e0: feefeffe feefeffe feefeffe feefeffe
3ffff1f0: feefeffe feefeffe feefeffe feefeffe
3ffff200: feefeffe feefeffe feefeffe feefeffe
3ffff210: feefeffe feefeffe feefeffe feefeffe
3ffff220: feefeffe feefeffe feefeffe feefeffe
3ffff230: feefeffe feefeffe feefeffe feefeffe
3ffff240: feefeffe feefeffe feefeffe feefeffe
3ffff250: feefeffe feefeffe feefeffe feefeffe
3ffff260: feefeffe feefeffe feefeffe feefeffe
3ffff270: feefeffe feefeffe feefeffe feefeffe
3ffff280: feefeffe feefeffe feefeffe feefeffe
3ffff290: feefeffe feefeffe feefeffe feefeffe
3ffff2a0: feefeffe feefeffe feefeffe feefeffe
3ffff2b0: feefeffe feefeffe feefeffe feefeffe
3ffff2c0: feefeffe feefeffe feefeffe feefeffe
3ffff2d0: feefeffe feefeffe feefeffe feefeffe
3ffff2e0: feefeffe feefeffe feefeffe feefeffe
3ffff2f0: feefeffe feefeffe feefeffe feefeffe
3ffff300: feefeffe feefeffe feefeffe feefeffe
3ffff310: feefeffe feefeffe feefeffe feefeffe
3ffff320: feefeffe feefeffe feefeffe feefeffe
3ffff330: feefeffe feefeffe feefeffe feefeffe
3ffff340: feefeffe feefeffe feefeffe feefeffe
3ffff350: feefeffe feefeffe feefeffe feefeffe
3ffff360: feefeffe feefeffe feefeffe feefeffe
3ffff370: feefeffe feefeffe feefeffe feefeffe
3ffff380: feefeffe feefeffe feefeffe feefeffe
3ffff390: feefeffe feefeffe feefeffe feefeffe
3ffff3a0: feefeffe feefeffe feefeffe feefeffe
3ffff3b0: feefeffe feefeffe feefeffe feefeffe
3ffff3c0: feefeffe feefeffe feefeffe feefeffe
3ffff3d0: feefeffe feefeffe feefeffe feefeffe
3ffff3e0: feefeffe feefeffe feefeffe feefeffe
3ffff3f0: feefeffe feefeffe feefeffe feefeffe
3ffff400: feefeffe feefeffe feefeffe feefeffe
3ffff410: feefeffe feefeffe feefeffe feefeffe
3ffff420: feefeffe feefeffe feefeffe feefeffe
3ffff430: feefeffe feefeffe feefeffe feefeffe
3ffff440: feefeffe feefeffe feefeffe feefeffe
3ffff450: feefeffe feefeffe feefeffe feefeffe
3ffff460: feefeffe feefeffe feefeffe feefeffe
3ffff470: feefeffe feefeffe feefeffe feefeffe
3ffff480: feefeffe feefeffe feefeffe feefeffe
3ffff490: feefeffe feefeffe feefeffe feefeffe
3ffff4a0: feefeffe feefeffe feefeffe feefeffe
3ffff4b0: feefeffe feefeffe feefeffe feefeffe
3ffff4c0: feefeffe feefeffe feefeffe feefeffe
3ffff4d0: feefeffe feefeffe feefeffe feefeffe
3ffff4e0: feefeffe feefeffe feefeffe feefeffe
3ffff4f0: feefeffe feefeffe feefeffe feefeffe
3ffff500: feefeffe feefeffe feefeffe feefeffe
3ffff510: feefeffe feefeffe feefeffe feefeffe
3ffff520: feefeffe feefeffe feefeffe feefeffe
3ffff530: feefeffe feefeffe feefeffe feefeffe
3ffff540: feefeffe feefeffe feefeffe feefeffe
3ffff550: feefeffe feefeffe feefeffe feefeffe
3ffff560: feefeffe feefeffe feefeffe feefeffe
3ffff570: feefeffe feefeffe feefeffe feefeffe
3ffff580: feefeffe feefeffe feefeffe feefeffe
3ffff590: feefeffe feefeffe feefeffe feefeffe
3ffff5a0: feefeffe feefeffe feefeffe feefeffe
3ffff5b0: feefeffe feefeffe feefeffe feefeffe
3ffff5c0: feefeffe feefeffe feefeffe feefeffe
3ffff5d0: feefeffe feefeffe feefeffe feefeffe
3ffff5e0: feefeffe feefeffe feefeffe feefeffe
3ffff5f0: feefeffe feefeffe feefeffe feefeffe
3ffff600: feefeffe feefeffe feefeffe feefeffe
3ffff610: feefeffe feefeffe feefeffe feefeffe
3ffff620: feefeffe feefeffe feefeffe feefeffe
3ffff630: feefeffe feefeffe feefeffe feefeffe
3ffff640: feefeffe feefeffe feefeffe feefeffe
3ffff650: feefeffe feefeffe feefeffe feefeffe
3ffff660: feefeffe feefeffe feefeffe feefeffe
3ffff670: feefeffe feefeffe feefeffe feefeffe
3ffff680: feefeffe feefeffe feefeffe feefeffe
3ffff690: feefeffe feefeffe feefeffe feefeffe
3ffff6a0: feefeffe feefeffe feefeffe feefeffe
3ffff6b0: feefeffe feefeffe feefeffe feefeffe
3ffff6c0: feefeffe feefeffe feefeffe feefeffe
3ffff6d0: feefeffe feefeffe feefeffe feefeffe
3ffff6e0: feefeffe feefeffe feefeffe feefeffe
3ffff6f0: feefeffe feefeffe feefeffe feefeffe
3ffff700: feefeffe feefeffe feefeffe feefeffe
3ffff710: feefeffe feefeffe feefeffe feefeffe
3ffff720: feefeffe feefeffe feefeffe feefeffe
3ffff730: feefeffe feefeffe feefeffe feefeffe
3ffff740: feefeffe feefeffe feefeffe feefeffe
3ffff750: feefeffe feefeffe feefeffe feefeffe
3ffff760: feefeffe feefeffe feefeffe feefeffe
3ffff770: feefeffe feefeffe feefeffe feefeffe
3ffff780: feefeffe feefeffe feefeffe feefeffe
3ffff790: feefeffe feefeffe feefeffe feefeffe
3ffff7a0: feefeffe feefeffe feefeffe feefeffe
3ffff7b0: feefeffe feefeffe feefeffe feefeffe
3ffff7c0: feefeffe feefeffe feefeffe feefeffe
3ffff7d0: feefeffe feefeffe feefeffe feefeffe
3ffff7e0: feefeffe feefeffe feefeffe feefeffe
3ffff7f0: feefeffe feefeffe feefeffe feefeffe
3ffff800: feefeffe feefeffe feefeffe feefeffe
3ffff810: feefeffe feefeffe feefeffe feefeffe
3ffff820: feefeffe feefeffe feefeffe feefeffe
3ffff830: feefeffe feefeffe feefeffe feefeffe
3ffff840: feefeffe feefeffe feefeffe feefeffe
3ffff850: feefeffe feefeffe feefeffe feefeffe
3ffff860: feefeffe feefeffe feefeffe feefeffe
3ffff870: feefeffe feefeffe feefeffe feefeffe
3ffff880: feefeffe feefeffe feefeffe feefeffe
3ffff890: feefeffe feefeffe feefeffe feefeffe
3ffff8a0: feefeffe feefeffe feefeffe feefeffe
3ffff8b0: feefeffe feefeffe feefeffe feefeffe
3ffff8c0: feefeffe feefeffe feefeffe feefeffe
3ffff8d0: feefeffe feefeffe feefeffe feefeffe
3ffff8e0: feefeffe feefeffe feefeffe feefeffe
3ffff8f0: feefeffe feefeffe feefeffe feefeffe
3ffff900: feefeffe feefeffe feefeffe feefeffe
3ffff910: feefeffe feefeffe feefeffe feefeffe
3ffff920: feefeffe feefeffe feefeffe feefeffe
3ffff930: feefeffe feefeffe feefeffe feefeffe
3ffff940: feefeffe feefeffe feefeffe feefeffe
3ffff950: feefeffe feefeffe feefeffe feefeffe
3ffff960: feefeffe feefeffe feefeffe feefeffe
3ffff970: feefeffe feefeffe feefeffe feefeffe
3ffff980: feefeffe feefeffe feefeffe feefeffe
3ffff990: feefeffe feefeffe feefeffe feefeffe
3ffff9a0: feefeffe feefeffe feefeffe feefeffe
3ffff9b0: feefeffe feefeffe feefeffe feefeffe
3ffff9c0: feefeffe feefeffe feefeffe feefeffe
3ffff9d0: feefeffe feefeffe feefeffe feefeffe
3ffff9e0: feefeffe feefeffe feefeffe feefeffe
3ffff9f0: feefeffe feefeffe feefeffe feefeffe
3ffffa00: feefeffe feefeffe feefeffe feefeffe
3ffffa10: feefeffe feefeffe feefeffe feefeffe
3ffffa20: feefeffe feefeffe feefeffe feefeffe
3ffffa30: feefeffe feefeffe feefeffe feefeffe
3ffffa40: feefeffe feefeffe feefeffe feefeffe
3ffffa50: feefeffe feefeffe feefeffe feefeffe
3ffffa60: feefeffe feefeffe feefeffe feefeffe
3ffffa70: feefeffe feefeffe feefeffe feefeffe
3ffffa80: feefeffe feefeffe feefeffe feefeffe
3ffffa90: feefeffe feefeffe feefeffe feefeffe
3ffffaa0: feefeffe feefeffe feefeffe feefeffe
3ffffab0: feefeffe feefeffe feefeffe feefeffe
3ffffac0: feefeffe feefeffe feefeffe feefeffe
3ffffad0: feefeffe feefeffe feefeffe feefeffe
3ffffae0: feefeffe feefeffe feefeffe feefeffe
3ffffaf0: feefeffe feefeffe feefeffe feefeffe
3ffffb00: 00000000 00000000 00000020 4010153a
3ffffb10: 3ffe8a20 40104918 3ffef8e4 feefeffe
3ffffb20: 00000000 00000000 00000020 4010153a
3ffffb30: 3ffe8a20 40104918 3ffef8e4 00000008
3ffffb40: 00000001 40103b3b 3ffecba0 00000001
3ffffb50: 40103f9e 0000007f 7fffffff 00000000
3ffffb60: 0000007f 00000000 4022b373 00000001
3ffffb70: 40103a82 0000007f 7fffffff 00000000
3ffffb80: 0000007f 00000001 00000000 4000050c
3ffffb90: 40102903 00080000 7fffffff 00000000
3ffffba0: 00000000 4010387e 00000000 4000050c
3ffffbb0: 00000000 00000000 0000001f 40105215
3ffffbc0: 4000050c 00000023 00000000 4000050c
3ffffbd0: 40002ef1 00000030 0000001c ffffffff
3ffffbe0: 40002ef1 1d090c60 00000013 000000f4
3ffffbf0: fffffff0 00000009 00000559 fffffffe
3ffffc00: ffffffff 3fffc6fc 00000001 00000500
3ffffc10: 1d090b60 1d090fcf 1d090ac6 00000030
3ffffc20: 4022b3c2 3ffec168 3ffeefe4 00000001
3ffffc30: 00000002 00000000 00000020 4010153a
3ffffc40: 3ffe8a22 40104918 3ffec168 4010153a
3ffffc50: 00000001 40103b3b 3ffecbe8 3fff0250
3ffffc60: 40103f9e 4021d853 4022b373 00000001
3ffffc70: ffffffff 00000000 4022b373 00000001
3ffffc80: ffffffff 00000000 3ffe8b71 00000008
3ffffc90: 4022b3c2 3ffec168 3ffeefe4 00000001
3ffffca0: 4022b4ce 3ffec168 3ffe850c 3ffee530
3ffffcb0: 3b253c76 3b253827 40205e2c 3fffefa0
3ffffcc0: 3ffe8a22 4022a47f 00000001 40205f0e
3ffffcd0: 40205200 00000000 3ffee530 40205f51
3ffffce0: 3ffffd1f 0000000a 00000001 401000f4
3ffffcf0: 3ffffd2f 00000001 0000000d 0000056c
3ffffd00: 00000005 00000000 00000020 4010153a
3ffffd10: 3ffe8a25 40104933 00000000 00000000
3ffffd20: 00000020 4010153a 3ffe8a20 40104918
3ffffd30: 3ffef8e4 40104933 00000001 40103b3b
3ffffd40: 3ffecba0 3ffec410 40103f9e 00000000
3ffffd50: 0000000a 5a54d632 3ffece8c 40102426
3ffffd60: 3ffe92ac 00000000 40103a82 0000007f
3ffffd70: 00000005 00000000 00000020 4010153a
3ffffd80: 00000005 00000000 00000020 4010153a
3ffffd90: 3ffe8a25 40104933 3ffec410 4010153a
3ffffda0: 40102251 3ffec410 3ffef8e4 40102426
3ffffdb0: fffffff5 5a589172 3ffece8c 40102426
3ffffdc0: 3ffe92dc 00000000 00000000 00000100
3ffffdd0: fffffff5 5a589172 40102866 00000100
3ffffde0: 7fffffff 3ffe92dc 3ffe92dc 00000001
3ffffdf0: 00000001 00006208 0000001f 40105215
3ffffe00: 00000000 00000000 0000001f 40105215
3ffffe10: 4000050c 40102600 3fffc200 00000022
3ffffe20: 40207bf5 00000030 00000010 ffffffff
3ffffe30: 40207bf0 3ffee328 402082f0 00000000
3ffffe40: 00004bc6 00000000 00000000 fffffffe
3ffffe50: 00000000 3fffc6fc 00000000 3ffee340
3ffffe60: 001720ea 3fffdad0 3fffff30 00000030
3ffffe70: 3ffefb24 3fffdad0 3ffee838 00000030
3ffffe80: 3ffefb24 3fffdad0 3ffee838 00000030
3ffffe90: 4020281f 00000030 00000010 ffffffff
3ffffea0: 40203867 3ffee2f8 60000600 00000000
3ffffeb0: 3ffe8830 00000000 00000000 fffffffe
3ffffec0: 00000000 4bc6a7f0 3ffe850c 001720ea
3ffffed0: 3fffdad0 3fffff30 40205e2c 3fffefa0
3ffffee0: 00000000 3fffdad0 00000064 40205f0e
3ffffef0: 00000000 3ffe8792 3ffefd01 40205f51
3fffff00: 1abe0ec4 3ffe8792 3ffee340 40204683
3fffff10: 00000008 3fffff1c 3ffee340 40207bfa
3fffff20: 3fffdad0 3ffee5a8 3ffee420 402024c4
3fffff30: 00000000 00000000 4bc6a7f0 00000000
3fffff40: 3ffffedc 3ffffee4 3ffee420 40207cb0
3fffff50: 00000000 3fffff04 3ffefb34 3ffee838
3fffff60: 3fffdad0 3ffee5a8 3ffee420 4020362b
3fffff70: 3fffdad0 3ffefb24 3ffee2f0 402027f0
3fffff80: 3fffdad0 3ffee2f8 3ffefeb4 40202857
3fffff90: 3fffdad0 00000000 3ffee808 40203867
3fffffa0: feefeffe feefeffe feefeffe 40205edc
<<<stack<<<
last failed alloc call: 40100914(20)
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v8b899c12
~ld
appstart
Connected to wifi 192.168.0.118
Connected to broker
 

Erel

Administrator
Staff member
Licensed User
You need to debug it. What happens if you don't do anything with the received message? Where is the MessageReceived code?
 

derez

Expert
Licensed User
Unrelated to Mqtt but related to all the forum members.
Because of communication problem I initialized a softserial every time I got MQTT message, this init caused the ram to reduce.
When moved to app_start it behaves normally.
 
Top