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

10.b Write MQTT-backed VeQItem for velib #190

Closed
chriadam opened this issue Sep 15, 2022 · 5 comments
Closed

10.b Write MQTT-backed VeQItem for velib #190

chriadam opened this issue Sep 15, 2022 · 5 comments

Comments

@chriadam
Copy link
Contributor

chriadam commented Sep 15, 2022

Prior required work: #189
Once we understand how DBus-backed VeQItem works, we can write MQTT-backend VeQItem, and put it into velib.

@chriadam
Copy link
Contributor Author

chriadam commented Sep 15, 2022

We want to be able to do the following in main.cpp:
  QScopedPointer<VeQItemMqttProducer> producer(new VeQItemMqttProducer(root=VeQItems::getRoot(), id="mqtt"));
  producer->open("ws://some.websocket.url:1884", ...);

So, I need to implement (in ve_qitems_mqtt.cpp/hpp):

::VeQItemMqttProducer(root, id)
-> mProducerRoot = createItem();
-> root->itemAddChild(id, mProducerRoot);
::open(url, connectionType -> websocket, tcp, ??)
-> internally, construct a MqttClientConnection, and connectToHost();
-> enumerate all topics which start with com.victronenergy
-> for each matching topic: mProducerRoot->itemGetOrCreate(topic)
   -> that is vanilla VeQItem which will split the topic into parts, and construct all intermediate items, via createChild() which calls producer->createItem()
::createItem()
-> return new VeQItemMqtt(this, mMqttClientConnection /* is this needed? */);


VeQItemMqtt(QObject *parent, mqttClientConnection)
-> (QPointer) mClientConnection(mqttClientConnection)
-> connect(mClientConnection->messageReceived) { get payload, determine if it's value/text/min/max/default -> update appropriately }
-> mClientConnection->subscribe(id())
-> and also error states etc I guess.

@chriadam
Copy link
Contributor Author

Since this is going into velib, I think we need to keep the license as permissive as possible, so I will use QMQTT instead of QtMqtt module, as QMQTT is Eclipse Public License rather than Qt Commercial or GPLv3.

According to emqx/qmqtt#191 it seems like WASM+WebSockets is supported in QMQTT already, so that's good.

@chriadam
Copy link
Contributor Author

https://github.com/victronenergy/velib/tree/chriadam-qmqtt-veqitemmqtt implements this.
It's still very very rough, but it works.

@chriadam
Copy link
Contributor Author

chriadam commented Oct 7, 2022

I've also implemented a QtMqtt version (instead of QMQTT as the first one was): https://github.com/victronenergy/velib/tree/chriadam-qtmqtt-veqitemmqtt

@chriadam
Copy link
Contributor Author

This is now in veutil repository: victronenergy/veutil#2
Marking as Done.

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

No branches or pull requests

1 participant