A library to synchronize MQTT topics with Python class attributes
Project description
syncmqtt
sync your data with mqtt
example usage:
from syncmqtt import qtt, attr, sub, conn
@qtt()
class SyncedMqtt:
# push_on_set will pub to topic when assign new value
# sync wil update value when new message from topic
# json means value are serialized before send and parsed after receive
test_a = attr(val='test_a', topic='/a', push_on_set=True, sync=True, retained=True)
test_b = attr(val=20, topic='/b', push_on_set=False, sync=True, json=True)
test_c = attr(val='test_c', topic='/c', push_on_set=True, sync=False, retained=False)
@sub(topic='/c', json=True) # make sure test_cb is called when topic='/c' got new message
def test_cb(self, val):
print(val)
self.test_a = val
async def main():
conn.connect(broker='mqtt://localhost:8000', live_topic='/test_status')
# init with last_will off => /test_status
# pub on => /test_status retained, let other know I'm online
# during conn.connect
sq = SyncedMqtt() # if use qttclass before conn.connect, raise error
sq.test_c = 'hello'
# pub hello => /c
# test_cb
# print hello
# set test_a
# pub hello => /a
conn.destory() # stop connection
# mqtt connect broken and off => /test_status base on last wil setting
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
syncmqtt-0.1.0.tar.gz
(4.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file syncmqtt-0.1.0.tar.gz.
File metadata
- Download URL: syncmqtt-0.1.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ae09be2ef317e04208b7d5587c228d9f3504f3c7368a097e883a44b1849b61c
|
|
| MD5 |
240a47ff166049d2aadf592e98212d38
|
|
| BLAKE2b-256 |
f6b605ba59cad7df88d1ba6226b1f01b2e7ccecf131ce94eaef66ce89f77890d
|
File details
Details for the file syncmqtt-0.1.0-py3-none-any.whl.
File metadata
- Download URL: syncmqtt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dedb372b8b368f280b6b0f11e5ecedc4cb2c2fb2f24d6d4f6396aff3274333f
|
|
| MD5 |
ac1c849376ae3d5f2e01fc47f0784416
|
|
| BLAKE2b-256 |
3511b81aae58e0370c8435faa13cb11b8ae711d98ed2c0828116b2fd40adb9c6
|