def process_message(topic, payload): """The callback for when a PUBLISH message is received from the server.""" now = datetime.now() print(binascii.hexlify(payload)) frame = LppFrame().from_bytes(payload) measurement = "sensor" moist = frame.get_by_type(100)[0].value[0] snr = frame.get_by_type(100)[1].value[0] rssi = frame.get_by_type(100)[2].value[0] pfe = frame.get_by_type(100)[3].value[0] temp = frame.get_by_type(103)[0].value[0] voltsR = frame.get_by_type(116)[0].value[0] voltsS = frame.get_by_type(116)[1].value[0] id1 = frame.get_by_type(102)[0].value[0] id2 = frame.get_by_type(102)[1].value[0] sensor = int(id1) + (int(id2) << 16) json_body = [{ "measurement": measurement, "tags": { "sensor": sensor, }, "time": str(now), "fields": { "moist": moist, "temp": temp, "voltsR": voltsR, "voltsS": voltsS, "snr": snr, "rssi": rssi, "pfe": pfe } }] print(json_body) influxdb_client.write_points(json_body) send_to_farmos(sensor, payload)
def frame(): empty_frame = LppFrame() return empty_frame
def test_init_invalid_data_item(): with pytest.raises(Exception): LppFrame([0])
def test_init_invalid_data_nolist(): with pytest.raises(Exception): LppFrame(42)
def frame(): empty_frame = LppFrame() empty_frame.reset() return empty_frame
def frame_hlt(): hlt = LppFrame() hlt.add_humidity(3, 45.6) hlt.add_load(1, 160.987) hlt.add_temperature(2, 12.3) return hlt
def frame(): lf = LppFrame() lf.add_humidity(3, 45.6) lf.add_temperature(2, 12.3) return lf