Skip to main content

python client for iot.lonelyassistant.com

Project description

newiotclient

Description

MQTT client for iot.lonelyassistant.com, authentication using JWT

Usage

Config

[broker]
host = 0.0.0.0
port = 1883
tls  = False
;client_id: xxx-xxxx

[device]
product_key = LASS-xxxxxxxx
device_sn = xxxxxx
register_username = register-xxxxx
register_password = register-xxxxx
refresh_jwt_username = jwt-refresh-xxxxx
refresh_jwt_password = jwt-refresh-xxxxx

Subscribe Topic

import time
from newiotclient.core import MqttJwtToken, JwtMqttClientSub

topic = 'xxxxxx/device/dt/001/LASS-xxxxxx/xxxxxx'


def on_message(m_client, userdata, msg):
    print('++++++ get message ++++++')
    print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))} {msg.payload.decode()}')
    print('++++++ do something here +++++++')


def run():

    def token_success(token):
        print('============================= get token =================================')
        sub = JwtMqttClientSub(topic=topic, on_message=on_message)
        sub.start()
        sub.join()

    mqtt_jwt_token = MqttJwtToken(config_ini='./dev.ini')
    mqtt_jwt_token.on_success = token_success
    mqtt_jwt_token.retrieving()


if __name__ == '__main__':
    run()

Publish Topic

import time
from newiotclient.core import MqttJwtToken, JwtMqttClientPub

topic = 'xxxxxx/device/dt/001/LASS-xxxxxx/xxxxxx'


def token_success(token):
    print('============================= get token =================================')
    while True:
        payload = 'hello'
        sub = JwtMqttClientPub(topic=topic, payload=payload)
        sub.start()
        sub.end()
        sub.join()

        time.sleep(5)


def run():
    mqtt_jwt_token = MqttJwtToken(config_ini='./dev.ini')
    mqtt_jwt_token.on_success = token_success
    mqtt_jwt_token.retrieving()


if __name__ == '__main__':
    run()

Issues

https://github.com/laonan/newiot-pyclient/issues

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

newiotclient-1.0.2.tar.gz (128.8 kB view details)

Uploaded Source

Built Distribution

newiotclient-1.0.2-py3-none-any.whl (127.8 kB view details)

Uploaded Python 3

File details

Details for the file newiotclient-1.0.2.tar.gz.

File metadata

  • Download URL: newiotclient-1.0.2.tar.gz
  • Upload date:
  • Size: 128.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.10

File hashes

Hashes for newiotclient-1.0.2.tar.gz
Algorithm Hash digest
SHA256 981b59c818d76ebe47f2b15b63e89fefe6e002043b0752a913d0542fc874a14e
MD5 54aac1dd1be1f2e6f66cb3ae024f3af0
BLAKE2b-256 8aed4b1ae0e52230c99cb95b09519a71bd62c61209260eafbb762a7d67a379e5

See more details on using hashes here.

File details

Details for the file newiotclient-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: newiotclient-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 127.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.10

File hashes

Hashes for newiotclient-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 07f4127b4676b132222b1d0a1d2c930a1df10561602b86b4c34496ae97cb44f7
MD5 0f41d5941bef6f596edbf9e878892e8c
BLAKE2b-256 3fc9035c5d7590c00961044071773c3f5bad11812d9fd44fa487e365d274ab4b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page