Esempio n. 1
0
 def rtc_init(self, year=0, month=0, day=0, hour=0, minute=0, second=0):
     rtc = machine.RTC()
     ntptime.settime()
     (year, month, mday, hour, minute, second, weekday, yearday)=utime.localtime(utime.time() + self.TIMEZONE_CORRECTION)
     rtc.datetime((year, month, mday, 0, hour, minute, second, 0))
def set_time(year, month, day, dayoweek, hour, minute, sec):
    machine.RTC().datetime((year, month, day, dayoweek, hour, minute, sec, 0))
Esempio n. 3
0
def settime():
    t = utime.localtime(time())
    machine.RTC().init((t[0], t[1], t[2], 0, t[3] + 1, t[4], t[5], t[6]))
Esempio n. 4
0

def read_settings():
    try:
        with open(config.SETTINGS_FILE) as f:
            settings = json.loads(f.read())
    except Exception:
        print('Error reading settings, using defaults')
        settings = config.DEFAULT_SETTINGS
        write_settings(settings)
    return settings


settings = read_settings()
wlan = network.WLAN(network.STA_IF)  # wifi connection
int_rtc = machine.RTC()  # internal RTC
sync_rtc()  # sync internal RTC with external RTC

# set deep sleep wakeup to alarm
int_rtc.irq(trigger=int_rtc.ALARM0, wake=machine.DEEPSLEEP)

reading = get_reading()

print('Temp: {1} Hum: {2}'.format(*reading))
# log to log file
write_log_line(config.LOG_FILE, reading)

num_readings = get_num_log_lines(config.QUEUE_FILE) + 1
if (num_readings >= settings['report_every'] and
        num_readings % settings['report_every'] <= settings['report_retries']):
    print('Time to transmit')
Esempio n. 5
0
def rtc():
    now = machine.RTC()
    return now.datetime()
Esempio n. 6
0
def do_deepsleep(seconds):
    rtc = machine.RTC()
    # Sleep n ms
    rtc.alarm(rtc.ALARM0, seconds * 1000)
    machine.deepsleep()
Esempio n. 7
0
def go_deep_sleep(sleeptime):
    st = sleeptime * 1000  # must be in milliseconds
    rtc = machine.RTC()
    rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
    rtc.alarm(rtc.ALARM0, st)
    machine.deepsleep()
import machine, time, term, buttons

# Deep sleep wakeup button
pin = buttons._gpioMap[buttons.BTN_A]
machine.RTC().wake_on_ext0(pin=pin, level=0)


def clear_boot_magic():
    rtc = machine.RTC()
    rtc.write(0, 0)
    rtc.write(1, 0)


def reboot(goHome=True):
    if goHome:
        home()
    else:
        machine.deepsleep(2)


def sleep(duration=0, status=False):
    if (duration >= 86400000):  #One day
        duration = 0
    if status:
        if duration < 1:
            term.header(True, "Sleeping until touchbutton is pressed...")
        else:
            term.header(True, "Sleeping for " + str(duration) + "ms...")
    time.sleep(0.1)
    machine.deepsleep(0)
def time():
    import machine
    year, month, day, weekday, hour, minute, second, msecs = machine.RTC(
    ).datetime()
    return mktime((year, month, day, hour, minute, second))
Esempio n. 10
0
def reset_chip():
    time.sleep(20)
    rtc = machine.RTC()
    rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
    rtc.alarm(rtc.ALARM0, 25000)
    machine.deepsleep()
Esempio n. 11
0
 def cleanmem(self):
     import machine
     machine.RTC().memory(b'')
Esempio n. 12
0
def set_time():
    ntptime.settime()
    tm = utime.localtime()
    tm = tm[0:3] + (0,) + tm[3:6] + (0,)
    machine.RTC().datetime(tm)
    print('current time: {}'.format(utime.localtime()))
def start():
    machine.RTC().memory('yaotaota')
    machine.reset()
Esempio n. 14
0
import machine
from machine import RTC
from machine import Timer
import main
import urtc
from time import time, sleep
from machine import Pin
my_time = machine.RTC().datetime()


def initalarm(rtc, rtc_wake):
    tim = machine.Timer(1)  # init with default time and date
    # create a RTC alarm that expires after 10 seconds
    #rtc.alarm(time=10000, repeat=True)
    #rtc_i = rtc.irq(trigger=RTC.ALARM0, handler=alarm_handler, wake=machine.SLEEP | machine.IDLE)
    tim.init(mode=tim.PERIODIC,
             period=2000,
             callback=alarm_handler(rtc, rtc_wake))


def alarm_handler(rtc, rtc_wake):

    rtc_wake = True
    main.alarmpolling(rtc, rtc_wake)
    print(rtc_wake)


