Files
flucto-heisskleber/tests/integration/async_streamer.py
Felix Weiler 78ba98a587 Feature/async sources (#46)
* 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.
2024-01-22 11:23:00 +01:00

44 lines
1.1 KiB
Python

import asyncio
import numpy as np
from heisskleber.mqtt import AsyncMqttSubscriber, MqttConf
from heisskleber.stream.resampler import Resampler, ResamplerConf
async def main():
topic1 = "topic1"
topic2 = "topic2"
config = MqttConf(broker="localhost", port=1883, user="", password="") # not a real password
sub1 = AsyncMqttSubscriber(config, topic1)
sub2 = AsyncMqttSubscriber(config, topic2)
resampler_config = ResamplerConf(resample_rate=250)
resampler1 = Resampler(resampler_config, sub1)
resampler2 = Resampler(resampler_config, sub2)
while True:
m1, m2 = await asyncio.gather(resampler1.receive(), resampler2.receive())
print(f"epoch: {m1['epoch']}")
print(f"diff: {diff(m1, m2)}")
def diff(dict1, dict2):
return dict(
zip(
dict1.keys(),
np.array(list(dict1.values())) - np.array(list(dict2.values())),
)
)
# Run the event loop
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("Keyboard Interrupt")