sinricpro / esp8266-esp32-sdk

Library for https://sinric.pro - simple way to connect your device to Alexa, Google Home, SmartThings and cloud
https://sinric.pro
Other
230 stars 124 forks source link

A remote connect #100

Closed serge2804 closed 3 years ago

serge2804 commented 3 years ago

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

sivar2311 commented 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

serge2804 commented 3 years ago

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

kakopappa commented 3 years ago

@serge2804 This might help

https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/examples/Switch/WeMosD1_mini_relay_shield/WeMosD1_mini_relay_shield.ino#L62

serge2804 commented 3 years ago

@serge2804 This might help

https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/examples/Switch/WeMosD1_mini_relay_shield/WeMosD1_mini_relay_shield.ino#L62

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.

sivar2311 commented 3 years ago

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.

serge2804 commented 3 years ago

Thank you a lot, I'm going try to make it run for me :)

serge2804 commented 3 years ago

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

ifdef ENABLE_DEBUG

   #define DEBUG_ESP_PORT Serial
   #define NODEBUG_WEBSOCKETS
   #define NDEBUG

endif

include

ifdef ESP8266

   #include <ESP8266WiFi.h>

endif

ifdef ESP32

   #include <WiFi.h>

endif

include "SinricPro.h"

include "SinricProSwitch.h"

define WIFI_SSID "freebox_chats2"

define WIFI_PASS "DECE280461"

define APP_KEY "e94c1987-b9d9-49fd-af96-38fa188xxxxxx" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"

define APP_SECRET "95e2c0e6-6030-43bf-bd55-cba1f4e14b7c-675e12b6-b185-4da2-bd69-2fexxxxxxxxx" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"

define SWITCH_ID "5f99b3150fb16xxxxxxxxx" // Should look like "5dc1564130xxxxxxxxxxxxxx"

define BAUD_RATE 115200 // Change baudrate to your need

// #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/

include

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(); }

sivar2311 commented 3 years ago

I am missing the onPowerState assingnment (mySwitch.onPowerState(onPowerState);) And please, remove the delays.

serge2804 commented 3 years ago

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 !