B4R Question how to add AvailableRAM and StackBufferUsage ?

candide

Active Member
Licensed User
i have an issue with code below : it is OK at compilation but after esp8266 crash at execution of this sequence...
i want to add AvailableRAM and StackBufferUsage at a payload to make a remote monitoring
B4X:
           Dim  payload_out() As Byte
            payload_out = "rf_OK  ".getbytes
            payload_out = JoinBytes( Array(payload_out," Available RAM=".getbytes))
            payload_out = JoinBytes( Array(payload_out,AvailableRAM))
            payload_out = JoinBytes( Array(payload_out," Stack level=".getbytes))
            payload_out = JoinBytes( Array(payload_out,StackBufferUsage))

what is the best way to add both parameters at array of byte ? i didn't find...

thanks for your help
 

candide

Active Member
Licensed User
it in a MQTT client: when we receive a command from a mobile, i have to build a paypoad and to send it to my mobile

B4X:
Sub mqtt_MessageArrived(Topic As String, payload()As Byte)
    Log("Topic recu =",Topic,"  Payload=",payload)
    If Topic = bc.StringFromBytes(GlobalStore.slot7) Then  'cas message rfbridge
        audit(0) = 1
        audit(1) = 1
' case payload from rfbridge + sos_key is the googd one, we store this alarm
        If (bc.IndexOf(payload,GlobalStore.Slot11)= 87) Or (bc.IndexOf(payload,GlobalStore.Slot12)= 87) Then
            bc.ArrayCopy(bc.SubString2(payload,2,29),hr_last)
            If sosnb = 0 Then     bc.ArrayCopy(bc.SubString2(payload,2,29),hr_start)
            bc.ArrayCopy(bc.SubString2(payload,86,94),sos_key)
            If sosnb < 999 Then
              sosnb = sosnb + 1
             Else
                sosnb = 0
            End If    
        End If
    End If
    If Topic = bc.StringFromBytes(GlobalStore.Slot8) Then  'cas message android
        'request from mobile => we have to provide answer
        Dim Topic_out As String
        Dim  payload_out() As Byte
        Topic_out = bc.StringFromBytes(GlobalStore.slot10)
        If audit(1) = 1 Then 
            payload_out = "rf_OK  ".getbytes
        Else    
            payload_out = "rf_NOK ".getbytes
        End If
        If bc.IndexOf(payload,"reset") = 0 Then
            sosnb = 0
'            payload_out = JoinBytes( Array(payload_out," Available RAM=".getbytes))
'            payload_out = JoinBytes( Array(payload_out,(bc.StringfromBytes(AvailableRAM)).getbytes))
'            payload_out = JoinBytes( Array(payload_out," Stack level=".getbytes))
'            payload_out = JoinBytes( Array(payload_out,StackBufferUsage))
        End If
        If sosnb > 0 Then    
            payload_out = JoinBytes( Array(payload_out,"SOSnb:".getbytes))
            Dim ss As String = sosnb    
            Dim sas() As Byte = "          "
            bc.ArrayCopy(bc.StringToBytes(ss),sas)
            payload_out = JoinBytes( Array(payload_out,sas))
            payload_out = JoinBytes( Array(payload_out,"   ".getbytes))
            payload_out = JoinBytes( Array(payload_out,hr_start))
            If sosnb > 1 Then
                payload_out = JoinBytes( Array(payload_out,"    ".getbytes))
                payload_out = JoinBytes( Array(payload_out,hr_last))
            End If
            payload_out = JoinBytes( Array(payload_out,"    SOS=".getbytes))
            payload_out = JoinBytes( Array(payload_out,sos_key))
        End If
        Log("Topic out=",Topic_out," / ","payload=",payload_out)
        If WiFi.IsConnected = True Then        
            mqtt.Publish(Topic_out, payload_out)
        End If

    End If

End Sub

and i would like to have a view on stack and memory from my apk => i want to add AvailableRAM and StackBufferUsage in my payload
 
Upvote 0

candide

Active Member
Licensed User
in fact i found a way to add AvailableRAM and StackBufferUsage in an array of byte.

B4X:
            Dim ram1 As String = AvailableRAM
            Dim stack1 As String = StackBufferUsage
            payload_out = JoinBytes( Array(payload_out," Available RAM=".getbytes))
            payload_out = JoinBytes( Array(payload_out,ram1.getbytes))
            payload_out = JoinBytes( Array(payload_out," Stack level=".getbytes))
            payload_out = JoinBytes( Array(payload_out,stack1.getbytes))
 
Upvote 0

candide

Active Member
Licensed User
in fact correct code is this one :
Dim ram1 As String = NumberFormat(AvailableRAM,5,0)
Dim stack1 As String = NumberFormat(StackBufferUsage,4,0)
payload_out = JoinBytes( Array(payload_out," Available RAM=".getbytes))
payload_out = JoinBytes( Array(payload_out,ram1.getbytes))
payload_out = JoinBytes( Array(payload_out," Stack level=".getbytes))
payload_out = JoinBytes( Array(payload_out,stack1.getbytes))
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…