B4R Question ESP8266 Exception 28 on MQTT.Connect2

barx

Well-Known Member
Licensed User
Longtime User
Hi
Can anybody think of a reason why trying to connect to MQTT would cause the following exception on an ESP8266?
B4X:
Exception (28):
epc1=0x4000bf80 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000004 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffcb0 end: 3fffffc0 offset: 01a0
3ffffe50:  00000005 00000066 40243c50 402068fb 
3ffffe60:  3ffee9f2 00000000 0000000c 4020724c 
3ffffe70:  00004bc6 3fffff48 3fffff40 00000000 
3ffffe80:  3ffee82c 3ffeec54 3ffee9f2 402045fd 
3ffffe90:  00000000 3fffda00 00000000 4020c200 
3ffffea0:  00000000 04dd2f1a 00000000 3ffee9e8 
3ffffeb0:  00000000 3ffee9e2 3ffee9f2 40203360 
3ffffec0:  007a1200 31fc2da9 3ffef000 00000030 
3ffffed0:  00000000 00000000 00000001 40100580 
3ffffee0:  00000000 3fffdad0 000003e8 3ffef08c 
3ffffef0:  3fffdad0 3fffff50 000003e8 4020a152 
3fffff00:  40204c3c 00000000 00000014 4020a18d 
3fffff10:  00000000 4bc6a7f0 1645a1ca 00000000 
3fffff20:  00000000 00000000 00000004 00000005 
3fffff30:  00000002 00000005 00000063 00002505 
3fffff40:  00000001 00002d05 00000001 40202e05 
3fffff50:  00000000 3fffff38 3fffff40 3fffff48 
3fffff60:  002b5c18 00000000 3ffee868 3ffef08c 
3fffff70:  3fffdad0 3ffee858 3ffee8ac 40201379 
3fffff80:  3fffdad0 3ffee858 3fff0f54 40202fbc 
3fffff90:  3fffdad0 00000000 3ffef04c 40206a4f 
3fffffa0:  feefeffe feefeffe feefeffe 4020a238 
3fffffb0:  feefeffe feefeffe 3ffe84f4 40101591 
<<<stack<<<

I have tried to recreate the issue on a smaller project but it seems to opertate fine. So, I can only assume it is some sort of conflict somewhere. I tried the ESP Exception decoder tool and it seems to mention SoftwareSerial. The project I am using does use softwareserial and a few timers and quite a few other bits.

Just thought I would ask here in case anyone else had come across it or had ideas,

thanks
 

barx

Well-Known Member
Licensed User
Longtime User
And for help. The exception decoder gives

B4X:
Exception 28: LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads
PC: 0x4000bf80
EXCVADDR: 0x0000000c

Decoding stack results
0x4020690c: _strtod_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdlib/strtod.c line 483
0x4020657c: _strtod_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdlib/strtod.c line 321
0x402045fd: fde_single_encoding_compare at /workdir/repo/gcc/libgcc/unwind-dw2-fde.c line 359
0x40207400: _strtol_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdlib/strtol.c line 206
0x402043d6: base_from_object at /workdir/repo/gcc/libgcc/unwind-dw2-fde.c line 244
0x40100580: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\Darren\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\core_esp8266_main.cpp line 160
0x40100984: puts(char const*) at C:\Users\Darren\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\libc_replacements.cpp line 117
0x40202ea5: __attachInterruptFunctionalArg(uint8_t, voidFuncPtrArg, void*, int, bool) at C:\Users\Darren\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\core_esp8266_wiring_digital.cpp line 206
0x40201379: SoftwareSerial::end() at C:\Users\Darren\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\SoftwareSerial\src\SoftwareSerial.cpp line 107
0x40202fbc: _realloc_r(_reent*, void*, size_t) at C:\Users\Darren\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\heap.cpp line 137
0x40206a4f: _strtod_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdlib/strtod.c line 633
0x4020a238: new_linkoutput at glue-lwip/lwip-git.c line 220
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Strangely, if I just use MQTT.Connect then it doesn't seem to cause excpetion.

I only use MQTT Options to set a last will like this.

B4X:
    MQTTOptions.Initialize("", "")
    MQTTOptions.SetLastWill("home/pv/status", "Offline", 1, True)

Maybe you can't have "" for username and password. I will try that now.

::EDIT::

Nope, Get the excpetion when using Connect2 and MQTTConnectOptions
Don't get exception when just using Connect

Interesting
 
Last edited:
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
I will give it a try shortly.
I'm already at 1500

Do we know what the maximum stack buffer is to avoid on an ESP8266?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Do we know what the maximum stack buffer is to avoid on an ESP8266?
It depends on the program size and the size of the global variables. The error is probably not related to the stack buffer.

Probably a conflict between two features. Make some tests. Disable SoftwareSerial and see if it happens.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Probably a conflict between two features. Make some tests. Disable SoftwareSerial and see if it happens.

I commented out all the code relating to SoftwareSerial and unticked the SoftwareSerial lib. Cleaned the project and ran it again. Still the same, how strange.

I think it may be something to do with depth of calls (or whatever you call it).
I created a new project and copied chunks of code over hoping that it would start to crash once something was declared, initialized or called. it happened when I added

B4X:
Public MQTTConn As Boolean = False

to Process_Globals and its relating code lines that set it to True if MQTT.Connect2 is successful and False in MQTT_Disconnected.

Now, if I leave the declaration in but don't try and change value later in the script, it ran ok.
If I tried to
B4X:
Log(MQTTConn)
Before I called MQTTConnect2
I got the error
If I logged a string literal in the same place as the above log but with the above log commented out with
B4X:
Log("Here")
it ran ok
It seemed that it didn't like the interaction with the variable.
I tried changing the name, still the same.

I then went back to the original project and cut out the boolean variable an it's code. Still got the error.
The only difference between the 2 projects now, was that in the test project the Connect2 was called like

Main -> AppStart -> MQTTHelper.ConenctMQTT
Module -> Sub -> Module.Sub

MQTTHelper is a code module I created to keep MQTT stuff to one side

In the main project it is called

Main -> CheckForSerial -> Select Case Mode -> Case LOGIN -> MQTTHelper.Connect2
Module -> Sub -> Statement -> Statement Branch -> Module.Sub

This was so that it only connected to the MQTT broker once it was logged into the device it is connecting to with serial
CheckForSerial is a sub I created that is called by a timer and checks swSerial.Stream.BytesAvailable and takes actions on the stream if anything is available. This is to work around the previously discovered issue with AsyncStream / SoftwareSerial in this thread >> Clicky

So, based on this I moved the call to MQTTHelper.Connect2 to match the test project and low and behold it didn't crash.

I'm going to keep playing with it when I get a little more spare time and will report if I find anything else.
 
Upvote 0
Top