Exemplo n.º 1
0
def start_app(act_name, msg):
    global tft
    tft.text(msg, 5, 180, WHITE, RED)
    from machine import RTC, deepsleep
    rtc = RTC()
    rtc.memory(act_name)
    time.sleep(1)
    deepsleep(1)  # use deepsleep to reset and release memory
Exemplo n.º 2
0
def main(vs):
    global var_store, free_mem
    var_store = vs
    print("tfth.main")
    horo_main=var_store['horo_main']
    sd = var_store['sd']
    tft = var_store['tft']
    free_mem = var_store['free_mem']
    tzone = load_tzone()
    lat,lon,drx = load_geo_cfg()
    syn=sync_time()
    tm = get_time()
    ct = time.localtime(tm)
    yr,mon,mday,hr,minu,sec,wday,_,=ct    
    tfth = TFTHoro(tft,tzone=tzone, lat=lat,lon=lon,drx=drx)
    tfth.set_datetime(yr,mon,mday,hr,minu,sec)
    var_store['tfth']=tfth
    var_store['tft']=tft
    tft.start_spi()
    first_cycle=True
    while True:
        if chk_btn():
            break
        try:
            _t(horo_main,tfth,tft,first_cycle)
            if first_cycle:
                first_cycle=False
        except Exception as e:
            sys.print_exception(e)
            time.sleep(1)
        i=0
        while True:
            if chk_btn():
                break
            time.sleep(0.5)
            tm = get_time()
            ct = time.localtime(tm)
            yr,mon,mday,hr,minu,sec,wday,_,=ct
            colon=' '
            if i:
                colon=':'
            i = not i
            tft.draw_string_at(colon,244,165,fnt,fg=WHITE,bg=NAVY)
            if sec==0:
                if minu==0 or not syn:
                    # sync every hour
                    syn = sync_time()
                break
    # command mode
    free_mem()
    if btn['A']:
        print('ap_lunar')
        from machine import RTC, deepsleep
        rtc = RTC()
        rtc.memory('ap_lunar')
        #tft.text('Lunar calendar...',5,5)
        #time.sleep(1)
        deepsleep(1) # use deepsleep to reset and release all memory        
Exemplo n.º 3
0
def skip():
    # command mode
    free_mem()
    if tch:
        print('ap_lunar')
        from machine import RTC, deepsleep
        rtc = RTC()
        rtc.memory('ap_lunar')
        #tft.text('Lunar calendar...',5,5)
        #time.sleep(1)
        deepsleep(1) # use deepsleep to reset and release all memory        
Exemplo n.º 4
0
def handle_interrupt(v):
  global switch_active
  
  rtc = RTC()
  print('Switch Interrupt')
  
  if switch_active == False:
    switch_active = True
    rtc.memory(b'3')
    start_webserver()
    
  if switch_active == True:
    switch_active = False
    print('Switch Toggle Off')
def WriteRTCMemory(write_timestamp, pressure_value):
    from machine import RTC

    rtc = RTC()
    print('---> Now writing to ESP8266 RTC memory')
    
    data = '%d,%d,%d,%d,' % (write_timestamp,
                            curr_dst_status,
                            accuracy,
                            current_timestamp)
    for val in pressure_value:
        data += '%d,' % val
    data += '0' # flag as unverified

    rtc.memory(data)
def ReadRTCMemory(ERRORFILE, rel_Pres_Rounded_hPa):
    from machine import RTC

    global saved_dst_status, last_pval_timestamp, accuracy

    rtc = RTC()

    print('---> Now reading ESP8266 RTC memory')
    data = rtc.memory()
    
    if not data:
        print('Empty RTC memory -- assuming First Run')
        FirstTimeRun(rel_Pres_Rounded_hPa)

    data_list = [int(i) for i in data.split(b',')]

    last_pval_timestamp = data_list[0]
    saved_dst_status    = data_list[1]
    accuracy            = data_list[2]
    last_run_timestamp  = data_list[3]
    flag                = data_list[:-1]    

    VerifyLastRunCompleted(flag, last_run_timestamp, ERRORFILE)

    pressure_values = []
    for i in range(4, pval_count + 4):
        pressure_values.append(data_list[i])
    print('Last %d saved pressure values:' % pval_count,
             ('%d; ' * pval_count)[:-2] % tuple(pressure_values))

    return pressure_values
