testboard = Testboard(TESTBOARD_ID)

# Our Product's Input will be connected the Testboard's Pin D3, making it our
# Output Pin
OUTPUT_PIN = "D3"


def test_raise_flooding_alarm():
    # set PIN state
    testboard.digitalWrite(OUTPUT_PIN, HIGH)

    time.sleep(2)

    # Ask spanner to wait for 3 seconds while at the same time checking if we
    # got a command from the device
    result = device.waitForCommand(3)

    # Make sure we actually got a command, and we didn't just time out
    spanner.assertTrue(result.commandReceived)
    # Double check the name of the command
    spanner.assertEqual("alarm_triggered", command.name)
    spanner.assertEqual("water_flooding", command.value)


if __name__ == "__main__":

    spanner.runTest(test_raise_flooding_alarm())


# NOT READY
# should happen every two seconds, so we should definitely get one if we wait
# for 3. Of course this would never be a real world example, it's only for
# educational purposes

import time
import spanner
import Device from AWSDevice


device = Device("device_name")

def expect_network_cmd():

    # Ask spanner to wait for 3 seconds while at the same time checking if we
    # got a command from the device
    result = device.waitForCommand(3)

    # Make sure we actually got a command, and we didn't just time out
    spanner.assertTrue(result.commandReceived)
    # Double check the name of the command
    spanner.assertEqual("heartbeat_event", command.name)
    spanner.assertEqual("", command.value)


if __name__ == "__main__":

    spanner.runTest(expect_network_cmd())


# NOT READY
Beispiel #3
0
# The goal of this example is to show you how you can drive a digital input on
# your device that expects a PWM signal from the Testboard.
#
# In our particular example, we are only setting a value and not asserting
# anything. Of course this would never be a real world example, it's only for
# educational purposes

import time
import spanner
import Testboard

# Our Product's Input will be connected the Testboard's Pin D0, making it our
# Output Pin
OUTPUT_PIN = "D0"

testboard = Testboard("testboard_name")


def set_pwm_output():
    # In this example, we'll give it a 50% duty cycle. Our pwmWrite takes values
    # from 0 to 4095, so a 50% duty cycle would be 2047.
    testboard.pwmWrite(OUTPUT_PIN, 2047)
    # See also pwmWrite(pin, value, frequency)


if __name__ == "__main__":

    spanner.runTest(set_pwm_output())

# NOT READY