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

Subscribe node to all properties #62

Closed
rossdargan opened this issue Apr 12, 2016 · 19 comments
Closed

Subscribe node to all properties #62

rossdargan opened this issue Apr 12, 2016 · 19 comments
Milestone

Comments

@rossdargan
Copy link

I am wanting to use the node input handler as I'm planning on controlling a set of switches. The property will relate to the switch, and the value will tell me if it is on or off.

My code looks like this:

HomieNode rcSwitchNode("rcSwitch", "switch", rcSwitchOnHandler);

bool rcSwitchOnHandler(String property, String value) {
  int houseCode = 1;
  int socketCode = property.toInt();

  controlStatusSwitch(houseCode,socketCode,value=="true");
  if (value == "true") {    
    Homie.setNodeProperty(rcSwitchNode, property, "true"); // Update the state of the light
    Serial.println("Switch is on");
  } else if (value == "false") {    
   Homie.setNodeProperty(rcSwitchNode, property, "false");
    Serial.println("Switch is off");
  } else {
    return false;
  }
  return true;
}

void setup() {  
  mySwitch.setProtocol(1);
  mySwitch.setRepeatTransmit(10);
  mySwitch.setPulseLength(307); // Bye Bye Standby
  mySwitch.enableTransmit(5);

  Homie.setFirmware("homie-switch", "1.0.0");
  Homie.registerNode(rcSwitchNode);
  Homie.setup();
}

Now I think my issue is that I'm not calling Homie.Subscribe("property",rcSwitchOnHandler) but I want to allow any property to be sent through really (well a number from 1->14).

This is the error homie gives me:

Node rcSwitch not subscribed to 1

Thanks for this wonderful library!

@marvinroger marvinroger modified the milestones: v2.0.0, v1.4.0 Apr 13, 2016
@marvinroger
Copy link
Member

What about a 4th parameter in the HomieNode constructor, that if set to true would by default subscribe to every properties? So you would only have to:

HomieNode rcSwitchNode("rcSwitch", "switch", rcSwitchOnHandler, true);

@rossdargan
Copy link
Author

yeah, that would work nicely!

@marvinroger
Copy link
Member

Great!

@marvinroger marvinroger changed the title Trying to use the node input handler Subscribe node to all properties Apr 13, 2016
marvinroger pushed a commit that referenced this issue Apr 14, 2016
@marvinroger
Copy link
Member

Will land in v1.4.0. :)

@rossdargan
Copy link
Author

Hi Marvin

I'm not a c dev, but I think the new changes could result in the property handler getting called twice. I've added a commend to the check in.

@rossdargan
Copy link
Author

In fact the https://github.com/marvinroger/homie-esp8266/blob/master/docs/3.-Advanced-usage.md suggests that the node input handler should handle every changed property of a specific node, but at the minute it doesn't. The same way the global input handler will not be called unless there is at least one subscription on that node.

An alternative could be to move 2bc6c8d#diff-ee62c9806128c2e2d545222f1f62952aR255 doewn below the global input handler, and the node property handler call?

That way you wouldn't need the subscribe all stuff (and it would more closely match the docs at the minute)

@marvinroger
Copy link
Member

I am not sure I understand what you mean. It handles every changed property of a specific node, if this property is registered. In your case, it will be called since you will use a node that is subscribed to all properties.

@marvinroger
Copy link
Member

And the property handler is called once, why would it be called twice?

@rossdargan
Copy link
Author

Had another look through, and I totally get it now! This is a great solution, thanks.

@marvinroger
Copy link
Member

You're welcome! :)

@marvinroger
Copy link
Member

@rossdargan before I release, can you test if it works for you? I added a LedStrip example for a concrete use case.

@marvinroger
Copy link
Member

@rossdargan
Copy link
Author

Sure thing (It may be Saturday night now though I'm afraid!)

@marvinroger
Copy link
Member

No problem. 😄

@webguy16
Copy link

Hello, thanks for the great work on this, not OP, but i figured i would give this a shot (already have a sous vide cooker going with the homie library) and it looks to be working well. Here is the code i am using:
https://github.com/webguy16/espCloner/blob/testing/espCloner_Homie/src/espCloner_Homie.ino

@marvinroger
Copy link
Member

Thanks a lot for your feedback! Glad to hear it is stable for you.

@rossdargan
Copy link
Author

Tested, and all working for me - fab! Here is my project https://github.com/rossdargan/Arduino-Projects/blob/master/HomieSwitch/HomieSwitch.ino

@marvinroger
Copy link
Member

Awesome, I guess it's ready for prime-time, then. :)

@marvinroger
Copy link
Member

Released!

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

No branches or pull requests

3 participants