-
Notifications
You must be signed in to change notification settings - Fork 122
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
sinricpro and esp8266 #221
Comments
The The meaning of the state parameter is A detailed description can be found in the documentation. If you need dedicated functions for on and off, you can call them from the onPowerState callback. Like so: void turnOn() {
// do something
}
void turnOff() {
// do something else
}
bool onPowerState(const String& deviceId, bool& state) {
if (state) {
turnOn();
} else {
turnOff();
}
return true;
} Since bool onPowerState(const String& deviceId, bool& state) {
digitalWrite(pin, state);
return true;
} You are completely free to choose what should happen in the callbacks. The callbacks always have a return value of the type For this reason it is a good idea that your dedicated functions also have a return value of type bool turnOn() {
// do something
return true; // operation was successful
}
bool turnOff() {
// do something else
return true; // operation was successful
}
bool onPowerState(const String& deviceId, bool& state) {
if (state) {
return turnOn();
} else {
return turnOff();
}
}
A much shorter way of writing to achieve the same thing is: bool onPowerState(const String& deviceId, bool& state) {
return state ? turnOn() : turnOff();
} |
Thanks a lot.
From: Boris Jäger ***@***.***>
Date: Wednesday, October 6, 2021 at 12:24 AM
To: sinricpro/esp8266-esp32-sdk ***@***.***>
Cc: carloslassous ***@***.***>, Author ***@***.***>
Subject: Re: [sinricpro/esp8266-esp32-sdk] sinricpro and esp8266 (#221)
The onPowerStateCallback has the parameter state of type bool.
The meaning of the state parameter is
true = the device is requested to turn on
false = The device is requested to switch off
A detailed description can be found in the documentation<https://sinricpro.github.io/esp8266-esp32-sdk/class_power_state_controller.html#aad370bc6b280bbdeac98181a31f22df4>.
In the documentation you will also find an overview<https://sinricpro.github.io/esp8266-esp32-sdk/class_power_state_controller.html> of which device types implement the onPowerState callback.
If you need dedicated functions for on and off, you can call them from the onPowerState callback. Like so:
void turnOn() {
// do something
}
void turnOff() {
// do something else
}
bool onPowerState(const String& deviceId, bool& state) {
if (state) {
turnOn();
} else {
turnOff();
}
return true;
}
Since HIGH and LOW are only defined values for true and false, the shortest way to switch a digital PIN on or off is this:
bool onPowerState(const String& deviceId, bool& state) {
digitalWrite(pin, state);
return true;
}
You are completely free to choose what should happen in the callbacks.
The callbacks always have a return value of the type bool which is returned to the SinricServer (and also to Alexa etc.).
A return true; at the end of the callback function signals that the action was executed successfully (Alexa will reply with "OK").
A return false; signals that something failed (e.g. a motor could not close the door). Alexa will then reply something like "Sorry, but something went wrong".
For this reason it is a good idea that your dedicated functions also have a return value of type bool which is then returned by the onPowerState callback like so:
bool turnOn() {
// do something
return true; // operation was successful
}
bool turnOff() {
// do something else
return true; // operation was successful
}
bool onPowerState(const String& deviceId, bool& state) {
if (state) {
return turnOn();
} else {
return turnOff();
}
}
A much shorter way of writing to achieve the same thing is:
bool onPowerState(const String& deviceId, bool& state) {
return state ? turnOn() : turnOff();
}
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#221 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AEVYOZLZXIS45LC2K6HQ2XLUFPMQXANCNFSM5FNL6RPQ>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
This issue has gone quiet. Spooky quiet. We currently close issues after 14 days of inactivity. It’s been at least 7 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder, the best way to fix this or any other problem is to provide a detailed error description including a serial log. Thanks for being a part of the SinricPro community! |
Thanks, the issued was resolve by the person that answered me.
Sent from Yahoo Mail for iPhone
On Friday, October 15, 2021, 6:22 AM, stale[bot] ***@***.***> wrote:
This issue has gone quiet. Spooky quiet. We currently close issues after 14 days of inactivity. It’s been at least 7 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder, the best way to fix this or any other problem is to provide a detailed error description including a serial log. Thanks for being a part of the SinricPro community!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
This issue has gone quiet. Spooky quiet. We currently close issues after 14 days of inactivity. It’s been at least 7 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder, the best way to fix this or any other problem is to provide a detailed error description including a serial log. Thanks for being a part of the SinricPro community! |
Hey again! It’s been 14 days since anything happened on this issue, so our friendly robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m |
Hello:
I am trying to create a personal switch with Sindric.
This should happen when I am turning on the device. If I turn Off the device something else should happen.
How do I create another method for this, I mean, one for On and one for Off
bool onPowerState1(const String &deviceId, bool &state)
{
digitalWrite(D0, LOW);
delay(1000);
digitalWrite(D0, HIGH);
Serial.printf("Device 1 turned %s\r\n", state?"on":"off");
return true; // request handled properly
}
The text was updated successfully, but these errors were encountered: