Skip to content

Instantly share code, notes, and snippets.

@pgorczak
Last active March 29, 2018 09:10
Show Gist options
  • Select an option

  • Save pgorczak/c14aa5f3660961dc6c08aa5d0b3f5716 to your computer and use it in GitHub Desktop.

Select an option

Save pgorczak/c14aa5f3660961dc6c08aa5d0b3f5716 to your computer and use it in GitHub Desktop.
Simplest half-duplex serial over Pycom LoRa

Dead simple serial-over-LoRa pipe using Pycom modules.

Note that this example is only half-duplex. You will need to implement some kind of flow control / media access control to be able to use it like a full duplex pipe.

import machine
machine.main('main.py')
import select
import socket
from machine import UART
from network import LoRa
uart = UART(0, baudrate=115200)
lora_card = LoRa(mode=LoRa.LORA, region=LoRa.EU868)
lora = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
lora.setblocking(True)
ios = [uart, lora]
while True:
readable, _, _ = select.select(ios, [], [])
if lora in readable:
uart.write(lora.recv(128))
if uart in readable:
lora.send(uart.read(128))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment