Git Product home page Git Product logo

Comments (3)

martinlindjarv avatar martinlindjarv commented on August 13, 2024 2

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.

from mqttwarn.

martinlindjarv avatar martinlindjarv commented on August 13, 2024 1

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

from mqttwarn.

amotl avatar amotl commented on August 13, 2024

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.

from mqttwarn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.