当前位置: 首页>>代码示例>>Python>>正文


Python utime.time方法代码示例

本文整理汇总了Python中utime.time方法的典型用法代码示例。如果您正苦于以下问题:Python utime.time方法的具体用法?Python utime.time怎么用?Python utime.time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utime的用法示例。


在下文中一共展示了utime.time方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: do_connect

# 需要导入模块: import utime [as 别名]
# 或者: from utime import time [as 别名]
def do_connect():
    sta_if = network.WLAN(network.STA_IF)
    start = utime.time()
    timed_out = False

    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        sta_if.connect(config.wifi_config["ssid"], config.wifi_config["password"])
        while not sta_if.isconnected() and \
            not timed_out:        
            if utime.time() - start >= 20:
                timed_out = True
            else:
                pass

    if sta_if.isconnected():
        ntptime.settime()
        print('network config:', sta_if.ifconfig())
    else: 
        print('internet not available') 
开发者ID:lemariva,项目名称:uPyCam,代码行数:23,代码来源:boot.py

示例2: status_handler

# 需要导入模块: import utime [as 别名]
# 或者: from utime import time [as 别名]
def status_handler(mqtt_link, status):
    global out_time
    res = await default_status_handler(mqtt_link, status)
    if res is not None:  # Handle failure on initialisation
        # res == 1 occurs on 1st run only. Tells driver to try the network
        # specified in net_local.
        # res == 0 indicates failure to connect. The default handler waits 30 secs
        # before returning 0 to give time for the network to come up.
        # If we return 0 the ESP8266 will be rebooted
        return res
    # WiFi handling for demo: easier to use wifi_handler (see pb_simple.py)
    if status == WIFI_UP:
        amber.on()
        delta = time() - out_time
        mqtt_link.publish('result', 'WiFi up: out time = {}s'.format(delta), 0, qos)
        return
    if status == WIFI_DOWN:
        out_time = time()
        amber.off()
        return
    if status == PUBOK:
        return
    status_vals.append(status)  # We will publish non-routine values 
开发者ID:peterhinch,项目名称:micropython-mqtt,代码行数:25,代码来源:pb_status.py

示例3: _do_rtc

# 需要导入模块: import utime [as 别名]
# 或者: from utime import time [as 别名]
def _do_rtc(self):
        lnk = self._lnk
        lnk.vbprint('Start RTC synchroniser')
        self._time_valid = not self._rtc_last_syn == 0  # Valid on restart
        while True:
            while not self._time_valid:
                lnk.channel.send(TIME)
                # Give 5s time for response
                await asyn.sleep(5)
                if not self._time_valid:
                    # WiFi may be down. Delay 1 min before retry.
                    await asyn.sleep(60)
            else:  # Valid time received or restart
                if self._rtc_interval < 0:
                    break  # One resync only: done
                tend = self._rtc_last_syn + self._rtc_interval
                twait = max(tend - time(), 5)  # Prolonged outage
                await asyn.sleep(twait)
                self._time_valid = False 
开发者ID:peterhinch,项目名称:micropython-mqtt,代码行数:21,代码来源:pbmqtt.py

示例4: get_time

# 需要导入模块: import utime [as 别名]
# 或者: from utime import time [as 别名]
def get_time(self, set_rtc = False):
        if set_rtc:
            data = self.await_transition()      # For accuracy set RTC immediately after a seconds transition
        else:
            self.ds3231.readfrom_mem_into(DS3231_I2C_ADDR, 0, self.timebuf)
            data = self.timebuf
        ss = bcd2dec(data[0])
        mm = bcd2dec(data[1])
        if data[2] & 0x40:
            hh = bcd2dec(data[2] & 0x1f)
            if data[2] & 0x20:
                hh += 12
        else:
            hh = bcd2dec(data[2])
        wday = data[3]
        DD = bcd2dec(data[4])
        MM = bcd2dec(data[5] & 0x1f)
        YY = bcd2dec(data[6])
        if data[5] & 0x80:
            YY += 2000
        else:
            YY += 1900
        if set_rtc:
            rtc.init((YY, MM, DD, hh, mm, ss, 0))
        return (YY, MM, DD, hh, mm, ss, 0, 0) # Time from DS3231 in time.time() format (less yday) 
开发者ID:ayoy,项目名称:upython-aq-monitor,代码行数:27,代码来源:ds3231.py

示例5: create_jwt

