in transform_binary_payload/src-payload-decoders/python/meteo_helix.py [0:0]
def dict_from_payload(base64_input: str, fport: int = None):
""" Decodes a base64-encoded binary payload into JSON.
Parameters
----------
base64_input : str
Base64-encoded binary payload
fport: int
FPort as provided in the metadata. Please note the fport is optional and can have value "None", if not
provided by the LNS or invoking function.
If fport is None and binary decoder can not proceed because of that, it should should raise an exception.
Returns
-------
JSON object with key/value pairs of decoded attributes
"""
decoded = base64.b64decode(base64_input)
# Printing the debug output
if DEBUG_OUTPUT:
print(f"Input: {decoded.hex().upper()}")
if len(decoded):
binary = data_to_bits(decoded)
# if physical property is 1111... = Sensor Error
if "0" not in binary:
return {"Error": "Sensor Error or N/A"}
# Message type - 2 bits
start_bit_offset, msg_type = bit_shift(binary, 0, 2)
# Battery - 5 bits
start_bit_offset, batt = bit_shift(binary, start_bit_offset, 5)
batt = round(batt * 0.05 + 3, 2)
# Temperature - 11 bits
start_bit_offset, temp = bit_shift(binary, start_bit_offset, 11)
temp = round(temp * 0.1 - 100, 2)
# T_min - 6 bits
start_bit_offset, t_min = bit_shift(binary, start_bit_offset, 6)
t_min = round((temp - t_min * 0.1), 2)
# T_max - 6 bits
start_bit_offset, t_max = bit_shift(binary, start_bit_offset, 6)
t_max = round((temp + t_max * 0.1), 2)
# Humidity - 9 bits
start_bit_offset, humid = bit_shift(binary, start_bit_offset, 9)
humid = round(humid * 0.2, 2)
# Pressure - 14 bits
start_bit_offset, press = bit_shift(binary, start_bit_offset, 14)
press = press * 5 + 50000
# Irradiation - 10 bits
start_bit_offset, irrad = bit_shift(binary, start_bit_offset, 10)
irrad = irrad * 2
# Irr_max - 9 bits
start_bit_offset, irr_max = bit_shift(binary, start_bit_offset, 9)
irr_max = irrad + (irr_max * 2)
# Rain - 8 bits
start_bit_offset, rain = bit_shift(binary, start_bit_offset, 8)
rain = round(rain, 2)
# Min_time_between_rain_gauge_clicks - 8 bits
start_bit_offset, min_time_between = bit_shift(binary, start_bit_offset, 8)
result = {
"Type": msg_type,
"Battery": batt,
"Temperature": temp,
"T_min": t_min,
"T_max": t_max,
"Humidity": humid,
"Pressure": press,
"Irradiation": irrad,
"Irr_max": irr_max,
"Rain": rain,
"Rain_min_time": min_time_between
}
return result