python client for iot.lonelyassistant.com
Project description
newiotclient
Description
MQTT client for iot.lonelyassistant.com, authentication using JWT
Usage
import time
from newiotclient.core import MqttJwtToken, JwtTokenThread, JwtMqttClient
def on_message(m_client, userdata, msg):
print('++++++ do something ++++++')
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))} {msg.payload.decode()}')
def run():
# Get these options from iot.lonelyassistant.com
parameters = {
'host': '0.0.0.0',
'port': 1883,
'tls': False,
# 'client_id': 'xxx-xxxx',
'product_key': 'LASS-xxxxxxxxxxxxxxxxxxx',
'device_sn': 'xxxxxxxxxxxx',
'register_username': 'register-xxxxxxxx',
'register_password': 'register-xxxxxxxx',
'refresh_jwt_username': 'jwt-refresh-xxxxxxxx',
'refresh_jwt_password': 'jwt-refresh-xxxxxxxx'
}
topic = 'xxxxxxxx/device/dt/001/LASS-xxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxx'
mqtt_jwt_token = MqttJwtToken(**parameters)
jwt_thread = JwtTokenThread(mqtt_jwt_token)
jwt_thread.setDaemon(True)
jwt_thread.start()
jwt_thread.join()
jwt_client = JwtMqttClient(loop_forever=False, on_message=on_message)
jwt_client.sub(topic)
try:
while True:
jwt_client.pub(topic, 'hello')
time.sleep(5)
except KeyboardInterrupt:
jwt_client.end()
if __name__ == '__main__':
run()
Issues
Project details
Release history Release notifications | RSS feed
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.0.tar.gz
(128.4 kB
view hashes)
Built Distribution
newiotclient-1.0.0-py3-none-any.whl
(127.4 kB
view hashes)
Close
Hashes for newiotclient-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8aebe3ce1e4454b61a88e782f8278ec4c296c15ee4632242ad38493aa56f6cb2 |
|
MD5 | bc1e03afc1c1b64444488a1a914cce66 |
|
BLAKE2b-256 | 4104742e1ed51ec2b09dad8c2795995fe838eff0a72e1652d089238b1fd5e31d |