mirror of
https://github.com/OMGeeky/flucto-heisskleber.git
synced 2025-12-28 23:36:17 +01:00
* WIP: Added async file reader. * Async resampling and synchronization refactored. * Add async mqtt publisher. Remove queue from joint. * Add async zmq publisher and subscriber. * Modify integration tests for streaming. * Name refactoring resampler. * Added async source/sink to factory. * Refactor joint and add integration tests. * Add termcolor dev dependency * Add conosole source and sink * Add cli interface for different protocols * Removed files unfit for merge. * Fix review requests. * Restore use of $MSB_CONFIG_DIR for now. It seems that the default behaviour is not looking for .config/heisskleber * Remove version test, causing unnecessary failures.
36 lines
999 B
Python
36 lines
999 B
Python
import asyncio
|
|
import time
|
|
|
|
from termcolor import colored
|
|
|
|
from heisskleber.mqtt import AsyncMqttPublisher, MqttConf
|
|
|
|
colortable = ["red", "green", "yellow", "blue", "magenta", "cyan"]
|
|
|
|
|
|
async def send_every_n_miliseconds(frequency, value, pub, topic):
|
|
start = time.time()
|
|
while True:
|
|
epoch = time.time() - start
|
|
payload = {"epoch": epoch, f"value{value}": value}
|
|
print_message = f"Pub #{int(value)} sending {payload}"
|
|
print(colored(print_message, colortable[int(value)]))
|
|
await pub.send(payload, topic)
|
|
await asyncio.sleep(frequency)
|
|
|
|
|
|
async def main2():
|
|
config = MqttConf(broker="localhost", port=1883, user="", password="")
|
|
|
|
pubs = [AsyncMqttPublisher(config) for i in range(5)]
|
|
tasks = []
|
|
for i, pub in enumerate(pubs):
|
|
tasks.append(asyncio.create_task(send_every_n_miliseconds(1 + i * 0.1, i, pub, f"topic{i}")))
|
|
|
|
await asyncio.gather(*tasks)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# main()
|
|
asyncio.run(main2())
|