Question from another dummy…
I have a BME680 sensor is working with my Pi-Zero and I can pull temp, pressure and voc data. The Pi-Supply Lora phat is connected and sending data. My Pi-Supply gateway works fine, I’m connected to TTN and passing decoded variables across to TagoIO which visualizes them. So all great… however i’m having trouble with decoding the data I’m sending to the TTN.
I’m using the “hello world” example script, supplied as part of the setup tutorial, as a template and have added the code to pull the data from the sensor. I’m converting that to HEX and the using the lora.send(temp). temp= the variable containing the hex of the temp integer. Packets are being received but my attempts to decode are failing. My assumption is that the data is being sent as ASCII text.
I have a question in with Pi Supply as to how the RAK811 library is encoding the data using the send command and also how do I decode it in the TTN?
If I use the raw rak811 send command i get…
rak811 -v send --port 1 FF TTN sees 46 46 in the payload
rak811 -v send --port 1 255 TTN sees 32 35 35 in the payload
rak811 -v send --port 1 01 TTN sees 30 31 in the payload
rak811 -v send --port 1 --binary 011001 TTN sees - 01 10 01 in the payload
I’m struggling to work out what the code is doing so I can clean it up. Based on the other post I’m assuming this is being seen as ASCII. How do I need to format my data?
I’d like to send the my temperature integer as HEX. So I was assuming that I would take 25.3456, shorten it to 2 decimal places *100 and send as 2 bits, 09c4. I’ve read about how to be ever more efficient but for now I’d be happy to have this work. Any pointers?
Python code from a coder of 3 months experience…
#!/usr/bin/env python3
from rak811 import Mode, Rak811
import time
import board
from busio import I2C
import adafruit_bme680
i2c = I2C(board.SCL, board.SDA)
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False)
bme680.sea_level_pressure = 1013.25
while True:
print("\nTemperature: %0.1f C" % bme680.temperature)
print("Gas: %d ohm" % bme680.gas)
print("Humididty: %0.1f %%" % bme680.humidity)
print("Pressure: %0.3f hPa" % bme680.altitude)
temp = (bme680.temperature)
temp = temp*100
temp = round(temp, 0)
tempH = hex(int(temp)).lstrip("0x")
print(tempH)
gas = (bme680.gas)
gasH = hex(int(gas)).lstrip("0x")
print(gasH)
lora = Rak811()
lora.hard_reset()
lora.mode = Mode.LoRaWan
lora.band = 'EU868'
lora.set_config(dev_eui='3939353461xxxxxx',
app_eui='70B3D57ED00xxxxx',
app_key='D4CDC8FCB4C407093796E4298Axxxxxx')
lora.join_otaa()
lora.dr = 5
lora.send(tempH)
time.sleep(1)
rak811 -v send --port 1 --binary (tempH)
lora.close()
time.sleep(60)
TTN Java decoder I’ve been messing about with this…I have no Java knowledge/skills etc
function Decoder(bytes, port) {
var gas = (bytes[1] << 23 ) | bytes[0];
var temp = (bytes[0] << 0) | bytes[0];
return {
gas: gas,
temp: temp
}
}