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


Python machine.unique_id方法代码示例

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


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

示例1: send_to_thingspeak

# 需要导入模块: import machine [as 别名]
# 或者: from machine import unique_id [as 别名]
def send_to_thingspeak(datapoints):
    mean_data = DataPoint.mean(datapoints)

    thingspeak_data = mean_data.to_thingspeak()
    print('sending data\n{}'.format(thingspeak_data))

    success = False
    number_of_retries = 3

    while not success and number_of_retries > 0:
        try:
            client_id = binascii.hexlify(machine.unique_id())
            client = MQTTClient(client_id, 'mqtt.thingspeak.com', user='wipy#1', password=MQTT_API_KEY, port=8883, ssl=True)
            client.connect()
            client.publish(topic='channels/379710/publish/{}'.format(MQTT_WRITE_API_KEY), msg=thingspeak_data)
            client.disconnect()
            success = True
        except OSError as e:
            print('network error: {}'.format(e.errno))
            number_of_retries -= 1
            pass

    return success 
开发者ID:ayoy,项目名称:upython-aq-monitor,代码行数:25,代码来源:thingspeak.py

示例2: get_eui

# 需要导入模块: import machine [as 别名]
# 或者: from machine import unique_id [as 别名]
def get_eui():
    id = ubinascii.hexlify(unique_id()).decode()
    return mac2eui(id) 
开发者ID:Wei1234c,项目名称:SX127x_driver_for_MicroPython_on_ESP8266,代码行数:5,代码来源:oled_test.py

示例3: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import unique_id [as 别名]
def __init__(self, channel, config):
        self.channel = channel
        self.subscriptions = {}
        # Config defaults:
        # 4 repubs, delay of 10 secs between (response_time).
        # Initially clean session.
        config['subs_cb'] = self.subs_cb
        config['wifi_coro'] = self.wifi_han
        config['connect_coro'] = self.conn_han
        config['client_id'] = ubinascii.hexlify(unique_id())
        super().__init__(config)

    # Get NTP time or 0 on any error. 
开发者ID:peterhinch,项目名称:micropython-mqtt,代码行数:15,代码来源:mqtt.py

示例4: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import unique_id [as 别名]
def __init__(
        self,
        listener,
        poller,
        port,
        root_url,
        server_version,
        persistent_uuid,
        other_headers=None,
        ip_address=None,
    ):
        self.listener = listener
        self.poller = poller
        self.port = port
        self.root_url = root_url
        self.server_version = server_version
        self.persistent_uuid = persistent_uuid
        self.uuid = machine.unique_id()
        self.other_headers = other_headers

        if ip_address:
            self.ip_address = ip_address
        else:
            self.ip_address = upnp_device.local_ip_address()

        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.bind((self.ip_address, self.port))
        self.socket.listen(5)
        if self.port == 0:
            self.port = self.socket.getsockname()[1]
        self.poller.add(self)
        self.client_sockets = {}
        self.listener.add_device(self) 
开发者ID:lemariva,项目名称:uPyEcho,代码行数:35,代码来源:main.py

示例5: unique_id

# 需要导入模块: import machine [as 别名]
# 或者: from machine import unique_id [as 别名]
def unique_id(self, **kwargs) -> str:
        """
        Get the unique ID of the device.
        t will vary from a board/SoC instance to another, if underlying hardware allows. Length varies by hardware
        (so use substring of a full value if you expect a short ID). In some MicroPython ports, ID corresponds to
        the network MAC address..

        :param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.execute`.
        """
        code = '''
import machine
print(':'.join(['{:02x}'.format(b) for b in machine.unique_id()]))
'''

        return self.execute(code, **kwargs).output 
开发者ID:BlackLight,项目名称:platypush,代码行数:17,代码来源:__init__.py

示例6: get_machine_stats

# 需要导入模块: import machine [as 别名]
# 或者: from machine import unique_id [as 别名]
def get_machine_stats(self):
        import machine
        import ubinascii
        id = "0x{}".format(ubinascii.hexlify(machine.unique_id()).decode().upper())
        return {
            'freq': machine.freq(),
            'unique_id': id
        } 
开发者ID:fadushin,项目名称:esp8266,代码行数:10,代码来源:stats_api.py

示例7: get_sys_stats

# 需要导入模块: import machine [as 别名]
# 或者: from machine import unique_id [as 别名]
def get_sys_stats(self):
        return {
            'machine_id': "0x{}".format(ubinascii.hexlify(machine.unique_id()).decode().upper()),
            'machine_freq': machine.freq(),
            'byteorder': sys.byteorder,
            'system': "{}-{}".format(
                sys.implementation[0],
                self.to_version_string(sys.implementation[1]),
            ),
            'maxsize': sys.maxsize,
            'modules': self.keys(sys.modules),
            'path': sys.path,
            'platform': sys.platform,
            'version': sys.version,
        } 
开发者ID:fadushin,项目名称:esp8266,代码行数:17,代码来源:api.py

示例8: getDeviceID

