Esempio n. 1
0
def deep_sleep():
    alarm.sleep_memory[0] = display_weather

    time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() +
                                      3600 * 24)
    alarm.exit_and_deep_sleep_until_alarms(time_alarm, pin_alarm_first_button,
                                           pin_alarm_second_button)
def go_to_sleep(sleep_period):
    # Turn off I2C power by setting it to input
    i2c_power = digitalio.DigitalInOut(board.I2C_POWER)
    i2c_power.switch_to_input()

    # Create a an alarm that will trigger sleep_period number of seconds from now.
    time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() +
                                      sleep_period)
    # Exit and deep sleep until the alarm wakes us.
    alarm.exit_and_deep_sleep_until_alarms(time_alarm)
Esempio n. 3
0
def go_to_sleep(sleep_period):
    # Create a an alarm that will trigger sleep_period number of seconds from now.
    time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + sleep_period)
    # Exit and deep sleep until the alarm wakes us.
    alarm.exit_and_deep_sleep_until_alarms(time_alarm)
Esempio n. 4
0
    if new_messages:
        for msg in new_messages:
            mqtt_client.publish(DATA_TOPIC,json.dumps(new_messages[msg]))
    # check for mqtt remote messages
    mqtt_client.loop()
    # break mqtt connection
    mqtt_client.disconnect()

# if we can't connect, cache message
else:
    for msg in new_messages:
        new_messages[msg]["N"]=0 # not new
        try:
            storage.remount('/',False)
            with open('/data.txt','a') as f:
                f.write(json.dumps(new_messages[msg])+'\n')
            storage.remount('/',True)
        except:
            print('Cant cache msg. Connected to usb?')
        gs.msg_cache=gs.msg_cache+1

gs.counter = gs.counter + 1

print('Finished. Deep sleep until RX interrupt or {}s timeout...'.format(gs.deep_sleep))
# wake up on IRQ or after deep sleep time
pin_alarm1 = alarm.pin.PinAlarm(pin=board.IO5, value=True, pull=False) # radio1
pin_alarm2 = alarm.pin.PinAlarm(pin=board.IO6, value=True, pull=False) # radio2
pin_alarm3 = alarm.pin.PinAlarm(pin=board.IO7, value=True, pull=False) # radio3
time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + gs.deep_sleep)
alarm.exit_and_deep_sleep_until_alarms(time_alarm,pin_alarm1,pin_alarm2,pin_alarm3)
Esempio n. 5
0
import alarm
import board
import time
import microcontroller
import storage

temperature = microcontroller.cpu.temperature
print("Temperature:", temperature)

try:
    with open("/log.txt", "a") as sdc:
        sdc.write("{}\n".format(temperature))
except OSError as e:
    print("Cannot write to fs, is GP4 grounded?")

## USB enumeration may take 4-5s per restart
time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + 10)

alarm.exit_and_deep_sleep_until_alarms(time_alarm)
# show bitmap

# CircuitPython 6 & 7 compatible
with open(bmp_file, "rb") as fp:
    bitmap = displayio.OnDiskBitmap(fp)
    tile_grid = displayio.TileGrid(
        bitmap, pixel_shader=getattr(bitmap, 'pixel_shader', displayio.ColorConverter())
    )
    group = displayio.Group()
    group.append(tile_grid)
    epd.show(group)
    time.sleep(epd.time_to_refresh + 0.01)
    epd.refresh()
    while epd.busy:
        pass

# # CircuitPython 7+ compatible
# bitmap = displayio.OnDiskBitmap(bmp_file)
# tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader)
# group = displayio.Group()
# group.append(tile_grid)
# epd.show(group)
# time.sleep(epd.time_to_refresh + 0.01)
# epd.refresh()
# while epd.busy:
#     pass

# go to sleep
alarm.exit_and_deep_sleep_until_alarms(*pin_alarms)
Esempio n. 7
0
        RESPONSE = MAGTAG.network.requests.get(DATA_SOURCE)
        VALUE = RESPONSE.json()

        # Choose a random project to display
        PROJECT = VALUE[random.randint(0, len(VALUE) - 1)]

        # Prepare the text to be displayed
        CLOSED = PROJECT["dateClose"].split("-")
        CLOSED.reverse()
        CLOSED = "/".join(CLOSED)

        print(PROJECT["name"])

        # Display the text
        MAGTAG.set_text(PROJECT["name"], 0, False)
        MAGTAG.set_text(CLOSED, 1, False)
        MAGTAG.set_text(PROJECT["description"], 2)

        # Play a song
        for notepair in SONG:
            MAGTAG.peripherals.play_tone(notepair[0], notepair[1] * 0.2)

        # Put the board to sleep for an hour
        time.sleep(2)
        print("Sleeping")
        PAUSE = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + 60 * 60)
        alarm.exit_and_deep_sleep_until_alarms(PAUSE)

    except (ValueError, RuntimeError) as e:
        print("Some error occured, retrying! -", e)
Esempio n. 8
0
    port=secrets["mqtt_port"],
    username=secrets["mqtt_username"],
    password=secrets["mqtt_password"],
    socket_pool=pool,
    ssl_context=ssl.create_default_context(),
)

print("Attempting to connect to %s" % mqtt_client.broker)
mqtt_client.connect()

while True:
    temperature, relative_humidity = sht.measurements

    output = {
        "temperature": temperature,
        "humidity": relative_humidity,
    }

    print("Publishing to %s" % MQTT_TOPIC)
    mqtt_client.publish(MQTT_TOPIC, json.dumps(output))

    if USE_DEEP_SLEEP:
        mqtt_client.disconnect()
        pause = alarm.time.TimeAlarm(monotonic_time=time.monotonic() +
                                     PUBLISH_DELAY)
        alarm.exit_and_deep_sleep_until_alarms(pause)
    else:
        last_update = time.monotonic()
        while time.monotonic() < last_update + PUBLISH_DELAY:
            mqtt_client.loop()
Esempio n. 9
0
def start_deep_sleep():
    magtag.set_text("Sleeping...zzz zzz zzz", 0, False)
    magtag.set_text("", 1, False)
    magtag.peripherals.deinit()
    pin_alarm = alarm.pin.PinAlarm(pin=board.BUTTON_A, value=False, pull=True)
    alarm.exit_and_deep_sleep_until_alarms(pin_alarm)
def alarm_deepSleep(how_long):
    time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() +
                                      how_long)
    alarm.exit_and_deep_sleep_until_alarms(time_alarm)