Exemplo n.º 1
0
def test_frame_from_bytes():
    # 03 67 01 10 05 67 00 FF = 27.2C + 25.5C
    buf = bytes([0x03, 0x67, 0x01, 0x10, 0x05, 0x67, 0x00, 0xff])
    frame = LppFrame.from_bytes(buf)
    assert buf == bytes(frame)
    assert buf == frame.to_bytes()
    assert len(frame) == 2
    # 01 67 FF D7
    buf = bytes([0x01, 0x67, 0xFF, 0xD7])
    frame = LppFrame.from_bytes(buf)
    assert buf == bytes(frame)
    assert buf == frame.to_bytes()
    assert len(frame) == 1
    # 06 71 04 D2 FB 2E 00 00
    buf = bytes([0x06, 0x71, 0x04, 0xD2, 0xFB, 0x2E, 0x00, 0x00])
    frame = LppFrame.from_bytes(buf)
    assert buf == bytes(frame)
    assert buf == frame.to_bytes()
    assert len(frame) == 1
    # 01 88 06 76 5f f2 96 0a 00 03 e8
    buf = bytes(
        [0x01, 0x88, 0x06, 0x76, 0x5f, 0xf2, 0x96, 0x0a, 0x00, 0x03, 0xe8])
    frame = LppFrame.from_bytes(buf)
    assert buf == bytes(frame)
    assert buf == frame.to_bytes()
    assert len(frame) == 1
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
def frame():
    empty_frame = LppFrame()
    return empty_frame
Exemplo n.º 4
0
def test_frame_from_base64():
    base64 = "AYgILMMBiIMAAAACAAY="
    frame = LppFrame.from_base64(base64)
    assert len(frame) == 2
Exemplo n.º 5
0
def test_frame_from_bytes():
    # 03 67 01 10 05 67 00 FF = 27.2C + 25.5C
    buf = bytearray([0x03, 0x67, 0x01, 0x10, 0x05, 0x67, 0x00, 0xff])
    frame = LppFrame.from_bytes(buf)
    assert buf == frame.bytes()
    assert len(frame) == 2
Exemplo n.º 6
0
def test_init_invalid_data_item():
    with pytest.raises(Exception):
        LppFrame([0])
Exemplo n.º 7
0
def test_init_invalid_data_nolist():
    with pytest.raises(Exception):
        LppFrame(42)
Exemplo n.º 8
0
def frame():
    empty_frame = LppFrame()
    empty_frame.reset()
    return empty_frame
Exemplo n.º 9
0
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
Exemplo n.º 10
0
def test_frame_from_bytes_base64():
    base64_str = "AYgILMMBiIMAAAACAAY="
    frame = LppFrame.from_bytes(base64.decodebytes(base64_str.encode('ascii')))
    assert len(frame) == 2
Exemplo n.º 11
0
def frame():
    lf = LppFrame()
    lf.add_humidity(3, 45.6)
    lf.add_temperature(2, 12.3)
    return lf