diff --git a/python/risinghf.py b/python/risinghf.py new file mode 100644 index 0000000..55b62ad --- /dev/null +++ b/python/risinghf.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 + +# Send lora packet to node-red when being triggered by postgresql +# Nico Schottelius +# 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))