Exemple #1
0
async def do_usec(minutes):
    tick = asyn.Event()
    print('Setting up GPS.')
    gps = await us_setup(tick)
    print('Waiting for time data.')
    await gps.ready()
    max_us = 0
    min_us = 0
    sd = 0
    nsamples = 0
    count = 0
    terminate = asyn.Event()
    loop = asyncio.get_event_loop()
    loop.create_task(killer(terminate, minutes))
    while not terminate.is_set():
        await tick
        usecs = tick.value()
        tick.clear()
        err = 1000000 - usecs
        count += 1
        print('Timing discrepancy is {:4d}μs {}'.format(
            err, '(skipped)' if count < 3 else ''))
        if count < 3:  # Discard 1st two samples from statistics
            continue  # as these can be unrepresentative
        max_us = max(max_us, err)
        min_us = min(min_us, err)
        sd += err * err
        nsamples += 1
    # SD: apply Bessel's correction for infinite population
    sd = int(math.sqrt(sd / (nsamples - 1)))
    print(
        'Timing discrepancy is: {:5d}μs max {:5d}μs min.  Standard deviation {:4d}μs'
        .format(max_us, min_us, sd))
    gps.close()
Exemple #2
0
 def __init__(self, mgr):
     self.pan = mgr.pan
     self.targetNodeId = None
     self.nodeOnlineEvent = asyn.Event()
     mgr.setPanCallback(self.onPanEvent)
     asyncio.create_task(self.loopTask()) # run a asyncio task
     log.info('App Starting')
Exemple #3
0
 def __init__(self, mgr, loop, pan):
     self.log = logging.getLogger("APP")
     self.log.setLevel(logging.DEBUG)
     self.pan = pan
     self.loop = loop
     self.targetNodeId = None
     self.nodeOnlineEvent = asyn.Event()
     mgr.setPanCallback(self.onPanEvent)
     self.loop.create_task(self.task())  # run a asyncio task
     self.log.info('App Starting')
Exemple #4
0
async def run_ack():
    loop = asyncio.get_event_loop()
    event = asyn.Event()
    ack1 = asyn.Event()
    ack2 = asyn.Event()
    count = 0
    while True:
        loop.create_task(event_wait(event, ack1, 1))
        loop.create_task(event_wait(event, ack2, 2))
        event.set(count)
        count += 1
        print('event was set')
        await ack1
        ack1.clear()
        print('Cleared ack1')
        await ack2
        ack2.clear()
        print('Cleared ack2')
        event.clear()
        print('Cleared event')
        await asyncio.sleep(1)
Exemple #5
0
async def run_event_test(lp):
    print('Test Lock class')
    loop = asyncio.get_event_loop()
    lock = asyn.Lock()
    loop.create_task(run_lock(1, lock))
    loop.create_task(run_lock(2, lock))
    loop.create_task(run_lock(3, lock))
    print('Test Event class')
    event = asyn.Event(lp)
    loop.create_task(eventset(event))
    await eventwait(event)  # run_event_test runs fast until this point
    print('Event status {}'.format('Incorrect' if event.is_set() else 'OK'))
    print('Tasks complete')
Exemple #6
0
 def __init__(self):
     self.p_red = Pin(env.PIN_NO_RED, Pin.OUT)
     self.p_green = Pin(env.PIN_NO_GREEN, Pin.OUT)
     self.p_blue = Pin(env.PIN_NO_BLUE, Pin.OUT)
     self.off()
     #p_red = PWM(Pin(env.PIN_NO_RED, Pin.OUT), freq=1000)
     #p_green = PWM(Pin(env.PIN_NO_GREEN, Pin.OUT), freq=1000)
     #p_blue = PWM(Pin(env.PIN_NO_BLUE, Pin.OUT), freq=1000)
     self.blinking_defs = {}
     self.blinking_def_id_sequence = 1
     self.blinking_def_id = None
     self.event = asyn.Event()
     loop = asyncio.get_event_loop()
     loop.create_task(self.blinking_watcher())
