A micropython server running on an ESP8266/ESP32 which acts as a bridge between UART and TCP (LAN/WLAN).
Follow steps to install esptool and micropython for ESP8266/ESP32.
Then...
- clone me, oh please, clone me!
$ git clone git@github.com/tiagocoutinho/us2n
- Create a file called
us2n.json
with a json configuration for Hardware UART:
import json
config = {
"name": "SuperESP32",
"verbose": False,
"wlan": {
"sta": {
"essid": "<name of your access point>",
"password": "<password of your access point>",
},
},
"bridges": [
{
"tcp": {
"bind": ["", 8000],
},
"uart": {
"port": 1,
"baudrate": 9600,
"bits": 8,
"parity": None,
"stop": 1,
},
},
],
}
with open('us2n.json', 'w') as f:
json.dump(config, f)
Note: if you are running us2n on an ESP32, specifying rx and tx pins is supported on hardware UART.
- Or, create a file called
us2n.json
with a json configuration for SoftUART:
import json
config = {
"name": "SuperESP32",
"verbose": False,
"wlan": {
"sta": {
"essid": "<name of your access point>",
"password": "<password of your access point>",
},
},
"bridges": [
{
"tcp": {
"bind": ["", 8000],
},
"uart": {
"type": "SoftUART",
"tx": 12,
"rx": 14,
"timeout": 20,
"timeout_char": 10,
"port": 1,
"baudrate": 9600,
"bits": 8,
"parity": None,
"stop": 1,
},
},
],
}
with open('us2n.json', 'w') as f:
json.dump(config, f)
- Include in your
main.py
:
import us2n
server = us2n.server()
server.serve_forever()
-
Load the newly created
us2n.json
to your ESP8266/ESP32 -
Load
us2n.py
to your ESP8266/ESP32 -
Load
main.py
to your ESP8266/ESP32 -
Press reset
The server board should be ready to accept requests in a few seconds.
Now, if, for example, your ESP8266/ESP32 UART is connected to a SCPI device, you can, from any PC:
$ nc <ESP8266/ESP32 Wifi IP> 8000
*IDN?
ACME Instruments, C4, 122393-2, 10-0-1
- Using socat to bridge back to a tty
$ socat pty,link=$HOME/dev/ttyV0,b9600,waitslave tcp:<ESP8266/ESP32 Wifi IP>:8000
- Connect to the virtual tty with miniterm.py
$ miniterm.py dev/ttyV0 9600
That's all folks!