ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
It would depend on what you are getting from Mosquitto.
Please show some sample lines of output from mosquitto_sub as you have it configured and we can guess.
Also port 1883 implies that you are making decisions based on unencrypted messages. If this is for anything serious, you need to consider sending MQTT over TLS.
This is just monitoring my solar system. I via this script wish to inform my tenants of wether we are on the grid or using batteries due to grid being down.
I can extract the value from MQTT but get an error when using it in an if statement.
Thanks. $1 will be solar_assistant/inverter_1/ac_output_voltage/state and $2 will be 230.0 because white space is the default field separator (FS) in AWK.
You can narrow the subscription there substantially so that Mosquitto shows only the output from the relevant topic, such as solar_assistant/inverter_1/ac_output_voltage/state or any other item there. See "man mosquitto_sub" and scroll down to -t or see "man 7 mqtt"
If you are watching more than one inverter, then you can subscribe to the topics with a wildcard: solar_assistant/+/ac_output_voltage/state
Quote:
Originally Posted by stockton
This is just monitoring my solar system. I via this script wish to inform my tenants of wether we are on the grid or using batteries due to grid being down.
In that case, top priority ought to be deploying TLS first, before working on the rest. Otherwise, with unencrypted connections anything can happen, including spoofed messages.
Quote:
Originally Posted by stockton
I can extract the value from MQTT but get an error when using it in an if statement.
That's not what was happening. It's what you wanted but the [url=https://mywiki.wooledge.org/CommandSubstitution]command substitution[/font] was capturing something else.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.