Skip to content

Commit

Permalink
Merge pull request #6 from wizzdev-pl/WI21-66_device_lost_configurati…
Browse files Browse the repository at this point in the history
…on_after_shutdown

WI21-66 new irq to reset config. no config -> default ssid and password
  • Loading branch information
marcin-nawrocki-wizzdev authored Feb 22, 2021
2 parents 474b18b + fe13d87 commit 9247e64
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
17 changes: 15 additions & 2 deletions MicroPython/src/common/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from machine import Pin, reset
from esp32 import wake_on_ext0
from machine import Pin, reset, SLEEP, DEEPSLEEP
from esp32 import wake_on_ext0, WAKEUP_ALL_LOW, WAKEUP_ANY_HIGH
from lib.logging import debug, info
from data_upload.handlers_container import HandlerContainer
from communication.wirerless_connection_controller import get_mac_address_as_string
Expand Down Expand Up @@ -170,8 +170,17 @@ def as_dictionary(self):
# Below functions as static methods to config class?
# Interrput on pin 0
def button_irq(p):
debug("=== RESET BUTTON PRESSED ===")
save()
reset()


def reset_config(p):
debug("=== CONFIG BUTTON PRESSED ===")
global cfg
cfg.ap_config_done = False
cfg.ssid = DEFAULT_SSID
cfg.password = DEFAULT_PASSWORD
save()
reset()

Expand All @@ -188,6 +197,10 @@ def init():
button.irq(trigger=Pin.IRQ_FALLING, handler=button_irq)
wake_on_ext0(pin=button, level=False)

button2 = Pin(32, Pin.IN, Pin.PULL_UP)
button2.irq(trigger=Pin.IRQ_FALLING, handler=reset_config)
wake_on_ext0(pin=button2, level=WAKEUP_ALL_LOW)

debug("Configuration loaded")


Expand Down
12 changes: 9 additions & 3 deletions MicroPython/src/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

from machine import Pin, reset, reset_cause, wake_reason, HARD_RESET, PWRON_RESET, SOFT_RESET, PIN_WAKE
from logging import debug
import _thread
Expand All @@ -24,7 +26,6 @@ def configuration_access_point():
def main():
debug("=== MAIN START ===")

# TODO: Czy to potrzebne?
# Increase stack size per thread this increases micropython recursion depth
_thread.stack_size(8192*2)

Expand All @@ -33,7 +34,13 @@ def main():

# Check if configuration via access point has to be started
if not config.cfg.ap_config_done or wake_reason() == PIN_WAKE:
configuration_access_point()
debug("AP_DONE: {}, wake_reason: {}".format(config.cfg.ap_config_done, wake_reason()))
debug("SSID: {}, Password: {}".format(config.cfg.ssid, config.cfg.password))
if config.cfg.ssid != 'ssid' and config.cfg.password != 'password':
debug("SSID and password aren't default. Try to connect")
pass
else:
configuration_access_point()

debug("Main loop")
# If the device is powered on, then actual time from NTP server must be downloaded
Expand All @@ -52,6 +59,5 @@ def main():
# Good night!
power_save(config.cfg.data_publishing_period_in_ms)


if __name__ == '__main__':
main()

0 comments on commit 9247e64

Please sign in to comment.