def check_alarm_time(alarm_time, rtc, isStart):
    print('check alarm time')
    #def datetime_tuple(year=None, month=None, day=None, weekday=None, hour=None, minute=None, second=None, millisecond=None)
    currtime = rtc.datetime()
Esempio n. 15
0
def start_sleeping(time=0):
    pin = machine.Pin(25)
    rtc = machine.RTC()
    rtc.wake_on_ext0(pin=pin, level=0)
    badge.eink_busy_wait()
    machine.deepsleep(time)
Esempio n. 16
0
def rtc_setup():
    rtc = machine.RTC()
    rtc.ntp_sync(server="ntp.jst.mfeed.ad.jp", tz="JST-9")
    while not rtc.synced():
        time.sleep_ms(100)
Esempio n. 17
0
def clear_boot_magic():
    rtc = machine.RTC()
    rtc.write(0, 0)
    rtc.write(1, 0)
Esempio n. 18
0
#analog clock with ESP8266 and SSD1306 OLED display

import machine, ssd1306, math, time

i2c = machine.I2C(scl=machine.Pin(5),
                  sda=machine.Pin(4))  #setup the I2C protocol for the display
oled = ssd1306.SSD1306_I2C(128, 64, i2c, 0x3c)  #set up the display
rtc = machine.RTC()  #initiate the RealTimeClock

#setup clock elements

center = (31, 31)  #center of the clock in pixels
face_radius = 30
long_hand = 25  #length of the minutes hand
short_hand = 15  #length of the hours hand


def coordinates(angle, radius):
    '''calculate coordinates of a point on the circle given angle and radius'''

    x = int(center[0] + radius * math.cos(angle))
    y = int(center[1] + radius * math.sin(angle))

    return x, y


def time_decoder(timestamp):
    '''extract hours and minutes from a timestamp expressed in seconds since Epoch'''

    full_time = time.localtime(timestamp)  #returns a tuple
    hours = full_time[3] % 12  #fourth element is hours in 24hrs format
Esempio n. 19
0
from rowing.ui import RowUI
from rowing.display import DisplayHandler
from rowing.hardware import Hardware

# Movement tracking:
from rowing.loc_track import LocTracker
from rowing.stroke_track import StrokeTracker

# Logging:
from rowing.util.logging import Log, TransLog

# Chrono:
from rowing.util.chrono import Chrono

RTC = m.RTC()

VOLT_PERC = [(4.2, 100), (4.1, 90), (4.0, 80), (3.9, 60), (3.8, 40), (3.7, 20),
             (3.6, 10), (3.5, 5), (3.0, 0)]

_running = True
# Async:
_main_loop = asyncio.get_event_loop()
_acc_loop = asyncio.EventLoop(16, 16)

# Log:
_event_log = Log('/sd/event_log.txt')
_trans_log = Log('/sd/trans_log.txt')
# TODO: ADD RTC FOR LOGGING

# Components:
Esempio n. 20
0
WLAN_I = WLAN(mode=WLAN.STA, max_tx_pwr=78)
print('Connecting to WiFi %s' % CONFIG.get('wifi_ssid'))
WLAN_I.connect(CONFIG.get('wifi_ssid'),
               (WLAN.WPA2, CONFIG.get('wifi_password')),
               timeout=60000)
i = 0
while not WLAN_I.isconnected():
    i = i + 1
    # print(".", end="")
    utime.sleep(1)
    if i > 60:
        print("\nWifi not available")
        break

# Syncing time
RTCI = machine.RTC()
print('Syncing time with %s' % CONFIG.get('ntp_server'), end='')
RTCI.ntp_sync(CONFIG.get('ntp_server'))
while not RTCI.synced():
    print('.', end='')
    utime.sleep(1)
print('')

# read the private key
FILE_HANDLE = open("cert/%s-pk8.key" % CONFIG.get('device_id'))
PRIVATE_KEY = FILE_HANDLE.read()
FILE_HANDLE.close()