# 需要导入模块: import machine [as 别名]
# 或者: from machine import unique_id [as 别名]
def getDeviceID():
    if platform == "linux":
        from pysmartnode import config
        return config.DEVICE_NAME
    import machine
    return ubinascii.hexlify(machine.unique_id()).decode() 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:8,代码来源:sys_vars.py

示例9: get_nodename

# 需要导入模块: import machine [as 别名]
# 或者: from machine import unique_id [as 别名]
def get_nodename():
    uuid = ubinascii.hexlify(machine.unique_id()).decode()
    node_name = "ESP_" + uuid
    return node_name 
开发者ID:lemariva,项目名称:uPyLoRaWAN,代码行数:6,代码来源:config_lora.py

示例10: get_unique_id

# 需要导入模块: import machine [as 别名]
# 或者: from machine import unique_id [as 别名]
def get_unique_id():
    if LINUX is False:
        return hexlify(unique_id()).decode()
    else:
        raise NotImplementedError(
            "Linux doesn't have a unique id. Provide the DEVICE_ID option in your settings.py."
        ) 
开发者ID:microhomie,项目名称:microhomie,代码行数:9,代码来源:utils.py

示例11: unique_id

# 需要导入模块: import machine [as 别名]
# 或者: from machine import unique_id [as 别名]
def unique_id():
        raise NotImplementedError("Linux doesn't have a unique id. Provide the argument client_id")


# Default "do little" coro for optional user replacement 
开发者ID:microhomie,项目名称:microhomie,代码行数:7,代码来源:mqtt_as.py

示例12: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import unique_id [as 别名]
def __init__(self, client_id=None,
                 server=None,
                 port=0,
                 user='',
                 password='',
                 keepalive=60,
                 ping_interval=0,
                 ssl=False,
                 ssl_params={},
                 response_time=10,
                 clean_init=True,
                 clean=True,
                 max_repubs=4,
                 will=None,
                 subs_cb=lambda *_: None,
                 wifi_coro=None,
                 connect_coro=None,
                 ssid=None,
                 wifi_pw=None):
        client_id = client_id or hexlify(unique_id())
        wifi_coro = wifi_coro or eliza
        connect_coro = connect_coro or eliza
        super().__init__(client_id, server, port, user, password, keepalive, ping_interval,
                         ssl, ssl_params, response_time, clean_init, clean, max_repubs, will,
                         subs_cb, wifi_coro, connect_coro, ssid, wifi_pw)
        self._isconnected = False  # Current connection state
        keepalive = 1000 * self._keepalive  # ms
        self._ping_interval = keepalive // 4 if keepalive else 20000
        p_i = self.ping_interval * 1000  # Can specify shorter e.g. for subscribe-only
        if p_i and p_i < self._ping_interval:
            self._ping_interval = p_i
        self._in_connect = False
        self._has_connected = False  # Define 'Clean Session' value to use.
        if ESP8266:
            import esp
            esp.sleep_type(0)  # Improve connection integrity at cost of power consumption. 
开发者ID:microhomie,项目名称:microhomie,代码行数:38,代码来源:mqtt_as.py

示例13: monkeypatch_machine

# 需要导入模块: import machine [as 别名]
# 或者: from machine import unique_id [as 别名]
def monkeypatch_machine():

    from mock import Mock

    import uuid
    import machine

    # Some primitives.
    machine.enable_irq = Mock()
    machine.disable_irq = Mock()
    machine.unique_id = lambda: str(uuid.uuid4().fields[-1])[:5].encode()
    machine.freq = Mock(return_value=42000000)
    machine.idle = Mock()

    # Reset cause and wake reason.
    machine.PWRON_RESET = 0
    machine.HARD_RESET = 1
    machine.WDT_RESET = 2
    machine.DEEPSLEEP_RESET = 3
    machine.SOFT_RESET = 4
    machine.BROWN_OUT_RESET = 5

    machine.PWRON_WAKE = 0
    machine.GPIO_WAKE = 1
    machine.RTC_WAKE = 2
    machine.ULP_WAKE = 3

    machine.reset_cause = Mock(return_value=0)
    machine.wake_reason = wake_reason 
开发者ID:hiveeyes,项目名称:terkin-datalogger,代码行数:31,代码来源:compat.py

示例14: get_device_id

# 需要导入模块: import machine [as 别名]
# 或者: from machine import unique_id [as 别名]
def get_device_id():
    """ 
    MAC address of device if supported.
    """
    import machine
    from ubinascii import hexlify
    return hexlify(machine.unique_id()).decode() 
开发者ID:hiveeyes,项目名称:terkin-datalogger,代码行数:9,代码来源:util.py

示例15: get_device_id

# 需要导入模块: import machine [as 别名]
# 或者: from machine import unique_id [as 别名]
def get_device_id():
    """ """
    import machine
    from ubinascii import hexlify
    return hexlify(machine.unique_id()).decode() 
开发者ID:hiveeyes,项目名称:terkin-datalogger,代码行数:7,代码来源:pycom.py


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