Hi,
I want to send the hotspot data from an Android phone to a “XIAO ESP32-C3” board via a BLE connection.
The hotspot is set up by Android using this B4a code.
The XIAO ESP32-C3 should then establish a WiFi connection to the Android phone, and from that moment on, data should only be exchanged via WiFi.
Question: is this even possible?
I have been using this B4a code for B4a and this code below for B4r.
So far, I haven't even been able to connect to Hotpost.
The error message is always: Failed to connect.
Thank you very much.
Filippo
I want to send the hotspot data from an Android phone to a “XIAO ESP32-C3” board via a BLE connection.
The hotspot is set up by Android using this B4a code.
The XIAO ESP32-C3 should then establish a WiFi connection to the Android phone, and from that moment on, data should only be exchanged via WiFi.
Question: is this even possible?
I have been using this B4a code for B4a and this code below for B4r.
B4X:
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
Public Serial1 As Serial
Private wifi As ESP8266WiFi
Private client As WiFiSocket
Private astream As AsyncStreams
Private timer1 As Timer
'Private serverIp() As Byte = Array As Byte(192, 168, 178, 30) 'PC
'Private serverIp() As Byte = Array As Byte(192, 168, 178, 29) 'Samsung-S4
Private serverIp() As Byte = Array As Byte(192,168,178,96) 'Nokia G20
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
'ScanNetworks
If wifi.Connect2("ssid","password") Then 'change to your network SSID (use Connect2 if a password is required).
Log("Connected to wireless network.")
Else
Log("Failed to connect.")
Return
End If
timer1.Initialize("timer1_Tick", 1000)
timer1.Enabled = True
Connect(0)
End Sub
Sub Timer1_Tick
If client.Connected Then
astream.Write("Time here is: ").Write(NumberFormat(Millis, 0, 0))
End If
End Sub
Private Sub Connect(u As Byte)
If client.ConnectIP(serverIp, 51042) Then
Log("Connected to server.")
astream.Initialize(client.Stream, "astream_NewData", "astream_Error")
Else
Log("Failed to connect to server")
CallSubPlus("Connect", 1000, 0)
End If
End Sub
Sub AStream_NewData (Buffer() As Byte)
Log("Received: ", Buffer)
End Sub
Sub AStream_Error
Log("Error")
CallSubPlus("Connect", 1000, 0)
End Sub
Private Sub ScanNetworks 'ignore
Dim numberOfNetworks As Byte = wifi.Scan
Log("Found: ", numberOfNetworks, " networks.")
For i = 0 To numberOfNetworks - 1
Log(wifi.ScannedSSID(i))
Next
End Sub
The error message is always: Failed to connect.
Thank you very much.
Filippo