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
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
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
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.