-
-
Save kakopappa/ec3a1c664e116a8423ce0a6b33ed7a7d to your computer and use it in GitHub Desktop.
//#define ENABLE_DEBUG | |
#ifdef ENABLE_DEBUG | |
#define DEBUG_ESP_PORT Serial | |
#define NODEBUG_WEBSOCKETS | |
#define NDEBUG | |
#endif | |
#include <Arduino.h> | |
#ifdef ESP8266 | |
#include <ESP8266WiFi.h> | |
#endif | |
#ifdef ESP32 | |
#include <WiFi.h> | |
#endif | |
#include "SinricPro.h" | |
#include "SinricProBlinds.h" | |
#define WIFI_SSID "" | |
#define WIFI_PASS "" | |
#define APP_KEY "" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx" | |
#define APP_SECRET "" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx" | |
#define DRAPE_ID "" // Should look like "5dc1564130xxxxxxxxxxxxxx" | |
#define CURTAIN_ID "" // Should look like "5dc1564130xxxxxxxxxxxxxx" | |
#define BAUD_RATE 9600 // Change baudrate to your need | |
int drapeBlindsPosition = 0; | |
int curtainBlindsPosition = 0; | |
bool onDrapePowerState(const String &deviceId, bool &state) { | |
Serial.printf("Drape %s power turned %s \r\n", deviceId.c_str(), state?"on":"off"); | |
digitalWrite(22, HIGH); | |
return true; // request handled properly | |
} | |
bool onDrapeRangeValue(const String &deviceId, int &position) { | |
Serial.printf("Device %s set position to %d\r\n", deviceId.c_str(), position); | |
return true; // request handled properly | |
} | |
bool onDrapeAdjustRangeValue(const String &deviceId, int &positionDelta) { | |
drapeBlindsPosition += positionDelta; | |
Serial.printf("Device %s position changed about %i to %d\r\n", deviceId.c_str(), positionDelta, drapeBlindsPosition); | |
positionDelta = drapeBlindsPosition; // calculate and return absolute position | |
return true; // request handled properly | |
} | |
bool onCurtainPowerState(const String &deviceId, bool &state) { | |
Serial.printf("Curtain %s power turned %s \r\n", deviceId.c_str(), state?"on":"off"); | |
return true; // request handled properly | |
} | |
bool onCurtainRangeValue(const String &deviceId, int &position) { | |
Serial.printf("Device %s set position to %d\r\n", deviceId.c_str(), position); | |
return true; // request handled properly | |
} | |
bool onCurtainAdjustRangeValue(const String &deviceId, int &positionDelta) { | |
curtainBlindsPosition += positionDelta; | |
Serial.printf("Device %s position changed about %i to %d\r\n", deviceId.c_str(), positionDelta, curtainBlindsPosition); | |
positionDelta = curtainBlindsPosition; // calculate and return absolute position | |
return true; // request handled properly | |
} | |
// setup function for WiFi connection | |
void setupWiFi() { | |
Serial.printf("\r\n[Wifi]: Connecting"); | |
WiFi.begin(WIFI_SSID, WIFI_PASS); | |
while (WiFi.status() != WL_CONNECTED) { | |
Serial.printf("."); | |
delay(250); | |
} | |
IPAddress localIP = WiFi.localIP(); | |
Serial.printf("connected!\r\n[WiFi]: IP-Address is %d.%d.%d.%d\r\n", localIP[0], localIP[1], localIP[2], localIP[3]); | |
} | |
void setupSinricPro() { | |
// get a new Blinds device from SinricPro | |
SinricProBlinds &myDrape = SinricPro[DRAPE_ID]; | |
myDrape.onPowerState(onDrapePowerState); | |
myDrape.onRangeValue(onDrapeRangeValue); | |
myDrape.onAdjustRangeValue(onDrapeAdjustRangeValue); | |
SinricProBlinds &myCurtain = SinricPro[CURTAIN_ID]; | |
myCurtain.onPowerState(onCurtainPowerState); | |
myCurtain.onRangeValue(onCurtainRangeValue); | |
myCurtain.onAdjustRangeValue(onCurtainAdjustRangeValue); | |
// setup SinricPro | |
SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); }); | |
SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); }); | |
SinricPro.begin(APP_KEY, APP_SECRET); | |
} | |
// main setup function | |
void setup() { | |
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n"); | |
pinMode(22, OUTPUT); | |
setupWiFi(); | |
setupSinricPro(); | |
} | |
void loop() { | |
SinricPro.handle(); | |
} |
Hello!
Please teach me how to use gpio at ”onDrapePowerState”.
There was an error at ”if ( state == on )” in my sketch.
error:'on' was not declared in this scope
bool onDrapePowerState(const String &deviceId, bool &state) {
Serial.printf("Drape %s power turned %s \r\n", deviceId.c_str(), state?"on":"off");
if ( state == on ){
digitalWrite(PIN_SEL3, HIGH);
digitalWrite(PIN_SEL4, LOW);
delay(3000);
Thank you for your advice.
I wii take a course.
Hello!
I'm worried that I can't perform the next operation for about 3 seconds after operating something. Is there any way to improve response of SINRIC APP?
bool onDrapeRangeValue(const String &deviceId, int &position) {
Serial.printf("Device %s set position to %d\r\n", deviceId.c_str(), position);
if (position == 100){
digitalWrite(PIN_SEL3, HIGH);
digitalWrite(PIN_SEL4, LOW);
delay(val);
digitalWrite(PIN_SEL3, LOW);
digitalWrite(PIN_SEL4, LOW);
}
else if (position == 0){
digitalWrite(PIN_SEL3, LOW);
digitalWrite(PIN_SEL4, HIGH);
delay(val);
digitalWrite(PIN_SEL3, LOW);
digitalWrite(PIN_SEL4, LOW);
}
return true; // request handled properly
}
Hello.
I found out why my APP response is slow.
Because "return true; // Since request handled properly"
was placed after
"delay (val) ;"
, it was not possible to operate during delay (val).
if (position == 100){
digitalWrite(PIN_SEL1, HIGH);
digitalWrite(PIN_SEL2, LOW);
return true; // request handled properly
delay(val);
digitalWrite(PIN_SEL1, LOW);
digitalWrite(PIN_SEL2, LOW);
}
However, if return true; is placed before delay (val), it will not work after delay (val).(like a above sketch)
Please let me know if there is any good solution.
I understand how to deal with it. Still, although it will be delayed if the curtain and drape are used continuously. I will fix it a little more.
Thank you very much.
Please tell us a little more about your PaSS solution.
Does the content of the program written to the ESP32 change individually during mass production?
APP_KEY
APP_SECRET
Device_ID1
Device_ID2
The following is what you taught me before
- Sinric Pro app for iOS / Android rebranded with your brand name / logo / change color. (Without any layout changes). The app supports device provisioning. You do not have to hardcode the app / security keys. It will be sent to We will provide you a example sketch for device provisioning and OTA once you signed-up to use PaSS solution.
Thank you . I understand.
The function of our automatic curtain is
① Open ② Stop ③ Close
3 actions and
③ Setting of operation time (open / stop)
④ Timer setting (wake up at 7:00, etc.)
It's different from the blinds, can you give me a special treatment?
- Open / Stop / Close - I can update the app to add a new screen for Curtain and show Open / Stop / Close buttons
- Open / Stop / Close commands must respond within 8 seconds back to Alexa. This is the Alexa rule, not ours. You should send the response back immediately and process the operation in the background.
- Timer setting (wake up at 7:00, etc.). Schedules will be available in the future version of the app. You can always use Alexa app as well for this
Hello!
I am sorry for late reply.
And thank you for telling me these situation.
By the way,
Could you tell me the situation of v2.13x?
has already been released?
Edit Name, WiFi within 14 days (26/June) (Current Sprint) (v2.13.x)
Okay, Thankyouforyourinformation.
Hello!
Please help me about schedule feature.
I'd like to try the schedule feature, but I can't find it.
The version of the app is v2.13.2, can I use it?
I'm using it on Android.
Thank you for your help.
I could found out it.
device type is blind
OK Thank you for your information.