Open martinlindjarv opened 5 months ago
Ok, it seems i have found a solution that suits my needs. Used url as base for info and made modifications.
samplefuncs.py:
def ecowitt_fields(data, srv=None):
"""Extract fields from JSON payload of messages on topic
ecowitt and publish the fields on separate
MQTT topics ecowitt/[Field]."""
if type(data) == dict and "winddir" in data and "windspeed" in data:
base_topic = "ecowitt"
republish_fields = ['winddir', 'windspeed']
if type(data) == dict and srv is not None:
for field, value in data.items():
if field in republish_fields:
srv.mqttc.publish("/".join([base_topic, field]), value, qos=0, retain=False)
return None
and into mqttwarn.ini i added:
[ecowitt]
targets=log:info
format=ecowitt_fields()
[ecowitt/+]
targets = influxdb:ecowitt
It all seems to work ... maybe there are some simplier solutions but this seems to finally serve the purpose for me.
Hi Martin,
excellent. Thanks for sharing your procedures.
So, effectively you are doing some JSON attribute filtering and MQTT topic rewriting in your custom code, right? I wonder if mqttwarn would offer a corresponding plugin out of the box, at least for the re-publishing part?
In any case, we are happy that you managed to find a solution using mqttwarn with custom code.
With kind regards, Andreas.
Good day,
What i wanted was simple - incoming json republished to mqtt as separate topics under one base. That filtering is there with case "it's possible" but not mandatory.
But as my solution seemed quite hacky i asked maybe it can be solved with existing code ...
But if not i will continue with my solution as it works :)
Regards, Martin
Good day!
First of all - thank you for great software!
For last few days i have been struggling with idea to get ecowitt weather station data to influxdb. I'm seem to be missing logic or understanding ...
When one value comes in and needs to go to influx it seems doable.
But once i have one json topic i have no idea how to do it :(
Received json is quite simple:
Now i would like to get winddir and windspeed and insert them directly to influx ... but have no idea how to do it ... With python func i have found it is possible to extract and formutale the message again ... but i have not found any example how to solve "one topic, multiple values to different places" - is it even possible?
Any hints or directions are welcome.