示例#1
0
def test_i2c(host):
    try:
        api = METFClient(host)

        api.pinMode(D2, INPUT)

        # Сигнал о пробуждении устройства
        assert api.wait_digital(D2, HIGH, 5.0)

        api.delay(20)

        # Поехали общаться
        api.i2c_begin(0, 2)
        api.i2c_setClock(100000)
        api.i2c_setClockStretchLimit(1500)

        addr = 10

        ret = api.i2c_ask(addr, 'M', 1)  # 'M'  mode

        ret = api.i2c_ask(addr, 'B', 10)  # 'B'  get data

    except HTTPError as err:
        log.error(err.response.text)
        raise Exception(err.response.text)
示例#2
0
def test_button(host):
    # Wait You press button
    # https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/
    api = METFClient(host)

    api.pinMode(D5, INPUT_PULLUP)
    assert api.digitalRead(D5) == HIGH
    assert api.wait_digital(D5, LOW, 3.0), "Button wasn't pressed"
    def test_button(self):
        # Wait You press button
        # https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/
        api = METFClient(ESP_HOST)

        api.pinMode(D5, INPUT_PULLUP)

        # check D5 is HIGH
        self.assertEqual(api.digitalRead(D5), HIGH)

        # 3 seconds for press button
        self.assertTrue(api.wait_digital(D5, LOW, 3.0),
                        "Button wasn't pressed")