Closed serge2804 closed 3 years ago
Hi Serge,
the code for sending the RF command should be still the same. You only need to implement your existing RF code in onPowerState() callback
thank you for the reply, so fast... May I ask you to write me an example of the structure of the "onPowerState()" I admit I am bite lost on this new way to write the commande lines. I have two commands, as u guess. One for the ON and one for the OFF
@serge2804 This might help
thank you for the link, I have had a look on this example, but in this one u send a "digitalwrite" ... in my case i used to call two void (), one for turnon, one for turnoff... anyway, maybe it is not the best solution, but it was ok and run.
Take the switch example
Then change the onPowerState function:
bool onPowerState(const String &deviceId, bool &state) {
if (state==true) {
// Write here your code to switch on the light
} else {
// Write here your code to switch off the light
}
return true; // request handled properly
}
Please check full documentation for further informations about the different devices and available callback-functions.
Thank you a lot, I'm going try to make it run for me :)
after a long time trying, i still have the same error message on sinric dashboard : "device return en error while processing the request" :(
if someone can have a look and tell me whats wrong. Thank you in advance
I try the RF direct command and its runs
thats my sketch
// Uncomment the following line to enable serial debug output //#define ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#include <ESP8266WiFi.h>
#include <WiFi.h>
// #define RELAY_PIN D1 // * Relay Shield transistor closes relay when D1 is HIGH
bool myPowerState = false;
// Pour plus d'info sur la RF http://darrigan.net/blog/prises-telecommandees-radiofrequence-arduino/
RCSwitch myswitch = RCSwitch();
// code pour la télécommande RF unsigned long LUMIERE_1_ON = 1118229; unsigned long LUMIERE_1_OFF = 1118228;
/ bool onPowerState(String deviceId, bool &state)
// 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); } Serial.printf("connected!\r\n[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str()); }
// setup function for SinricPro void setupSinricPro() { // add device to SinricPro SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];
// 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() { // pinMode(RELAY_PIN, OUTPUT); // define Relay GPIO as output myswitch.enableTransmit(13);
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n"); setupWiFi(); setupSinricPro(); }
void loop() { SinricPro.handle(); }
I am missing the onPowerState assingnment (mySwitch.onPowerState(onPowerState);
)
And please, remove the delays.
Thank you a lottttt ... thats ok now :)
just maybe say to add (the onPowerState assingnment) in "void setupSinricPro() "
Maybe this post will help some others !
Hi all, first I'm french so I hope you will forgive my not perfect english.
I was using Sinric till now, but nowaday it doesn't run more so i needed to connect on SinricPro and reviewing my arduino sketch. my device is turnig on off a light (classic one) using a RF remote for that. and it runs on Alexa. I'm using a Wemos D1 R2 for that. My problem is I don't find in the example the way to send a command to the RF device connected to the arduino. It was ok on sinric but the same "routine" doesn't run more on SinricPro.
Thank you in advance for your Help. Serge