B4R Question Object to string for SSID name ESP8266

Amateurtje

Member
Licensed User
Longtime User
Hello,

I am starting with B4R and try to set up a ESP 8266. I have it set up as AP and as Network client and have it as a serial websocket. My problem now is that during the startup of the module, I want to send it through the serial port the SSID name, the WLAN Password and the mode (AP or Client).

through the serialisation I have divided 3 objects with the info
Object(0) is the mode
Object(1) is SSIDName
Object (2) is Password

The problem that i encounter is that it does not allow me to change a string. How can I get the object in a string and put it in the wifi.Connect(SSIDNaam)

object to string:
Sub Process_Globals
     Private     SSIDNaam As string
     Private    SSIDPass As Object
End Sub
Sub astreamCom_NewData(Buffer() As Byte)
      Dim be(50) As Object 'used as a storage buffer.
      Dim objects() As Object = ser.ConvertBytesToArray(Buffer, be)
      If objects.Length < 3 Then Return
      Instelling= objects(0)
      SSIDNaam = objects(1)
      SSIDPass = objects(2)
end sub

It is probably simple but I am getting a bit stuck..
 

Amateurtje

Member
Licensed User
Longtime User
Thanks (dankjewel?) janderkan for this info. This helps me getting started. I still have 1 problem. Maybe you, or anybody can help me.

it gives a lot of mistakes when trying to make from the objects an integer or a string.

When reading (log) object(0) it gives a 2. When trying to put this 2 into a integer, it makes the integer value -705.. When trying to put Object (1) and Object(2), containing strings into the GlobalStore, it crashes.
When writing it to a log, it does it without a problem, but logging seems to be very different than putting it into a variable or storing it with GlobalStore..

Probably related; also
B4X:
 If wifi.Connect(GlobalStore.Slot0) Then
gives an error and does not work, eventhough slot0 is filled with the correct wifi name. Directly with the correct string works perfectly...
 
Last edited:
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
Perhaps some code which I use may help.

In my app I use the following when using the SSID and password stored in GlobalStore in order to connect to the WiFi:

B4X:
Private bc As ByteConverter


If wifi.Connect3(bc.StringFromBytes(GlobalStore.slot0), bc.StringFromBytes(GlobalStore.Slot1), 0, GlobalStore.Slot2) = True Then

noting that I use Connect3 in lieu of Connect because as well as the SSID and password, I also store the BSSID using GlobalStore as I want to connect to a particular AP in the WiFi network.

Also in my app when reading the password from the ESP8266 file system in which I have files with the names of saved SSIDs in which the password is saved in order to save it in GlobalStore, I use the following:

B4X:
Private fs As ESP8266FileSystem

    If fs.OpenRead(bc.StringFromBytes(GlobalStore.Slot0)) Then
        fs.Position=0
        Dim buffer(fs.CurrentFile.size) As Byte
        GlobalStore.Put(1, bc.StringFromBytes(buffer))
        fs.Close
    Else
        Log("Cannot open file for read: ", bc.StringFromBytes(GlobalStore.Slot0))
    End If
 
Last edited:
Upvote 0
Top