Exemplo n.º 7
0
def init_RTC(init):
    global r
    # pass list of bytes eg  [1, 1, 0, 0, 0]

    ###########################################
    # RTC 16KB of SRAM
    ###########################################

    # index into RTC memory, 2 bytes
    # r.memory()[0] is temp error state
    # r.memory()[1] is lipo error state
    # 2 number of temp read error since last reboot
    # 3 same for lipo
    # 4 number of watchdog popped

    r = RTC()
    mem = r.memory()  # content survives deep sleep
    print('RTC memory: ', mem)

    if (mem == b''):
        print('RTC memory empty. initializing..')
        #r.memory(bytearray(0b00000000)) # need object with buffer protocol

        # store x bytes in RTC
        # layout
        # 1 , 1 : reset error condition for sensor error. send alarm only first error and recovered
        # 0, 0, 0 : number of temp error, lipo error, watchdog reset , SINCE LAST POWER UP

        r.memory(bytes(init))  # need object with buffer protocol
        mem = r.memory()  # type bytes, immutable
        print('RTC memory: ', mem)  #  b'\x01\x01\x00\x00\x00'

    # to test a value  r.memory() [i]

    # to set a value
    # x=r.memory()
    # x=bytearray(x) make mutable
    # x[i]=1
    # r.memory(x)

    # bit operation possible as well
    # r.memory and wifi_error == 0 , test if bit not set
    # r.memory (r.memory() or wifi_error), set bit
    # r.memory (r.memory() and not wifi_error) reset bit

    else:
        pass
def FirstTimeRun(rel_Pres_Rounded_hPa):
    from cycle_machine import ResetMachine
    from machine import RTC

    global accuracy

    print('---> Starting initialization process')
    rtc = RTC()
    accuracy = 1

    data = '%d,%d,%d,%d,' % (current_timestamp,
                             curr_dst_status,
                             accuracy,
                             current_timestamp)
    for _ in range(pval_count):
        data += '%d,' % rel_Pres_Rounded_hPa
    print('---> Saved initial pressure data')
    data += '1'

    rtc.memory(data)
    
    print('Doing a reset now.')
    ResetMachine()
Exemplo n.º 9
0
# custo File → Preferences → User Settings tab size and detect

import gc
from machine import deepsleep, idle, RTC, reset_cause, DEEPSLEEP_RESET, DEEPSLEEP
from utime import sleep_ms, sleep, sleep_us, localtime, mktime
from machine import Pin
import framebuf

# check if the device woke from a deep sleep
if reset_cause() == DEEPSLEEP_RESET:
    print('woke from a deep sleep')
else:
    print('fresh boot')

r = RTC()
mem = r.memory()  # content survives deep sleep

print('RTC memory contents (bytes): ', mem)  # bytes

# initialize and increment RTC memory.  digit as string
if mem == b'':
    print('RTC memory empty. initializing with "0" ..')
    mem = "0"
    r.memory(mem)

mem_int = int(mem)

# avoid gosts
if mem_int == 9:
    avoid_ghost = True  # could be used to do some housekeeping on the display every x deep sleep
    mem_int = 1
Exemplo n.º 10
0
#hardware platform: FireBeetle-ESP8266

from machine import RTC
import time

rtc = RTC()  #create RTC object
print(rtc.datetime(
))  #print time(year, month, day, hour, minute, second, microsecond, tzinfo)

#rtc.datetime((2017,5,20,5,0,0,0,0))    #you can use this to set current time

