Created
March 19, 2018 10:31
-
-
Save matthieubrient/95f87ba079f510aed0b1ca597b33c458 to your computer and use it in GitHub Desktop.
LPWAN_Raspberry_LoPy_serial_connectivity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import UART | |
import pycom | |
import time | |
from network import LoRa | |
import socket | |
import binascii | |
import struct | |
pycom.heartbeat(False) # turn off heartbeat | |
uart1 = UART(1, 115200, bits=8, parity=None, stop=1) | |
uart1.init(baudrate=115200, bits=8, parity=None, stop=1, timeout_chars=2, pins=("P3", "P4")) | |
uart1.write("Connected...") | |
lora = LoRa(mode=LoRa.LORAWAN) | |
app_eui = binascii.unhexlify('00 00 00 00 00 00 00 00'.replace(' ','')) | |
app_key = binascii.unhexlify('11 22 33 44 55 66 77 88 11 22 33 44 55 66 77 88'.replace(' ','')) | |
lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0) | |
while not lora.has_joined(): | |
time.sleep(2.5) | |
print('Not yet joined...') | |
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) | |
s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5) | |
s.setsockopt(socket.SOL_LORA, socket.SO_CONFIRMED, False) | |
pycom.heartbeat(False) | |
while True: | |
if uart1.any(): | |
data = uart1.readall() | |
pycom.rgbled(0xFF0000) # set LED to RED on if data received | |
print(data) | |
if data == b'send': | |
s.send("data") | |
pycom.rgbled(0x00FF00) # set LED to GREEN if data is b'send' | |
time.sleep(1) | |
pycom.rgbled(0x000000) | |
time.sleep(0.25) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment