示例#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_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
示例#4
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
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()
示例#6
0
def invoke_datalogger(caplog, settings, pycom=False, raspberrypi=False):

    # Use a fake filesystem.
    with FakeFS():

        # Pycom mounts the main filesystem at "/flash".
        if pycom:
            os.mkdir('/flash')

        if raspberrypi:
            os.makedirs('/sys/firmware/devicetree/base')
            with open('/sys/firmware/devicetree/base/model', 'w') as f:
                f.write('Raspberry')

            os.makedirs('/sys/bus/w1/devices/w1_bus_master1')
            with open('/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves',
                      'w') as f:
                f.writelines(['28-ff641d8fdf18c1\n', '28-ff641d8fc3944f\n'])

            os.makedirs('/sys/bus/w1/devices/w1_bus_master1/28-ff641d8fdf18c1')
            with open(
                    '/sys/bus/w1/devices/w1_bus_master1/28-ff641d8fdf18c1/w1_slave',
                    'w') as f:
                f.write('YES\nt=48187')

            os.makedirs('/sys/bus/w1/devices/w1_bus_master1/28-ff641d8fc3944f')
            with open(
                    '/sys/bus/w1/devices/w1_bus_master1/28-ff641d8fc3944f/w1_slave',
                    'w') as f:
                f.write('YES\nt=48187')

            os.makedirs('/dev')
            with open('/dev/i2c-3', 'w') as f:
                f.write('nonsense')

        # Capture log output.
        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_cycle()

            return datalogger