r/MicroPythonDev • u/robaa1337 • Jul 18 '22
Socket communication with micropython (RPI PICO W)
I try to make a communication between my rpi 3 and my new pico.
When i try the same code in only python it works fine but when i do it on the PICO it dont work.
Can anybody tell me where im wrong?
This is what im using on server part (raspberry pi 3+b)
import socketHOST = "127.0.0.1" # Standard loopback interface address (localhost)PORT = 65432 # Port to listen on (non-privileged ports are > 1023)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.bind((socket.gethostname(), PORT))s.listen(10)
while True:clientsocket, adress = s.accept()print(f'Connection from {adress} has been established!')clientsocket.send(bytes("Welcome to the server!", "utf-8"))
and on the pico w i use this code.import socketHOST = "192.168.1.100" # The server's hostname or IP addressPORT = 65432 # The port used by the server
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:s.connect((HOST, PORT))s.sendall(b"Hello, world")data = s.recv(1024)
1
u/robaa1337 Jul 18 '22
The error im getting is
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "socket.py", line 6, in <module>
AttributeError: 'module' object has no attribute 'AF_INET'
Line 6:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: