37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
"""MicroMesh example for a generic ESP32 development board.
|
|||
|
|
|
||
|
|
Wiring (cross TX and RX):
|
||
|
|
ESP32 GPIO17 / UART2 TX -> Meshtastic radio RX
|
||
|
|
ESP32 GPIO16 / UART2 RX <- Meshtastic radio TX
|
||
|
|
ESP32 GND --- Meshtastic radio GND
|
||
|
|
|
||
|
|
Change the pin numbers when GPIO16 or GPIO17 is unavailable on your board.
|
||
|
|
"""
|
||
|
|
|
||
|
|
from machine import Pin, UART
|
||
|
|
from time import sleep_ms
|
||
|
|
|
||
|
|
from micromesh import PortNum, SerialInterface
|
||
|
|
|
||
|
|
|
||
|
|
def on_packet(packet):
|
||
|
|
if packet.WhichOneof("payload_variant") != "decoded":
|
||
|
|
return
|
||
|
|
if packet.decoded.portnum == PortNum.TEXT_MESSAGE_APP:
|
||
|
|
print("from !%08x: %s" % (
|
||
|
|
packet.from_, packet.decoded.payload.decode("utf-8", "replace")
|
||
|
|
))
|
||
|
|
|
||
|
|
|
||
|
|
uart = UART(2, baudrate=115200, tx=Pin(17), rx=Pin(16), timeout=0, rxbuf=1024)
|
||
|
|
mesh = SerialInterface(uart, on_packet=on_packet, on_log=print)
|
||
|
|
mesh.connect()
|
||
|
|
|
||
|
|
hello_sent = False
|
||
|
|
while True:
|
||
|
|
mesh.poll()
|
||
|
|
if mesh.config_complete and not hello_sent:
|
||
|
|
mesh.sendText("hello from ESP32")
|
||
|
|
hello_sent = True
|
||
|
|
sleep_ms(10)
|