B4R Question save custom Type to GlobalStore

Chris160179

Member
Licensed User
Longtime User
Hello Everybody,

I want to save custom type variables in a GlobalStore slot.
I can compile and run my code, but when I try to log the saved IP address, the ESP8266 crashes.

My code:
B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    Public Serial1 As Serial
    Type System_Type (Resets As UInt, Sommerzeit As Boolean)
    Type WLAN_Type (IP As String, SSID As String, Password As String, Chanel As Byte, BSSID As String)
    Type Einstellungen (System As System_Type, WLAN As WLAN_Type)
    Private bc As ByteConverter
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    Private Settings As Einstellungen
    Private System1 As System_Type
    Private WLAN1 As WLAN_Type
    Settings.System = System1
    Settings.WLAN = WLAN1
    'set defaults
    Settings.System.Resets = 0
    Settings.System.Sommerzeit = True
    Settings.WLAN.IP = "192.168.0.170"   
    Settings.WLAN.SSID = "Wireless1"
    Settings.WLAN.Password = "@Oktober160"
    Settings.WLAN.Chanel = 1
    Settings.WLAN.BSSID = "CCCE1E1DC20B"
    
    Log ("Save Size: " , SizeOf(Settings))
    GlobalStore.Put(0, bc.ObjectToBytes(Settings, SizeOf(Settings))) 'store value in slot #0
    
    CallSubPlus ("Test", 100, 0)
End Sub


Sub Test (Tag As Byte)
    Log ("Load Settings: ")
    Dim s As Einstellungen
    Private System1 As System_Type
    Private WLAN1 As WLAN_Type
    s.System = System1
    s.WLAN = WLAN1
    
    s = bc.ObjectFromBytes(GlobalStore.Slot0)
    Dim str As String = s.WLAN.IP
'    Log("myIP: ", str) 'get the value from slot #0
    
End Sub

Am I doing something wrong or have I forgotten something?
Or ist ist not possible?

Error MSG:
B4X:
Exception (28):
epc1=0x402078ea epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000bda0 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffd30 end: 3fffffc0 offset: 01a0
3ffffed0:  40201e2c 3ffee518 0000bda1 4020202c 
3ffffee0:  3ffee518 00000002 00000001 402020cc 
3ffffef0:  3ffee518 00000002 00000000 40201585 
3fffff00:  3fffff10 00000002 00000001 40201427 
3fffff10:  4023a9d0 00000066 0000bda1 40201465 
3fffff20:  4023a9d8 4bc6a766 0147ae14 00000000 
3fffff30:  3fffff60 3fffff40 00000004 00000000 
3fffff40:  3fffff4c 00000066 4023a9d0 00000065 
3fffff50:  0000bda1 00995480 3ffee301 3ffe864a 
3fffff60:  0000bda1 3ffe863c 3ffee301 3ffee634 
3fffff70:  3fffdad0 00000000 3ffee338 40201c36 
3fffff80:  3fffdad0 3ffee358 3ffef194 402017fd 
3fffff90:  3fffdad0 00000000 3ffee5f4 40201db3 
3fffffa0:  feefeffe feefeffe feefeffe 40202adc 
3fffffb0:  feefeffe feefeffe 3ffe84e4 40100c09 
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1392, room 16
tail 0
chksum 0xd0
csum 0xd0
v3d128e5c
~ld

The Exception Decoder says:
B4X:
Exception 28: LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads
PC: 0x402078ea: strnlen_P at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/sys/xtensa/string_pgmspace.c line 34
EXCVADDR: 0x0000bda0

Decoding stack results
0x4020202c: Print::write(char const*) at C:\Users\Christian\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266/Print.h line 60
0x402020cc: Print::println() at C:\Users\Christian\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\Print.cpp line 184
0x40201585: B4R::B4RStream::Print(Print*, B4R::Object*) at Z:\### Programmieren ###\B4r\GlobalStore\Objects\bin\sketch\B4RStream.cpp line 55
0x40201427: B4R::Common::LogHelper(int, ...) at Z:\### Programmieren ###\B4r\GlobalStore\Objects\bin\sketch\B4RCore.cpp line 187
0x402017fd: B4R::Scheduler::loop() at Z:\### Programmieren ###\B4r\GlobalStore\Objects\bin\sketch\Scheduler.cpp line 79


THX
Chris
 

Chris160179

Member
Licensed User
Longtime User
Hello Erel,

Thank you for the info.
I will then switch to a Rasperry Pi Zero w and do this with B4J.
There are no restrictions regarding custom types here.
Changing global variables is also not limited.
Correct me if I'm wrong.

THX
Chris
 
Upvote 0
Top