From 06e532ecc05e977c362e4e6313930ae13a86afa0 Mon Sep 17 00:00:00 2001 From: jonpas Date: Wed, 16 Jan 2019 13:18:00 +0100 Subject: [PATCH] Add VGS ESP8266 UDP to UART transparent bridge --- VGS_ESP8266_Bridge_UDP-UART/README.md | 8 +++++++ VGS_ESP8266_Bridge_UDP-UART/main.py | 32 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 VGS_ESP8266_Bridge_UDP-UART/README.md create mode 100644 VGS_ESP8266_Bridge_UDP-UART/main.py diff --git a/VGS_ESP8266_Bridge_UDP-UART/README.md b/VGS_ESP8266_Bridge_UDP-UART/README.md new file mode 100644 index 0000000..1fa51c2 --- /dev/null +++ b/VGS_ESP8266_Bridge_UDP-UART/README.md @@ -0,0 +1,8 @@ +Transparent UDP to UART bridge for ESP8266 (ESP-01 with 1MB flash) using MicroPython. + +### Setup + +- Flash MicroPython to ESP8266 module +- Configure UDP and UART details in `main.py` +- Upload `main.py` to the file system (`ampy --port put main.py`) +- Reboot ESP8266 module diff --git a/VGS_ESP8266_Bridge_UDP-UART/main.py b/VGS_ESP8266_Bridge_UDP-UART/main.py new file mode 100644 index 0000000..2ce2716 --- /dev/null +++ b/VGS_ESP8266_Bridge_UDP-UART/main.py @@ -0,0 +1,32 @@ +import network +import socket +from machine import UART + + +# CONFIGURATION +AP_NAME = "PixRacer" +AP_PASS = "pixracer" +HOST = "0.0.0.0" +PORT = 14450 +UART = 0 +BAUDRATE = 115200 + + +# Connect and transparently send raw data from UDP to UART +sta_if = network.WLAN(network.STA_IF) +ap_if = network.WLAN(network.AP_IF) + +sta_if.active(True) +ap_if.active(False) + +sta_if.connect(AP_NAME, AP_PASS) + +s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +s.bind((HOST, PORT)) + +uart = UART(UART, BAUDRATE) +uart.init(BAUDRATE) + +while True: + data = s.recv(1024) + uart.write(data)