Dear All!
I have managed to set up my STEM dashboard with widgets of temperature, humidity, SNR, RSSI values of a Seeed Lora temperatue and humidity sensor. Sensor is sending data to helium network, than from helium console integration comes to STEM. All working except the values of temperature and humidity are strange. Temperature shows 2.72 and humidity shows different values more above 100.
I guess it can be maybe the helium plugin decoder section problem, which shows below
Can you help me please the exact code of the decoding function?
Or any fix for this problem?
Thanks a lot!
"
import base64
def format_payload(args):
# Log received data for debugging purposes:
print(args)
# See Helium's default JSON schema at: https://developer.helium.com/console/integrations/json-schema
# Get RSSI and SNR variables using Helium hotspots data:
hotspots = args.get('hotspots', [])
ubidots_payload = {}
for i in range(len(hotspots)):
hotspot_name = hotspots[i].get('name', '')
rssi = hotspots[i].get('rssi', '')
snr = hotspots[i].get('snr', '')
# Use reported timestamp of each hotspot
ts = int(hotspots[i].get('reported_at', ""))
# Delete no longer needed keys from payload, and assign to context
hotspots[i].pop('rssi', None)
hotspots[i].pop('snr', None)
hotspots[i].pop('reported_at', None)
hotspot_context = hotspots[i]
# Format payload for RSSI and SNR
ubidots_payload['rssi-' + hotspot_name] = {'value': rssi, 'timestamp': ts, 'context': hotspot_context}
ubidots_payload['snr-' + hotspot_name] = {'value': snr, 'timestamp': ts}
# Get Fcnt and Port variables:
ubidots_payload['fcnt'] = args.get('fcnt', None)
ubidots_payload['port'] = args.get('port', None)
# Get main payload's timestamp
ubidots_payload['timestamp'] = int(args.get('reported_at', ""))
# See if there's a decoded payload already
decoded_payload = args.get('decoded', {}).get('payload', {})
# If no decoded payload was found, then decode here:
if not bool(decoded_payload):
bytes = base64.b64decode(args.get('payload', ''))
# This a sample decoder for RAK1906 WisBlock Environmental Sensor (https://docs.rakwireless.com/Product-Categories/WisBlock/RAK1906/Overview/#)
if bytes[0] == 1:
decoded_payload['temperature'] = (bytes[1] << 8 | (bytes[2])) / 100
decoded_payload['humidity'] = (bytes[3] << 8 | (bytes[4])) / 100
decoded_payload['pressure'] = (bytes[8] | (bytes[7] << 8) | (bytes[6] << 16) | (bytes[5] << 24)) / 100
decoded_payload['gas'] = bytes[12] | (bytes[11] << 8) | (bytes[10] << 16) | (bytes[9] << 24)
else:
print("ERROR: Didn't find a valid Wisblock payload")
# Clean up decoded_payload dict to avoid conflict
decoded_payload = {}
# Join dicts into Ubidots payload
ubidots_payload.update(decoded_payload)
return ubidots_payload"