board to board websocket communication

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
pipponefrancone
Posts: 10
Joined: Sat Sep 12, 2020 6:02 pm

board to board websocket communication

Post by pipponefrancone » Thu Sep 17, 2020 9:50 pm

Hello (again)!
I am trying to make an esp8266 talk to an esp32 using a softAP (no internet available). I am using the esp32 as the AP to wich the esp8266 connects to, and I am trying to use sockets to enstablish a fast comunication. I can successfully connect the esp8266 to the esp32 AP using those commands:

esp32 side:

Code: Select all

import network
wifi = network.WLAN(network.AP_IF)
wifi.config(essid='esp32-hello', password='1234')
wifi.active(True)
esp8266 side:

Code: Select all

import network
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect('esp32-hello','1234')
wifi.isconnected()
>>> True
The boards seem to be now connected via wifi. After that, I try to setup the esp32 as a server, and the esp8266 as a client using sockets:

esp32 side:

Code: Select all

import socket
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
address = socket.getaddrinfo('0.0.0.0', 9000)[0][-1]
s.bind(address)
s.listen(1)

client_sock, client_addrs = s.accept()
>>>   
I get the esp32 ip by doing:

Code: Select all

wifi.ifconfing()[0]
>>> '192.168.4.1'
esp8266 side:

Code: Select all

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.4.1',9000))
>>> Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    OSError: [Errno 9] EBADF
I am using the code provided by Clayton Darwing in this video as a reference. Esp32 is running micropython v1.12 + ulab (provided by forum user: rcolistete), Esp8266 is running stock micropython v1.13. What am I doing wrong? Thanks in advantance :)

Post Reply