Beispiel #1
0
def cancel():
    for x in range(10, 0, -1):
        print('nunning', x)
        utime.sleep(0.5)
        wdt_feed(5)  # Hold off for 5s

    wdt_feed(WDT_CANCEL)

    print('Pause 10s: should not reset in 5s')
    utime.sleep(10)
    print('WDT is permanently cancelled.')
Beispiel #2
0
def normal():
    try:
        for x in range(10, 0, -1):
            print('nunning', x)
            utime.sleep(0.5)
            wdt_feed(5)  # Hold off for 5s

        print('Should reset in 5s')
        utime.sleep(10)
    except KeyboardInterrupt:
        pass
    finally:
        wdt_feed(WDT_CANCEL)  # Should never execute
Beispiel #3
0
def default():
    for x in range(10, 0, -1):
        print('nunning', x)
        utime.sleep(0.5)
        wdt_feed(5)  # Hold off for 5s

    wdt_feed(0)  # Use default period
    print('Should reset in 2s')
    utime.sleep(10)
    wdt_feed(WDT_CANCEL)  # Should never execute
Beispiel #4
0
def suspend():
    for x in range(10, 0, -1):
        print('nunning', x)
        utime.sleep(0.5)
        wdt_feed(5)  # Hold off for 5s

    wdt_feed(WDT_SUSPEND)
    for x in range(5, 0, -1):
        print('suspended', x)
        utime.sleep(0.5)

    for x in range(5, 0, -1):
        print('nunning', x)
        utime.sleep(0.5)
        wdt_feed(5)  # Hold off for 5s

    print('Should reset in 5s')
    utime.sleep(10)
    wdt_feed(WDT_CANCEL)  # Should never execute
#    reset()
#
# InfluxDB query examples:
#    curl -sG "http://localhost:8086/query?pretty=true" --data-urlencode "q=SHOW DATABASES"
#    curl -sG "http://localhost:8086/query?pretty=true" --data-urlencode "db=test" --data-urlencode "q=SHOW MEASUREMENTS"
#    curl -sG "http://localhost:8086/query?pretty=true" --data-urlencode "db=test" --data-urlencode "q=SELECT * FROM garage ORDER BY DESC LIMIT 3"
#       NOTE: If there are '-' and '_' characters in the measurement name change query format to: FROM \"garage-bay\" ORDER
#    curl -sG "http://localhost:8086/query?pretty=true" --data-urlencode "q=DROP DATABASE test"
#
# InfluxDB AUthentication:
#    https://docs.influxdata.com/influxdb/v1.8/administration/authentication_and_authorization/
#

from soft_wdt import wdt_feed, WDT_CANCEL  # Initialize Watchdog Timer
wdt_feed(
    60
)  # main.py script has 1 minute to initialize and loop before Watchdog timer resets device

from machine import reset
from time import sleep
from uos import uname
import urequests
import gc

import key_store
from sys import exit

import AnalogDevices_TMP36

if 'TinyPICO' in uname().machine:
    import TinyPICO_RGB as led
    # Send the Data to Server
    data = "name,device=%s temp_F=%.01f,humidity=%.01f" % (client_id, temp_F,
                                                           sensor.humidity())
    response = urequests.post(url, data=data)
    #print('STATUS:', response.status_code)
    if '204' in str(
            response.status_code
    ):  # HTTP Status 204 (No Content) indicates server successfull fulfilled request with no response content
        print('Upload: Success')
        print()
    else:
        print('Upload: Failed')
        sleep(sleep_interval)
        reset()


while True:
    try:
        main()
        wdt_feed(
            sleep_interval * 2
        )  # Keep Watchdog Timer from resetting device for 2x sleep_interval
        sleep(sleep_interval)
    except KeyboardInterrupt:
        wdt_feed(
            WDT_CANCEL)  # Cancel/Disable Watchdog Timer when Ctrl+C pressed
        exit()
    except:
        sleep(sleep_interval)
        reset()
# --OR--
#
#     $ ampy --port /dev/ttyUSB0 put boot_with_wifi.py boot.py
#     $ screen /dev/ttyUSB0 115200
#     >>>  <Ctrl+a then Shift+k to exit repl>
#

print()
print('=' * 45)
print('boot.py: Press CTRL+C to drop to REPL...')
print()
#utime.sleep(3)  # A chance to hit Ctrl+C in REPL

try:
    from soft_wdt import wdt_feed, WDT_CANCEL  # Initialize Watchdog Timer
    wdt_feed(120)  # boot.py script has 2 minutes to complete before Watchdog timer resets device
except:
    print('soft_wdt.py module is not present')
    pass  # still works if soft_wdt.py is missing 

from machine import reset
import utime
from uos import uname

# Create exceptions (feedback) in cases where normal RAM allocation fails (e.g. interrupts)
from micropython import alloc_emergency_exception_buf
alloc_emergency_exception_buf(100)

if 'TinyPICO' in uname().machine:
    try:
        import TinyPICO_RGB