hanze/muizenval

dump/esp-client/main.py in master
Repositories | Summary | Log | Files

main.py (1011B) download


 1from machine import Pin
 2from time import sleep
 3import config
 4import urequests as requests
 5
 6urlstatus = f"http://{config.SERVER}:{config.PORT}{config.ENDPOINTSTATUS}"
 7urlconnect =  f"http://{config.SERVER}:{config.PORT}{config.ENDPOINTCONNECT}"
 8
 9
10led = Pin(23, Pin.OUT)
11trap = Pin(15, Pin.IN, Pin.PULL_DOWN)
12connectbutton = Pin(4, Pin.IN, Pin.PULL_DOWN)
13state = False
14mac = "0000000000000001"
15#esp32.wake_on_ext1(pins = (button, button2), level = esp32.WAKEUP_ANY_HIGH)
16
17while connection.isconnected():
18    print(connectbutton.value())
19    print(trap.value())
20    new_state = trap.value()
21    led.value(new_state)
22    if state != new_state:
23        response = requests.post(urlstatus, json={ "mac": config.MAC, "status": new_state })
24        answer = response.json()
25        state = new_state
26        print(answer)
27    if connectbutton.value():
28        response = requests.post(urlconnect, json={ "mac": config.MAC })
29        answer = response.json()
30        print(answer)
31
32    sleep(config.DELAY)
33
34#deepsleep()