B4R Question ESP32 WebSocket data length error

Mostez

Well-Known Member
Licensed User
Longtime User
I use ESP32 WebSocket to receive data from B4J server, WebSocket_NewMessage sub receives data from server and handle it as required, this part of code is not working as expected though other select case in the same sub are OK. the array size is 9, it should be 13 as sent from server side, any suggestions?

TIA

Server Side:
Dim WhoSendIt As String = ws.Session.GetAttribute("name")
    If cChkusedefaults Then cChkstaticip = False 'DHCP is the default value
    Dim Config As List   
    Config.Initialize
    '13 elements are sent to client device
    Config.AddAll(Array As String (WhoSendIt.ToUpperCase,cChkusedefaults,cDevicename.ToUpperCase,cServerIP, _
                    cServerport,cIPaddress,cGateway,cSubnet,cChkstaticip,cSSID,cPassword,cLCDContrast,cBacklightLevel))
    
                                
    CallSubDelayed3(PushShared,"UploadDeviceConfig",cTargetDevice,Config)

B4X:
Sub WebSocket_NewMessage (FunctionName As String, Params() As String)
    Select FunctionName
        Case FUNCTION_EMPL_INFO
            
            If ScreenType = SCREEN_TYPE_READ Then
                UpdateName(Params(1))
'                NLCD.PutString(1,31,Params(1),NLCD.Font8x16,False,False)
'                NLCD.InvertArea(0,30,NLCD.LCDWIDTH,18) 'highlight name
                If Params(0) = "E00" Then
                    UpdateSavedIcon(True)
                    BeepConfirm
                Else
                    UpdateSavedIcon(False)
                    BeepError
                End If
                NLCD.Update
            End If           
                    
        Case FUNCTION_SYNC_DATE_TIME ' sync server date time
            '(21,22,7,25,11,59,00,1) 'century,yr,mon,day,hr,min,sec,day of week, 7 = sunday
            DT(0) = 21
            DT(1) = Params(0)
            DT(2) = Params(1)
            DT(3) = Params(2)
            DT(4) = Params(3)
            DT(5) = Params(4)
            DT(6) = Params(5)
            DT(7) = Params(6)
            RTC.SetClock(DT,0,0)
            
        Case FUNCTION_SET_DEVICE_CONFIG 'this part is not working, array length error
Log(Params.Length) 'returns 9, should be 13

            Log(Params(0))
            Log(Params(1))
            Log(Params(2))
            Log(Params(3))
            Log(Params(4))
            Log(Params(5))
            Log(Params(6))
            Log(Params(7))
            Log(Params(8))
            Log(Params(9))
            Log(Params(10))
            Log(Params(11))
            Log(Params(12))
 

Attachments

  • srvr.jpg
    srvr.jpg
    189.5 KB · Views: 143
  • clt.jpg
    clt.jpg
    9.7 KB · Views: 144

Mostez

Well-Known Member
Licensed User
Longtime User
I've changed array size in rWebSocketClient.cpp file to:
C++:
 B4RString strings[20];
I also changed this line in WebSocketClient.cpp file to:
C++:
elementsInArray = Common_Min(21 - 1, elementsInArray + 1);
It worked OK, but I don't know if it the best solution or not!
 
Upvote 0
Top