def lora_thread(): '''Handles connection to LoRa,reads drone voltage battery and sends data values.''' print("\nStarting program...\n") while True: try: vbat = voltage_measure.vbat_measure( voltage_pin.voltage()) #get new battery voltage value if not lora.lora_connected: #if lora isn't connected, connect it. lora.connect_lora(app_eui, app_key) pycom.rgbled(green) sounds.lora_connected() elif alarm_active: print("Alarm!") lora.send_values( alarm_temp, vbat) #send 2 floats: alarm temperature and voltage else: lora.send_values( sensor_temp, vbat ) #send 2 floats: sensor temperature and battery voltage except OSError as er: print("Connectivity issue: " + str(er)) lora.lora_connected = False except Exception as e: print("General error: " + str(e)) lora.lora_connected = False
#import CayenneLPP import i2c_read import lora import struct import time import read_dht lora.connect_lora() from lora import s # // byte 0,1 are for co2. No need of signed, and range of sensor is 400-8192. # var co2 = (bytes[0] << 8) | bytes[1]; # // byte 2,3 are for VOC. range 0-1187de # var voc = (bytes[2] << 8) | bytes[3]; # // byte 4,5 pressure in hPa # var bmp_pressure = (bytes[4] << 8) | bytes[5]; # // byte 7 temp from bmp # var bmp_temp = bytes[3]; # // byte 8 temp from dht # var dht_temp = (bytes[2] << 8) | bytes[3]; # // byte 9 RH from dht # var dht_RH = (bytes[2] << 8) | bytes[3]; def send_value(): co2, voc, bmp_P, bmp_T = i2c_read.value() dht_T, dht_RH = read_dht.value() print('co2: ', co2) # two bytes print('voc: ', voc) # two bytes print( 'bmp P: ', bmp_P