# make a mqtt client, connect and publish an empty message
MQTT_CLIENT = GoogleMQTTClient(CONFIG.get('project_id'), PRIVATE_KEY,
                               CONFIG.get('cloud_region'),
Esempio n. 21
0
def save_datetime(an, mo, jo, h, mn):
    #print(h, mn)
    rtc = machine.RTC()
    rtc.datetime((an, mo, jo, 6, h, mn, 0, 0))  # 6:dimanche
    print(rtc.datetime())
    ds.save_time()  # ecriture et sauvegarde de l'heure
Esempio n. 22
0
# RTC memory driver for MicroPython on ESP32
# MIT license; Copyright (c) 2017 Renze Nicolai

import machine as m

p = m.Pin(25)
r = m.RTC()
r.wake_on_ext0(pin=p, level=0)


def start_sleeping(self, time=0):
    m.deepsleep(time)


def reboot(self):
    m.deepsleep(1)
Esempio n. 23
0
def deep_sleep():
    print('Deep sleep...for .. 60s')
    rtc = machine.RTC()
    rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
    rtc.alarm(rtc.ALARM0, 60000)
    machine.deepsleep()
            rgb.image(data, (12, 0), (8, 8))
            time.sleep(3)
            rgb.clear()
            print("Error connecting to wifi")
            system.reboot()

    if not ntp.set_NTP_time():
        print("Error setting time")
        system.reboot()

wifi.disconnect()

## Taken from Bas' PrettyClock.
## Get your timezone from
## https://remotemonitoringsystems.ca/time-zone-abbreviations.php
rtc = machine.RTC()
timezone = machine.nvs_getstr('system', 'timezone')
if timezone is None:
    timezone = 'CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00'
machine.RTC().timezone(timezone)


def input_B(pressed):
    global direction
    direction = defines.BTN_B


buttons.register(defines.BTN_B, input_B)

gifd = [0, 0x00FFFFFF, 0, 0, 0, 0x00FFFFFF, 0, 0, 0, 0, 0, 0, 0, 0]
def current_time():
    return machine.RTC().datetime()
Esempio n. 26
0
def settime():
    t = time_now()
    tm = time.localtime(t)
    tm = tm[0:3] + (0, ) + tm[3:6] + (0, )
    machine.RTC().datetime(tm)
Esempio n. 27
0
def get_networktime():
    import machine
    my_timezone = "CET-1CEST" # found in second field, text before the coma, in https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/blob/master/MicroPython_BUILD/components/micropython/docs/zones.csv
    rtc = machine.RTC()
    rtc.init((2018, 01, 01, 12, 12, 12))
    rtc.ntp_sync(server= "", tz=my_timezone, update_period=3600)
Esempio n. 28
0
def setup_rtc():
    rtc = machine.RTC()
    rtc.ntp_sync("pool.ntp.org")
    while not rtc.synced():
        utime.sleep_ms(100)
    utime.timezone(3600)
Esempio n. 29
0
                      freq=20000)
    d = DHT12_I2C(i2c, 92)
    d.measure()
    print(d.temperature(), d.humidity())

    try:
        c = MQTTClient("umqtt_client", server)
        c.connect()
        print("Connected to " + server)
        c.publish(topic + '/temperature', str(d.temperature()))
        time.sleep_ms(100)
        c.publish(topic + '/humidity', str(d.humidity()))
        time.sleep_ms(100)
        c.disconnect()
        time.sleep_ms(100)
    except Exception as e:
        print(e)
        pass
else:
    print('power on or hard reset')

# configure RTC.ALARM0 to be able to wake the device
rtc = machine.RTC()
rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)

# set RTC.ALARM0 to fire after 10 seconds (waking the device)
rtc.alarm(rtc.ALARM0, 10000)

# put the device to sleep
machine.deepsleep()
Esempio n. 30
0
def postar_dados(email, dispositivo):
    import time
    import json
    from urequests import *

    email = email[:email.index('@')]

    date = "{}-{}-{}".format(machine.RTC().datetime()[2],
                             machine.RTC().datetime()[1],
                             machine.RTC().datetime()[0])

    if (machine.RTC().datetime()[5] < 10
            and (machine.RTC().datetime()[4] - 3) > 10):
        time = "{}:0{}".format(machine.RTC().datetime()[4] - 3,
                               machine.RTC().datetime()[5])
    if (machine.RTC().datetime()[5] < 10
            and (machine.RTC().datetime()[4] - 3) < 10):
        time = "0{}:0{}".format(machine.RTC().datetime()[4] - 3,
                                machine.RTC().datetime()[5])
    if (machine.RTC().datetime()[5] > 10
            and (machine.RTC().datetime()[4] - 3) < 10):
        time = "0{}:{}".format(machine.RTC().datetime()[4] - 3,
                               machine.RTC().datetime()[5])
    if (machine.RTC().datetime()[5] > 10
            and (machine.RTC().datetime()[4] - 3) > 10):
        time = "{}:{}".format(machine.RTC().datetime()[4] - 3,
                              machine.RTC().datetime()[5])

    tipo_dispositivo = dispositivo

    dicionario_pot = {}

    dicionario_pot["potencia"] = 155.56 * getCurrentAC(5)

    print("http://micropython-1e299.firebaseio.com/" + email + "/" +
          tipo_dispositivo + "/" + date + "/" + time + "/.json")
    print("Json postado ->", dicionario_pot)
    try:
        request("PUT",
                "https://micropython-1e299.firebaseio.com/" + email + "/" +
                tipo_dispositivo + "/" + date + "/" + time + "/.json",
                data=json.dumps(dicionario_pot))
    except OSError:
        machine.reset()