B4R Question ESP8266 + Android

Mostez

Well-Known Member
Licensed User
Longtime User
I want to build WiFi controlled car for my kid, I'll use mobile phone to control the car by sending text control commands to ESP8266 module.
as a start I want to know how to establish direct connection between ESP8266 module and Android to send simple text commands? wifi network may not be available in some places.

TIA
 

Num3

Active Member
Licensed User
Longtime User
My guess is you would have to program the ESP to be in AP Station mode, and connect the phone wifi to that station.
I am following this thread, I have the same question.
 
Upvote 0

rbghongade

Active Member
Licensed User
Longtime User
I would suggest:
Create app with MQTT broker service on smartphone
Start mobile hotspot
Connect the ESP to the mobile hotspot
Then you can send control commands and also receive sensor data ( if required)
 
Upvote 0

Mostez

Well-Known Member
Licensed User
Longtime User
Thank you for your help and suggestions,
the answer is here in Erel's tutorial, I've made little modifications to server code, my next step is design the mobile application to send data to ESP board
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private wifi As ESP8266WiFi
    Private server As WiFiServerSocket
    Private astream As AsyncStreams
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    Log(wifi.StartAccessPoint("esp_server"))
    Delay(200)
    RunNative("SetAP", Null)
    Delay(200)
    Log(wifi.LocalIp)
    Log(wifi.AccessPointIp)
    server.Initialize(80, "server_NewConnection")
    server.Listen
End Sub

#if C
void SetAP(B4R::Object* o) {
const char *ssid = "ESP32ap";
const char *password = "12345678";
 // Serial.begin(115200);
 // Serial.println("Configuring access point...");
 //WiFi.mode(WIFI_AP_STA);
 WiFi.mode(WIFI_AP);
  WiFi.softAP(ssid, password);
  //Serial.println("Wait 100 ms for AP_START...");
  delay(100);
  //Serial.println("Set softAPConfig");
  IPAddress Ip(192, 168, 10, 1);
  //IPAddress Ipgw(192, 168, 1, 1);
  IPAddress NMask(255, 255, 255, 0);
  WiFi.softAPConfig(Ip, Ip, NMask);
}
#end if

Sub Server_NewConnection (NewSocket As WiFiSocket)
    astream.InitializePrefix(NewSocket.Stream, False, "astream_NewData", "astream_Error")
    astream.Initialize(NewSocket.Stream, "astream_NewData", "astream_Error")
    Log("new connection")
End Sub

Sub astream_NewData (Buffer() As Byte)
    Log(Buffer)
    'server.Socket.Close 'disconnect to allow new connections
End Sub

Sub astream_Error
    Log("error")
    server.Listen
End Sub

Image1.jpg
 
Upvote 0
Top