LoRa Network – Data plotting with Python

admin Hackster projekti

Sjajan tutorijal na Hackster portalu o tome kako napraviti projekat koji omogućava grafički prikaz podataka koje šalje LoRa uređaj.
Autor projekta je Luigi Francesco Cerfada

# LoraWAN sensor data Logging
 
import streams
from microchip.rn2483 import rn2483
from stm.hts221 import hts221
 
streams.serial()
 
try:
    rst = D16 # reset pin 
    # insert otaa credentials!
    appeui = "YOUAPPEUI"
    appkey =  "YOUAPPKEY"
    print("joining...")
    
    if not rn2483.init(SERIAL1, appeui, appkey, rst): # LoRa Click on slot A
        print("denied :(")
        raise Exception
 
    print("sending first message, res:")
    print(rn2483.tx_uncnf('TTN'))
 
    temp_hum = hts221.HTS221( I2C1,D31 ) # Temp Hum Click on slot C
    
    while True:
        temp, hum = temp_hum.get_temp_humidity()
        print('temp: ', temp, 'hum: ', hum)
        data = bytearray(4) 
        data[0:2] = bytearray([ int(temp) + 127, int((temp - int(temp)) * 100) ])
        data[2:4] = bytearray([ int(hum) + 127, int((hum - int(hum)) * 100) ])
        r = rn2483.tx_uncnf(data) # send data to TTN
        sleep(5000)
        
except Exception as e:
    print(e)