add decoder, pylint
This commit is contained in:
parent
ed60265c85
commit
df870c39aa
2 changed files with 25 additions and 7 deletions
16
lorawan_sensing_network/ttn_decoder_bme280.js
Normal file
16
lorawan_sensing_network/ttn_decoder_bme280.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// TinyLoRa - BME280 and Feather ID Decoder
|
||||
function Decoder(bytes, port) {
|
||||
var decoded = {};
|
||||
|
||||
// Decode bytes to int
|
||||
var celciusInt = (bytes[1] << 8) | bytes[2];
|
||||
var humidInt = (bytes[3] << 8) | bytes[4];
|
||||
|
||||
// Decode Feather ID
|
||||
decoded.featherID = bytes[0]
|
||||
// Decode int to float
|
||||
decoded.celcius = celciusInt / 100;
|
||||
decoded.humid = humidInt / 100;
|
||||
|
||||
return decoded;
|
||||
}
|
||||
|
|
@ -3,12 +3,13 @@ import board
|
|||
import busio
|
||||
from digitalio import DigitalInOut
|
||||
import adafruit_bme280
|
||||
from adafruit_bme280 import Adafruit_BME280_I2C
|
||||
from adafruit_tinylora.adafruit_tinylora import TTN, TinyLoRa
|
||||
|
||||
# BME280
|
||||
# Unique feather identifier
|
||||
FEATHER_ID = 1
|
||||
|
||||
i2c = busio.I2C(board.SCL, board.SDA)
|
||||
bme280 = Adafruit_BME280_I2C(i2c)
|
||||
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
|
||||
|
||||
# TinyLoRa/RFM9x Setup
|
||||
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
|
||||
|
|
@ -34,14 +35,15 @@ lora = TinyLoRa(spi, cs, irq, ttn_config, channel = 6)
|
|||
bme_d = bytearray(7)
|
||||
|
||||
while True:
|
||||
# Grab sensor data
|
||||
temp_val = int(bme280.temperature * 100)
|
||||
humid_val = int(bme280.humidity * 100)
|
||||
|
||||
bme_d[0] = 0x01
|
||||
|
||||
bme_d[0] = FEATHER_ID
|
||||
# Temperature data
|
||||
bme_d[1] = (temp_val >> 8) & 0xff
|
||||
bme_d[2] = temp_val & 0xff
|
||||
# Humid data
|
||||
# Humidity data
|
||||
bme_d[3] = (humid_val >> 8) & 0xff
|
||||
bme_d[4] = humid_val & 0xff
|
||||
|
||||
|
|
@ -49,4 +51,4 @@ while True:
|
|||
lora.send_data(bme_d, len(bme_d), lora.frame_counter)
|
||||
print('Packet sent!')
|
||||
lora.frame_counter += 1
|
||||
time.sleep(2)
|
||||
time.sleep(1 * 60)
|
||||
|
|
|
|||
Loading…
Reference in a new issue