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
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.1.tar.gz
(128.9 kB
view hashes)
Built Distribution
newiotclient-1.0.1-py3-none-any.whl
(127.9 kB
view hashes)
Close
Hashes for newiotclient-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cac4b533c53d77d96bdacce22fe0fa6aa29894a67738ba6f81b36276a7ac9853 |
|
MD5 | fdaec00b80c6aee0cc95755842bc0565 |
|
BLAKE2b-256 | d93ca434728b07a6e3a1a2b774b249cfa55be1709ae54271a0ded08cdaca01df |