예제 #1
0
def test_basic_cpython(caplog):

    # Use very basic settings without networking.
    import test.settings.basic as settings

    with FakeFS():

        with caplog.at_level(logging.DEBUG):

            # Invoke bootloader.
            bootloader = invoke_umal()

            # Start datalogger with a single duty cycle on a fake filesystem.
            from terkin.datalogger import TerkinDatalogger
            datalogger = TerkinDatalogger(
                settings, platform_info=bootloader.platform_info)
            datalogger.setup()
            datalogger.duty_task()

            # Capture log output.
            captured = caplog.text

            # Proof it works by verifying log output.
            assert "Starting Terkin datalogger" in captured, captured
            assert "platform: linux2" in captured, captured
예제 #2
0
def test_basic_esp32(caplog):

    # Use very basic settings without networking.
    import test.settings.basic as settings

    with FakeFS():

        with caplog.at_level(logging.DEBUG):

            # Invoke bootloader.
            bootloader = invoke_umal()

            # Start datalogger with a single duty cycle on a fake filesystem.
            from terkin.datalogger import TerkinDatalogger
            datalogger = TerkinDatalogger(
                settings, platform_info=bootloader.platform_info)
            datalogger.setup()
            datalogger.duty_task()

            # Capture log output.
            captured = caplog.text

            # Proof it works by verifying log output.
            assert "Starting Terkin datalogger" in captured, captured
            assert "platform: esp32" in captured, captured
            assert "[WiFi] Interface not enabled in settings." in captured, captured
            assert "[LoRa] Interface not enabled in settings." in captured, captured
            assert "[GPRS] Interface not enabled in settings." in captured, captured
            assert "Reading 0 sensor ports" in captured, captured
            assert "Sensor data:  {}" in captured, captured
            assert "Telemetry status: SUCCESS (0/0)" in captured, captured
예제 #3
0
def test_wifi_esp32(monkeypatch, caplog):

    # Define platform and start bootloader.
    monkeypatch.setattr(sys, 'platform', 'esp32')
    bootloader = invoke_umal()

    # Use very basic settings without networking.
    import test.settings.wifi as settings

    # Start datalogger with a single duty cycle on a fake filesystem.
    from terkin.datalogger import TerkinDatalogger
    with FakeFS():

        with caplog.at_level(logging.DEBUG):
            datalogger = TerkinDatalogger(settings, platform_info=bootloader.platform_info)
            datalogger.setup()
            datalogger.duty_task()

            # Capture log output.
            captured = caplog.text

            # Proof it works by verifying log output.
            assert "Starting Terkin datalogger" in captured, captured
            assert "platform: esp32" in captured, captured

            assert "WiFi STA: Preparing connection to network \"FooBarWiFi\"" in captured, captured
            assert "WiFi STA: Connected to \"FooBarWiFi\"" in captured, captured
            assert "Network stack ready" in captured, captured

            assert "[LoRa] Interface not enabled in settings" in captured, captured
            assert "[GPRS] Interface not enabled in settings" in captured, captured
            assert "Reading 0 sensor ports" in captured, captured
            assert "Sensor data:  {}" in captured, captured
            assert "Telemetry status: SUCCESS (0/0)" in captured, captured
예제 #4
0
def test_wifi_cpython(monkeypatch, caplog):

    # Define platform and start bootloader.
    monkeypatch.setattr(sys, 'platform', 'linux2')
    bootloader = invoke_umal()

    # Use very basic settings without networking.
    import test.settings.wifi as settings

    # Start datalogger with a single duty cycle on a fake filesystem.
    from terkin.datalogger import TerkinDatalogger
    with FakeFS():

        with caplog.at_level(logging.DEBUG):
            datalogger = TerkinDatalogger(settings, platform_info=bootloader.platform_info)
            datalogger.setup()
            datalogger.duty_task()

            # Capture log output.
            captured = caplog.text

            # Proof it works by verifying log output.
            assert "Starting Terkin datalogger" in captured, captured
            assert "platform: linux2" in captured, captured

            assert "WiFi STA: Preparing connection to network \"FooBarWiFi\"" in captured, captured
            assert "WiFi STA: Connected to \"FooBarWiFi\"" in captured, captured
            assert "Network stack ready" in captured, captured
예제 #5
0
def test_uplink_wifi_mqtt(mosquitto, caplog, capmqtt):

    # Acquire settings with MQTT telemetry.
    import test.settings.telemetry_mqtt as settings

    # Use a fake filesystem.
    with FakeFS():

        with caplog.at_level(logging.DEBUG):

            # Invoke bootloader.
            bootloader = invoke_umal()

            # Invoke datalogger with a single duty cycle.
            from terkin.datalogger import TerkinDatalogger
            datalogger = TerkinDatalogger(
                settings, platform_info=bootloader.platform_info)
            datalogger.setup()
            datalogger.duty_task()

            # Capture log output.
            captured = caplog.text

            # Proof it works by verifying log output.
            assert "Starting Terkin datalogger" in captured, captured
            assert "platform: esp32" in captured, captured

            assert "WiFi STA: Preparing connection to network \"FooBarWiFi\"" in captured, captured
            assert "WiFi STA: Connected to \"FooBarWiFi\"" in captured, captured
            assert "Network stack ready" in captured, captured

            assert "Reading 4 sensor ports" in captured, captured
            #assert "Sensor data:  {}" in captured, captured

            assert "MQTT topic:   mqttkit-1/testdrive/area-42/node-01/data.json" in captured, captured
            assert 'MQTT payload: {"system.memfree": 1000000, "system.temperature": 44.7053182608696' in captured, captured
            assert "Telemetry status: SUCCESS (1/1)" in captured, captured

            data_reference = {
                "system.memfree": 1000000,
                "system.temperature": 44.7053182608696,
                "system.wifi.rssi": -85.3,
            }

            # Wait some time for message to arrive.
            time.sleep(0.2)

            message_1 = capmqtt.buffer()[0]
            data_1 = json.loads(message_1)
            del data_1['system.time']
            del data_1['system.uptime']
            del data_1['system.runtime']
            assert data_1 == data_reference, capmqtt.buffer()