# 需要导入模块: import utime [as 别名]
# 或者: from utime import time [as 别名]
def create_jwt(project_id, private_key, algorithm, token_ttl):
    print("Creating JWT...")
    private_key = rsa.PrivateKey(*private_key)

    # Epoch_offset is needed because micropython epoch is 2000-1-1 and unix is 1970-1-1. Adding 946684800 (30 years)
    epoch_offset = 946684800
    claims = {
            # The time that the token was issued at
            'iat': utime.time() + epoch_offset,
            # The time the token expires.
            'exp': utime.time() + epoch_offset + token_ttl,
            # The audience field should always be set to the GCP project id.
            'aud': project_id
    }

    #This only supports RS256 at this time.
    header = { "alg": algorithm, "typ": "JWT" }
    content = b42_urlsafe_encode(ujson.dumps(header).encode('utf-8'))
    content = content + '.' + b42_urlsafe_encode(ujson.dumps(claims).encode('utf-8'))
    signature = b42_urlsafe_encode(rsa.sign(content,private_key,'SHA-256'))
    return content+ '.' + signature #signed JWT 
开发者ID:GoogleCloudPlatform,项目名称:iot-core-micropython,代码行数:23,代码来源:main.py

示例6: temp_update

# 需要导入模块: import utime [as 别名]
# 或者: from utime import time [as 别名]
def temp_update(self):
        tick = utime.time()
        buffer = ustruct.pack(
            "<HB",
            tick,
            (270 + urandom.randint(0, 32767)))
        result = self.aci_gatt_update_char_value(
            serv_handle=self.hw_serv_handle,
            char_handle=self.temperature_bluest_char_handle,
            char_val_offset=0,
            char_value_len=len(buffer),
            char_value=buffer).response_struct
        if result.status != status.BLE_STATUS_SUCCESS:
            raise ValueError("aci_gatt_update_char_value status: {:02x}".format(
                result.status))
        log.debug("aci_gatt_update_char_value %02x", result.status) 
开发者ID:dmazzella,项目名称:uble,代码行数:18,代码来源:bluest_protocol.py

示例7: pwr_update

# 需要导入模块: import utime [as 别名]
# 或者: from utime import time [as 别名]
def pwr_update(self):
        tick = utime.time()
        chg = urandom.randint(0, 100)
        voltage = urandom.randint(0, 100)
        current = urandom.randint(0, 100)
        npwrstat = urandom.randint(0, 100)
        buffer = ustruct.pack(
            "<HHHHB",
            tick,
            chg, voltage, current, npwrstat)
        result = self.aci_gatt_update_char_value(
            serv_handle=self.hw_serv_handle,
            char_handle=self.pwr_bluest_char_handle,
            char_val_offset=0,
            char_value_len=len(buffer),
            char_value=buffer).response_struct
        if result.status != status.BLE_STATUS_SUCCESS:
            raise ValueError("aci_gatt_update_char_value status: {:02x}".format(
                result.status))
        log.debug("aci_gatt_update_char_value %02x", result.status) 
开发者ID:dmazzella,项目名称:uble,代码行数:22,代码来源:bluest_protocol.py

示例8: press_update

# 需要导入模块: import utime [as 别名]
# 或者: from utime import time [as 别名]
def press_update(self):
        tick = utime.time()
        buffer = ustruct.pack(
            "<HI",
            tick,
            100000 + urandom.randint(0, 32767))
        result = self.aci_gatt_update_char_value(
            serv_handle=self.hw_serv_handle,
            char_handle=self.pressure_bluest_char_handle,
            char_val_offset=0,
            char_value_len=len(buffer),
            char_value=buffer).response_struct
        if result.status != status.BLE_STATUS_SUCCESS:
            raise ValueError("aci_gatt_update_char_value status: {:02x}".format(
                result.status))
        log.debug("aci_gatt_update_char_value %02x", result.status) 
开发者ID:dmazzella,项目名称:uble,代码行数:18,代码来源:bluest_protocol.py

示例9: _PMdata

# 需要导入模块: import utime [as 别名]
# 或者: from utime import time [as 别名]
def _PMdata(self):
        d = {}
        check = False
        # check data
        control_sum = 0x42 + 0x4d
        for b in range(len(self._data)-2):
            control_sum += self._data[b]

        control_sum_data = self._data[28] * 256 + self._data[29]
        print()
        if control_sum == control_sum_data:
            check = True

        d['time'] = utime.time() + epoch_offset
        d['cpm10'] = self._data[4] * 256 + self._data[5]
        d['cpm25'] = self._data[6] * 256 + self._data[7]
        d['cpm100'] = self._data[8] * 256 + self._data[9]
        d['apm10'] = self._data[10] * 256 + self._data[11]
        d['apm25'] = self._data[12] * 256 + self._data[13]
        d['apm100'] = self._data[14] * 256 + self._data[15]

        return [check, d] 
开发者ID:lemariva,项目名称:uPySensors,代码行数:24,代码来源:pmsa003.py

示例10: connect

