mirror of
https://github.com/OMGeeky/flucto-heisskleber.git
synced 2026-01-10 13:40:20 +01:00
* Add start, stop and __repr__ to sink and source types. * Merge conflicts on mqtt async pub and resampler. * Add start() and stop() functions to udp and zmq. Change tests accordingly. * Rename broker, ip, interface to common config name "host". * Updated "host" entry in config files. * Add lazyload to mqtt-source.
44 lines
1.1 KiB
Python
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(host="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")
|