print(rtc.datetime())
time.sleep(3.5)
print(rtc.datetime())
print(rtc.memory())  #print the memory of rtc
rtc.memory("dfrobot" + str(rtc.datetime()[6]))  #set rtc memory
Exemplo n.º 11
0
# check if the device woke from a deep sleep
if reset_cause() == DEEPSLEEP_RESET:
    print('ESP32: woke from a deep sleep')
else:
    print('ESP32: fresh boot')

###########################################
# RTC 16KB of SRAM
###########################################

# index into RTC memory, 2 bytes
# r.memory()[0] is temp error
# r.memory()[1] is lipo error

r = RTC()
mem = r.memory()  # content survives deep sleep
print('RTC memory: ', mem)

if (mem == b''):
    print('RTC memory empty. initializing..')
    #r.memory(bytearray(0b00000000)) # need object with buffer protocol

    # store 2 bytes in RTC # default OK
    r.memory(bytes([1, 1]))  # need object with buffer protocol
    mem = r.memory()  # type bytes, immutable
    print('RTC memory: ', mem)

# to test a value  r.memory() [i]

# to set a value
# x=r.memory()
Exemplo n.º 12
0
tft.bl_on()
tft.start_spi()
tft.fill_rect(0, 0, 240, 20, NAVY)
tft.text('starting...', 5, 5, WHITE, NAVY)
import gc
gc.collect()
var_store = {
    'tft': tft,
    'horo_main': horo_main,
    'free_mem': free_mem,
    'motor': motor,
    'rtcx': rtcx
}

rtc = RTC()
app_name = rtc.memory()
if not app_name:
    import ap_bmp_1
    ap_bmp_1.main(var_store)
    free_mem()
    app_name = 'ap_lunar'
else:
    app_name = app_name.decode('utf-8')

var_store['old_app_name'] = app_name
while app_name:
    old_app_name = app_name
    app = __import__(old_app_name)
    app_name = app.main(var_store)
    var_store['old_app_name'] = old_app_name
    del sys.modules[old_app_name]
Exemplo n.º 13
0
        print('RNG number repeated')
        break

for i in range(0, 10):
    machine.idle()

print("Active")

#print(machine.reset_cause() >= 0)
#print(machine.wake_reason() >= 0)

try:
    machine.main(123456)
except:
    print('Exception')

try:
    machine.main("other_main.py")
except:
    print('Exception')

# Test machine.RTC
from machine import RTC

rtc = RTC()
#reset memory
rtc.memory(b'')
print(rtc.memory())
rtc.memory(b'10101010')
print(rtc.memory())
Exemplo n.º 14
0
if machine.reset_cause() == machine.PWRON_RESET:
    initial_buzzer_duty = 512

buzzer = PWM(Pin(BUZZER_PIN), freq=4000, duty=initial_buzzer_duty)
time.sleep(0.05)
buzzer.duty(0)

leak_detect_pad = TouchPad(Pin(LEAK_TOUCHPAD_PIN))
leak_detect_pad.config(LEAK_CAP_THRESHOLD)
print("Slowing down touch sensor measurement rate")
esp32.set_touch_sensor_measurement_time(
    0xffff, # 2.28885 Hz
    0x1fff) # 1.02388 ms

rtc = RTC()
print("RTC memory: {}".format(rtc.memory()))
error_reported = True if rtc.memory() else False

blynk = blynklib.Blynk(secret.BLYNK_AUTH, log=print)
dishwasher = Device(blynk, buzzer, connect, leak_detect_pad)

if not dishwasher.is_leak():
    print("There is no leak")
    dishwasher.leak_led = False
    dishwasher.beacon()
    # The touchpad reading gets lower when wifi is activated so it's possible
    # that we get here (there is no leak) but still that the capacitance
    # shown below is below LEAK_CAP_THRESHOLD since here we sent a beacon
    # hence we are connected to wifi.
    # It doesn't affect a real leak since a leak bottoms out the capacitance
    # to 0.