B4R Question How to Make Two ESP8266 Talk each other, Is it possible?

yontala

Member
Licensed User
Longtime User
I have seen examples, and a esp8266 in server mode, but all the time connection is between esp8266 and PC or Android device. It's possible talk two NodeMCU esp8266 each other? How? Can anybody show a simple example?
 

derez

Expert
Licensed User
Longtime User
For connection by wire, do it like this, select any two pins instead of 10,11 in the example:
https://www.b4x.com/android/forum/t...-arduinos-with-rsoftwareserial-library.65779/
For connection through net - use the first part from here https://www.b4x.com/android/forum/threads/esp8266-getting-started.68740/ for the server, the second part for the client esp is like this:
B4X:
Sub Process_Globals
  Public Serial1 As Serial
  Private wifi As ESP8266WiFi
  Private client As WiFiSocket
  Private astream As AsyncStreams
  Private serverIp() As Byte = Array As Byte(192, 168, 0, xxx)
  Private ServerPort As UInt = xxxxx
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   If wifi.Connect2("xxxxxx","xxxxxxxxxx") Then ' fill in the correct data
     Log("Connected to wireless network.")
     Log(wifi.LocalIp)
   Else
     Log("Failed to connect.")
     Return
   End If
   Connect(0)
End Sub

Private Sub Connect(u As Byte)
   If client.ConnectIP(serverIp, ServerPort) 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

You can also use MQTT.
 
Last edited:
Upvote 0
Top