muizenval

Observe mouse traps remotely
Log | Files | Refs

main.py (1011B)


      1 from machine import Pin
      2 from time import sleep
      3 import config
      4 import urequests as requests
      5 
      6 urlstatus = f"http://{config.SERVER}:{config.PORT}{config.ENDPOINTSTATUS}"
      7 urlconnect =  f"http://{config.SERVER}:{config.PORT}{config.ENDPOINTCONNECT}"
      8 
      9 
     10 led = Pin(23, Pin.OUT)
     11 trap = Pin(15, Pin.IN, Pin.PULL_DOWN)
     12 connectbutton = Pin(4, Pin.IN, Pin.PULL_DOWN)
     13 state = False
     14 mac = "0000000000000001"
     15 #esp32.wake_on_ext1(pins = (button, button2), level = esp32.WAKEUP_ANY_HIGH)
     16 
     17 while 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()