Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First version of mqtt support. #357

Merged
merged 9 commits into from
Dec 31, 2018
Merged

First version of mqtt support. #357

merged 9 commits into from
Dec 31, 2018

Conversation

mbehr1
Copy link
Contributor

@mbehr1 mbehr1 commented Aug 4, 2018

See here for #308 the first commits for review and discussion.
Seems to work for me.

Topics generated are:
< prefix>/chn/id <- contains the channel identifier (e.g. Obis code)
< prefix>/chn/uuid <- contains the uuid from that channel
< prefix>/chn/[raw|agg] <- contains the last value. either raw or from configured agg mode.
prefix defaults to "vzlogger" and can be overwritten in mqtt object within vzlogger.conf.

For testing I used test.mosquitto.org. Simply update mqtt object inside vzlogger.cfg and e.g. use mosquitto_sub -h test.mosquitto.org -t "vzlogger/#" -v
and see the data arriving ;-)

Adds
- ENABLE_MQTT cmake option. Defaults to On but turns off automatically
  if libmosquitto not found.
- basic mqtt client support using libmosquitto
  - topics generated are:
    vzlogger/<channel-id>/uuid
    vzlogger/<channel-id>/raw
    vzlogger/<channel-id>/agg
- added config options for
  - host
  - port (currently no tls/sll support!)
  - user
  - password
  - topic (prefix used instead of vzlogger in above example)
  - (some more, see etc/vzlogger.conf)
- agg values get's preferred instead of raw. Using config option
  rawAndAgg this can be changed.
@mbehr1 mbehr1 mentioned this pull request Aug 4, 2018
This should be to get a better understanding of what the channel
actually is. E.g. will contains obis ids.
@mbehr1 mbehr1 requested a review from andig August 5, 2018 09:21
@andig
Copy link
Contributor

andig commented Aug 5, 2018

Hi Mathias,

Code ist jenseits meiner Fähigkeiten ;) Was ich nich gesehen habe: reconnect wenn mqtt stirbt und wieder kommt bzw. late connect falls mqtt meim Start von vzlogger nicht da? Namenskonvention der Topics?

Viele Grüße, Andreas

@mbehr1
Copy link
Contributor Author

mbehr1 commented Aug 5, 2018

@andig reconnect ist dabei:
int res = mosquitto_loop(mqttClient->_mcs, 1000, 1); if (res != MOSQ_ERR_SUCCESS) { print(log_warning, "mosquitto_loop returned %d. trying reconnect", "mqtt", res); sleep(1); res = mosquitto_reconnect(mqttClient->_mcs);
gleiches sollte auch den late connect abhandeln.
Aber wäre gut, wenn das von paar Leuten mit getestet werden kann. Habe bei log_finest relativ viele Log Ausgaben. Könnte schnell noch was einbauen.

@andig
Copy link
Contributor

andig commented Aug 5, 2018

Ich hab den Logger gar nicht mehr im Einsatz- Modbus Zähler...

@mbehr1
Copy link
Contributor Author

mbehr1 commented Aug 5, 2018

Hab reconnect Handling beim Startup hinzugefügt. Wenn "con refused" kommt, wird später wieder versucht.

@andig
Copy link
Contributor

andig commented Aug 5, 2018

Wie heissen die Topics?

@mbehr1
Copy link
Contributor Author

mbehr1 commented Aug 5, 2018

s.o.
< prefix>/chn/id <- contains the channel identifier (e.g. Obis code)
< prefix>/chn/uuid <- contains the uuid from that channel
< prefix>/chn/[raw|agg] <- contains the last value. either raw or from configured agg mode.
prefix defaults to "vzlogger" and can be overwritten in mqtt object within vzlogger.conf.
also. z.b.
"vzlogger/chn5/id"
"vzlogger/chn5/uuid"
"vzlogger/chn5/agg"

This should allow startups where the mqtt server will be available later
@mbehr1
Copy link
Contributor Author

mbehr1 commented Aug 5, 2018

I could add the meter name as well into the topic. e.g. vzlogger/mtr1/chn5/... but the channel ids would still be unique. (so e.g. mtr1/ch1, mtr1/ch2, mtr2/ch3,...)

@andig
Copy link
Contributor

andig commented Aug 6, 2018

"vzlogger/chn5/id"

Wo kommt denn das chn5 her- manuell zu konfigurieren? Oder beim Startup durchnummeriert?

"vzlogger/chn5/uuid"

Uuid optional? Im use case von @gitka würde es ja gar kein VZ api mehr geben.

Ich habe bei meinen Redesigngedankenspielen auch damit gekämpft wie die Hierarchie aus Meter/ Devices/ Meßwerten aussehen soll. Richtig glücklich hat mich am Ende nicht gemacht...

@mbehr1
Copy link
Contributor Author

mbehr1 commented Aug 6, 2018

Wo kommt denn das chn5 her- manuell zu konfigurieren? Oder beim Startup durchnummeriert?

ist der 5. Channel aus der Cfg. Ich nutze einfach Channel::name().
Für uuid nutze ich Channel::uuid(). Habe grad noch Commit hinzugefügt, der die nur nutzt, wenn nicht leer.

@tunip
Copy link

tunip commented Oct 18, 2018

Runs quite good so far.

@sir106
Copy link

sir106 commented Dec 23, 2018

when will this be merged into the master branch ? long awaited feature ;)

@mbehr1
Copy link
Contributor Author

mbehr1 commented Dec 31, 2018

@andig ok for you to be merged?

@andig
Copy link
Contributor

andig commented Dec 31, 2018

Yes of course! And prerequisite for #366

@mbehr1 mbehr1 merged commit 48cd577 into volkszaehler:master Dec 31, 2018
@r00t-
Copy link
Contributor

r00t- commented Nov 24, 2022

@mbehr1:
great that you supplied this code!
but can you comment on why you integrated it into the core in the way you did?
(i imagine there are some challenges in implementing it "properly", and it would be great if you could provide information on them to anybody looking to improve the integration.)
either here or in #550.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants