Add first version of risinghf parser
This commit is contained in:
parent
b41d1a67f1
commit
a05d1d2950
1 changed files with 64 additions and 0 deletions
64
python/risinghf.py
Normal file
64
python/risinghf.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Send lora packet to node-red when being triggered by postgresql
|
||||
# Nico Schottelius <nico.schottelius -at- ungleich.ch>
|
||||
# 2016-11-02
|
||||
# GPLv3+
|
||||
|
||||
|
||||
|
||||
import base64
|
||||
import binascii
|
||||
import logging
|
||||
import sys
|
||||
|
||||
# L A T I T U D E L O N G I TU DE
|
||||
# status temp deg min sec +hem deg min min min
|
||||
# 9e 17 46 58 204 0 009 02 320 a5 9a 0e e7
|
||||
# 1 2 3 4 5 6 ? 8 9 10 11 12 13 14
|
||||
|
||||
|
||||
# on display: 46 58 122N 09 02 207E
|
||||
# 46.58 204 09.02 320
|
||||
# sodaq: lat=46.9699219 lon=9.0391764
|
||||
# google: 46.969943, 9.038999
|
||||
|
||||
log = logging.getLogger("adeunis")
|
||||
log.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
|
||||
def get_humidity(hexpkg):
|
||||
humidity_value = int(hexpkg[6:8], 16)
|
||||
humidity = (125*humidity_value/(2**8))-6
|
||||
|
||||
return humidity
|
||||
|
||||
def get_temperature(hexpkg):
|
||||
temp_byte1 = int(hexpkg[2:4], 16)
|
||||
temp_byte2 = int(hexpkg[4:6], 16)
|
||||
|
||||
temp_value = (temp_byte2 << 8) + temp_byte1
|
||||
#print(temp_value)
|
||||
|
||||
temp = (175.72 * temp_value / (2**16)) - 46.85
|
||||
|
||||
# print("{}+{} {}{} {} - {}".format(temp_byte1,
|
||||
# temp_byte2,
|
||||
# hexpkg[4:6],
|
||||
# hexpkg[2:4],
|
||||
# temp_value, temp))
|
||||
|
||||
return temp
|
||||
|
||||
if __name__ == '__main__':
|
||||
payload_raw="gShne5YAM9av"
|
||||
payload_raw="AaxkRpYAmxfE"
|
||||
payload_bin=binascii.a2b_base64(payload_raw)
|
||||
payload_hex=binascii.b2a_hex(payload_bin)
|
||||
|
||||
print(get_temperature(payload_hex))
|
||||
print(get_humidity(payload_hex))
|
||||
|
||||
|
||||
# print("{} {}".format(payload_raw, payload_hex))
|
Loading…
Reference in a new issue