# 需要导入模块: import utime [as 别名]
# 或者: from utime import time [as 别名]
def connect(self, timeout=_CONNECT_TIMEOUT):
        end_time = time.time() + timeout
        while not self.connected():
            if self._state == self.DISCONNECTED:
                try:
                    self._get_socket()
                    self._authenticate()
                    self._set_heartbeat()
                    self._last_rcv_time = ticks_ms()
                    self.log('Registered events: {}\n'.format(list(self._events.keys())))
                    self.call_handler(self._CONNECT)
                    return True
                except BlynkError as b_err:
                    self.disconnect(b_err)
                    sleep_ms(self.TASK_PERIOD_RES)
                except RedirectError as r_err:
                    self.disconnect()
                    self.server = r_err.server
                    self.port = r_err.port
                    sleep_ms(self.TASK_PERIOD_RES)
            if time.time() >= end_time:
                return False 
开发者ID:blynkkk,项目名称:lib-python,代码行数:24,代码来源:blynklib_mp.py

示例11: start

# 需要导入模块: import utime [as 别名]
# 或者: from utime import time [as 别名]
def start(mqtt_link):
    global reset_count
    mqtt_link.subscribe('green', qos, cbgreen)    # LED control qos 1
    loop = asyncio.get_event_loop()
    loop.create_task(asyn.Cancellable(publish, mqtt_link, 10)()) # Publish a count every 10 seconds
    loop.create_task(pulse(blue))  # Flash blue LED each time we restart ESP8266
    reset_count += 1 
开发者ID:peterhinch,项目名称:micropython-mqtt,代码行数:9,代码来源:pb_status.py

示例12: cbnet

# 需要导入模块: import utime [as 别名]
# 或者: from utime import time [as 别名]
def cbnet(state, objlink):
    global out_time
    if state:
        amber.on()
        delta = time() - out_time
        objlink.publish('result', 'WiFi up: out time = {}s'.format(delta), 0, qos)
    else:
        amber.off()
        out_time = time() 
开发者ID:peterhinch,项目名称:micropython-mqtt,代码行数:11,代码来源:pbrange.py

示例13: start

# 需要导入模块: import utime [as 别名]
# 或者: from utime import time [as 别名]
def start(mqtt_link):
    global reset_count
    mqtt_link.subscribe('green', qos, cbgreen)    # LED control qos 1
    mqtt_link.wifi_handler(cbnet, mqtt_link)  # Detect WiFi changes
    loop = asyncio.get_event_loop()
    loop.create_task(asyn.Cancellable(publish, mqtt_link, 10)()) # Publish a count every 10 seconds
    loop.create_task(pulse(blue))  # Flash blue LED each time we restart ESP8266
    reset_count += 1 
开发者ID:peterhinch,项目名称:micropython-mqtt,代码行数:10,代码来源:pbrange.py

示例14: _publish

# 需要导入模块: import utime [as 别名]
# 或者: from utime import time [as 别名]
def _publish(self):
        while True:
            if len(self.pubs): 
                args = self.pubs.pop(0)
                secs = 0
                # pub free can be a long time coming if WiFi is down
                while not self._pub_free:
                    # If pubs are queued, wait 1 sec to respect ESP8266 buffers
                    await asyncio.sleep(1)
                    if self._wifi_up:
                        secs += 1
                    if secs > 60:
                        self.quit('No response from ESP8266')
                        break
                else:
                    self.channel.send(argformat(PUBLISH, *args))
                    # All pubs send PUBOK.
                    # No more pubs allowed until PUBOK received.
                    self.pub_free(False)
            else:
                await asyncio.sleep_ms(20)

# start() is run each time the channel acquires sync i.e. on startup and also
# after an ESP8266 crash and reset.
# Behaviour after fatal error with ESP8266:
# It sets _running False to cause local tasks to terminate, then returns.
# A return causes the local channel instance to wait on the exit_gate to cause
# tasks in this program terminate, then issues a hardware reset to the ESP8266.
# (See SynCom.start() method). After acquiring sync, start() gets rescheduled. 
开发者ID:peterhinch,项目名称:micropython-mqtt,代码行数:31,代码来源:pbmqtt.py

示例15: _observe

# 需要导入模块: import utime [as 别名]
# 或者: from utime import time [as 别名]
def _observe(self):
        try:
            v = self.sensor.sample()
            self._dispatch_next((self.sensor.sensor_id, utime.time(), v),)
        except FatalError:
            raise
        except StopIteration:
            self._dispatch_completed()
        except Exception as e:
            self._dispatch_error(e) 
开发者ID:mpi-sws-rse,项目名称:thingflow-python,代码行数:12,代码来源:thingflow.py


注:本文中的utime.time方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。