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

Proposal to optionally run HomieNode::loop() also in disconnected state #490

Merged
merged 23 commits into from
Mar 10, 2019

Conversation

euphi
Copy link
Member

@euphi euphi commented Feb 13, 2018

See #354, #487

euphi and others added 19 commits September 28, 2016 00:32
- $broadcast is handled and globalInputHandler is called
- still many TODOs, e.g. support for other callbacks or splitted MQTT
message (make use of payload buffer)
+ minor improvements
+ added comments to BootNormal.cpp to explain handling of incoming MQTT
message
* 📝 Add Gitter badge

* 📝 Add link to the Gitter in the ISSUE_TEMPLATE

* 🐛 Fix loopFunction being called too early before MQTT connection is established - closes homieiot#260 (homieiot#290)

* 👕 Fix lint

* ✨ Add destructor to HomieNode, that will abort() (homieiot#286)

* Added destructor to HomieNode, that will abort()

* 🎨 Log wifi client IP address upon connection. (homieiot#280)

This removes the need to hunt the device IP when debugging connectivity issues.

* 📝 Mention troubleshooting page in issue template

* 👕 Fix cpplint failure, causing travis CI to be red (homieiot#291)

E.g. https://travis-ci.org/marvinroger/homie-esp8266/jobs/199213998

Ran the following command successfully:
  cpplint --repository=. --recursive \
  --filter=-whitespace/line_length,-legal/copyright,-runtime/printf,-build/include,-build/namespace,-runtime/int \
  ./src

* 🔥 Remove MQTT ack logging

* 🐎 Make tiny optimizations

* 🎨 Add a comma to the wifi connected log

* 🎨 Reorganize next boot mode feature

* 🐎 Check length on input fields (homieiot#292)

* Fixing loopFunction being called too early before MQTT connection is established

* Started cleanup of strcpy/sprintf to include length check.

* Fixed warning under Interface.cpp

* 👕 Fix lint

* 🎨 Print firmware name and version at boot

* 🐛 Fix DeviceId incomplete MAC address (homieiot#296)

snprintf works with n-1 characters

expected behaviour: DeviceId is 12 characters
behaviour: only 11 characters are returned

(resulting in a "incomplete" mac address)

* :bug Fix millis() overflow in uptime - fix homieiot#299 (homieiot#302)

Corrected type declaration for correct overflow handling of millis
function in uptime calculation
* 📝 Add Gitter badge

* 📝 Add link to the Gitter in the ISSUE_TEMPLATE

* 🐛 Fix loopFunction being called too early before MQTT connection is established - closes homieiot#260 (homieiot#290)

* 👕 Fix lint

* ✨ Add destructor to HomieNode, that will abort() (homieiot#286)

* Added destructor to HomieNode, that will abort()

* 🎨 Log wifi client IP address upon connection. (homieiot#280)

This removes the need to hunt the device IP when debugging connectivity issues.

* 📝 Mention troubleshooting page in issue template

* 👕 Fix cpplint failure, causing travis CI to be red (homieiot#291)

E.g. https://travis-ci.org/marvinroger/homie-esp8266/jobs/199213998

Ran the following command successfully:
  cpplint --repository=. --recursive \
  --filter=-whitespace/line_length,-legal/copyright,-runtime/printf,-build/include,-build/namespace,-runtime/int \
  ./src

* 🔥 Remove MQTT ack logging

* 🐎 Make tiny optimizations

* 🎨 Add a comma to the wifi connected log

* 🎨 Reorganize next boot mode feature

* 🐎 Check length on input fields (homieiot#292)

* Fixing loopFunction being called too early before MQTT connection is established

* Started cleanup of strcpy/sprintf to include length check.

* Fixed warning under Interface.cpp

* 👕 Fix lint

* 🎨 Print firmware name and version at boot

* 🐛 Fix DeviceId incomplete MAC address (homieiot#296)

snprintf works with n-1 characters

expected behaviour: DeviceId is 12 characters
behaviour: only 11 characters are returned

(resulting in a "incomplete" mac address)

* :bug Fix millis() overflow in uptime - fix homieiot#299 (homieiot#302)

Corrected type declaration for correct overflow handling of millis
function in uptime calculation
@@ -97,6 +97,9 @@ void BootNormal::loop() {
ESP.restart();
}

for (HomieNode* iNode : HomieNode::nodes) {
Copy link
Contributor

@jamesmyatt jamesmyatt Feb 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this moved? It may break functionality that assumes that loopFunction is executed before the individual node loop methods (for example). Or, in fact, all of the connection logic that is immediately below this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the loop is before the loop.

Prior the change, the loop-function was called as last. Now it is called first, so the order has not changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Maybe it's not so bad, but the end of the loop and the start are only the same if there's nothing else in the Arduino loop function.

@jamesmyatt
Copy link
Contributor

jamesmyatt commented Feb 14, 2018

I'm strongly opposed to this implementation. It could break existing HomieNodes that assume that the loop methods are only executed when MQTT is connected. Furthermore, if a particular HomieNode expects the runLoopDisconnected to be set to function correctly, then there is no way to enforce that and users may forget to set the flag, creating unexpected behaviour.

I suggest to have two "loop" methods per HomieNode: one that only runs when connected (as currently) and one that runs even when disconnected. Then it is up to the implementation of each HomieNode to determine when the loop functionality should run.

I'm also worried about unintended consequences of moving where the node loop methods are executed within the homie loop method.

@euphi
Copy link
Member Author

euphi commented Feb 14, 2018

runLoopDisconnected is initialized to false, so the default behaviour has not changed.

Furthermore, runLoopDisconnected is a field of HomieNode, so each HomieNode can set the flag itself. It even couldoverride the setter, so no one else can change this.
(I think it is sufficient that the setter is non-virtual, because no user would access a derived class as HomieNode unless he knows what he's doing - however, if you think that this is not enough, the setter can be made virtual).

@jamesmyatt
Copy link
Contributor

jamesmyatt commented Feb 15, 2018

OK. I take back my comments about runLoopDisconnected. I was a bit hasty; I thought it was a property of Homie rather than of the Node. I don't think you need a setter since the property is protected and it should only be set during the Node constructor.

I still think it would be better with two loop methods for the Node, one which runs always and one which runs when connected.

@timpur
Copy link
Contributor

timpur commented Feb 15, 2018

Compermise ? Pass is connected into the loop ?

@euphi
Copy link
Member Author

euphi commented Feb 16, 2018

@nzbuu you're rigth with the setter. There is no need for it, if you can set the flag in constructor. I will add an optional parameter to HomieNode::HomieNode(..).

@euphi
Copy link
Member Author

euphi commented Feb 16, 2018

Oh, and I don't see the benefit of passing a connected parameter to loop(), because it is easy to "ask" homie for it's current state.

@timpur
Copy link
Contributor

timpur commented Feb 17, 2018

More for convenience

But if this loop is running at max speed then asking for the status every look could slow down the loop speed ??? Idk

@stritti
Copy link
Collaborator

stritti commented Feb 27, 2019

Would be cool to have loops which are running without connection to build more robust controllers which are working without connections too.

Any progress on this issue?

@euphi euphi merged commit 9968042 into homieiot:develop Mar 10, 2019
@euphi
Copy link
Member Author

euphi commented Mar 10, 2019

As this is for the development-version (both v2 and v3), I think the minor risk of side effecs due to the different running order in the loop is acceptable.
This closes #571, #536, #487, #354

@kleini
Copy link
Collaborator

kleini commented Mar 11, 2019

For this breaks all my existing HomieNodes. Previously I could assume that MQTT is ready when the HomieNode::loop() method is called. This is not the case any more and results in MQTT problems. My HomieNodes read sensor values in the loop method() and send them via MQTT. MQTT sending does not work any more as MQTT ready is not reached and SendPromise::send() refuses to send data if MQTT ready is not reached.
For me this merge has a big impact and breaks all my HomieNodes although runLoopDisconnected is still false in my cases.
So my question is, is this intended that HomieNode::loop() should be executed although MQTT ready is not reached and SendPromise::send() refuses to send messages? Do I need to check manually for MQTT ready to make send() not fail?

kleini added a commit to kleini/homie-esp8266 that referenced this pull request Mar 11, 2019
@euphi euphi deleted the upstream-develop branch March 11, 2019 22:27
kleini added a commit to kleini/homie-esp8266 that referenced this pull request Mar 24, 2019
@mwildbolz mwildbolz mentioned this pull request Jan 6, 2020
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

Successfully merging this pull request may close these issues.

5 participants