forked from Telos4/LoRa-Workshop
added examples for lora and lorawan
This commit is contained in:
parent
ea258abf20
commit
0cd1cf2d8c
20
micropython/examples/lora.py
Normal file
20
micropython/examples/lora.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
from lora_transceiver import LoRaTransceiver
|
||||||
|
|
||||||
|
from uPySensors.ssd1306_i2c import Display
|
||||||
|
|
||||||
|
d = Display()
|
||||||
|
|
||||||
|
# create transceiver for LoRaWAN frequency (channel 0 = 868.1 Mhz)
|
||||||
|
lora = LoRaTransceiver(frequency=868.1E6, syncword=0x34, display=d)
|
||||||
|
|
||||||
|
# change the spreading factor
|
||||||
|
lora.setSpreadingFactor(7)
|
||||||
|
|
||||||
|
# sending string data
|
||||||
|
lora.send_string('imaginaerraum')
|
||||||
|
|
||||||
|
# sending raw data
|
||||||
|
#lora.send([0x61, 0x62, 0x63])
|
||||||
|
|
||||||
|
# start receiving data
|
||||||
|
#lora.recv()
|
42
micropython/examples/lorawan.py
Normal file
42
micropython/examples/lorawan.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
from lora_transceiver import LoRaTransceiver
|
||||||
|
|
||||||
|
from uPySensors.ssd1306_i2c import Display
|
||||||
|
|
||||||
|
import uLoRaWAN
|
||||||
|
from uLoRaWAN.MHDR import MHDR
|
||||||
|
|
||||||
|
d = Display()
|
||||||
|
|
||||||
|
# create transceiver for LoRaWAN frequency (channel 0 = 868.1 Mhz)
|
||||||
|
lora = LoRaTransceiver(frequency=868.1E6, syncword=0x34, display=d)
|
||||||
|
|
||||||
|
# change the spreading factor
|
||||||
|
lora.setSpreadingFactor(9)
|
||||||
|
|
||||||
|
# set address and keys for LoRaWAN
|
||||||
|
devAddr = [0x26, 0x01, 0x16, 0x5C] # ir_test_device_01
|
||||||
|
#devAddr = [0x26, 0x01, 0x18, 0x52] # ir_test_device_02
|
||||||
|
#devAddr = [0x26, 0x01, 0x1E, 0x4F] # ir_test_device_03
|
||||||
|
|
||||||
|
nwkSKey = [0x9D, 0x95, 0x0F, 0xAB, 0xCB, 0x63, 0xD3, 0x04, 0xBC, 0x09, 0xC4, 0x9E, 0xC5, 0xDF, 0x3C, 0x37]
|
||||||
|
appSKey = [0xC9, 0x6C, 0x00, 0xD1, 0xB0, 0x1C, 0x2E, 0x42, 0x11, 0xBA, 0x32, 0x6F, 0x2F, 0xC2, 0x75, 0x6A]
|
||||||
|
|
||||||
|
devAddr_hex = " ".join(list(map(lambda x: "{0:02x}".format(x), devAddr))).upper()
|
||||||
|
nwkSKey_hex = " ".join(list(map(lambda x: "{0:02x}".format(x), nwkSKey))).upper()
|
||||||
|
appSKey_hex = " ".join(list(map(lambda x: "{0:02x}".format(x), appSKey))).upper()
|
||||||
|
print("devAddr: ", devAddr_hex)
|
||||||
|
print("nwkSKey: ", nwkSKey_hex)
|
||||||
|
print("appSKey: ", appSKey_hex)
|
||||||
|
|
||||||
|
# lorawan object for conversion of data in LoRaWAN message format
|
||||||
|
lorawan = uLoRaWAN.new(nwkSKey, appSKey)
|
||||||
|
|
||||||
|
def send_lorawan(message, frame_cnt=0):
|
||||||
|
lorawan.create(MHDR.UNCONF_DATA_UP, {'devaddr': devAddr, 'fcnt': frame_cnt, 'data': list(map(ord, message)) })
|
||||||
|
payload = lorawan.to_raw()
|
||||||
|
|
||||||
|
lora.send(payload)
|
||||||
|
|
||||||
|
print("lorawan message sent")
|
||||||
|
|
||||||
|
send_lorawan("Hello world!")
|
Loading…
Reference in New Issue
Block a user