Exemple #7
0
async def do_drift(minutes):
    print('Setting up GPS.')
    gps = await setup()
    print('Waiting for time data.')
    await gps.ready()
    terminate = asyn.Event()
    loop = asyncio.get_event_loop()
    loop.create_task(killer(terminate, minutes))
    print('Setting RTC.')
    await gps.set_rtc()
    print('Measuring drift.')
    change = await drift_test(terminate, gps)
    ush = int(60 * change / minutes)
    spa = int(ush * 365 * 24 / 1000000)
    print('Rate of change {}μs/hr {}secs/year'.format(ush, spa))
    gps.close()
Exemple #8
0
async def do_time(minutes):
    fstr = '{}ms Time: {:02d}:{:02d}:{:02d}:{:06d}'
    print('Setting up GPS.')
    gps = await setup()
    print('Waiting for time data.')
    await gps.ready()
    print('Setting RTC.')
    await gps.set_rtc()
    terminate = asyn.Event()
    loop = asyncio.get_event_loop()
    loop.create_task(killer(terminate, minutes))
    while not terminate.is_set():
        await asyncio.sleep(1)
        # In a precision app, get the time list without allocation:
        t = gps.get_t_split()
        print(fstr.format(gps.get_ms(), t[0], t[1], t[2], t[3]))
    gps.close()
        self.maxLimitPin = Pin(maxLimitPinNo, Pin.IN)
#         self.minLimitPin = Pin(minLimitPinNo,Pin.IN)
#    N)     self.maxLimitPin = Pin(maxLimitPinNo,Pin.IN)

    def minLimit(self):
        return self.minLimitPin.value()

    def maxLimit(self):
        return True


#         return self.maxLimitPin.value()

if __name__ == '__main__':

    readOK = asyn.Event()

    async def hello():
        while (True):
            tim = time.time()
            print("Mike %d " % tim)
            await asyncio.sleep(1)

    async def bounce():
        while (True):
            print('bounce forward')
            asyncio.create_task(s1.move(1, 300))
            print('wait')
            await asyncio.sleep(10)
            print('bounce stop')
            s1.stop()
import uasyncio as asyncio
from config import *
from checkconnection import check_connection
from mqtt_helpers import *
from basesensor import BaseSensor
import builtins

# Board specific modules
from si7021sensor import SI7021sensor


builtins.MESSAGES = {}
builtins.debug = True
builtins.CONFIG = {}
builtins.loop = asyncio.get_event_loop()
builtins.event = asyn.Event()
list_of_instances = []


if init_config():
    load_config(CONFIG)
else:
    save_default_config()


class Sensor01(BaseSensor, SI7021sensor):
    publish_state_to_mqtt = True

    def __init__(self):
        super(Sensor01, self).__init__()
        print('Sensor class 01')
        uos.mount(sd, "/sd")
        break
    except:
        utime.sleep_ms(100)

# create file exception.txt if it does not yet exist
files = uos.listdir("/sd")
if not 'exception.txt' in files:
    f = open('/sd/exception.txt', mode='wt', encoding='utf-8')
    f.close()

# wrap the application in a global exception catcher
try:
    loop = asyncio.get_event_loop(ioq_len=2)
    lock = asyn.Lock()
    event_new_pm_data = asyn.Event(PM_POLLING_DELAY_MS)
    event_mqtt_publish = asyn.Event()
    
    spec_sensors = SpecSensors()
    temp_hum = THSensor()
    ps = ParticulateSensor(lock, event_new_pm_data)
    display = Display()
    
    if modes[operating_mode].aq == 'periodic':
        interval_timer = IntervalTimer(event_mqtt_publish)
    
    if modes[operating_mode].logging == 1:
        sdcard_logger = SDCardLogger()
        
    mic = Microphone()