Hi Team,
I am trying to program a simple socket connection between the ESP8266 board (Adafruit Feather HUZZAH with ESP8266), client side, to a Raspberry Pi 3, server side. Can you help me getting any directions to create this simple application?
Thanks a lot and very best regards,
ESP8266 Micropython TCP Socket Simple Sample Code
-
- Posts: 463
- Joined: Wed Apr 08, 2015 5:19 am
Re: ESP8266 Micropython TCP Socket Simple Sample Code
On the Raspberry Pi run a TCP server listening on port 8000 (lets assume its IP address visible to the ESP8266 is 192.168.4.2) in a terminal:
On the ESP8266 run the following to connect to the server and send the string "Hello World!":
The terminal output on the Raspberry Pi should now show "Hello World!".
For further information see https://docs.python.org/3/howto/sockets.html.
Code: Select all
$ netcat -l --tcp --local-port=8000
Code: Select all
import socket
sock = socket.socket()
addrinfos = socket.getaddrinfo('192.168.4.2', 8000)
# (host and port to connect to are in 5th element of the first tuple in the addrinfos list
sock.connect(addrinfos[0][4])
sock.send("Hello World!")
sock.close()
For further information see https://docs.python.org/3/howto/sockets.html.