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
227 stars 121 forks source link

Compilation error: invalid user-defined conversion from 'SINRICPRO_3_0_1::SinricProClass::Proxy' to 'SinricProDoorbell&&' {aka 'SINRICPRO_3_0_1::SinricProDoorbell&&'} [-fpermissive] #382

Closed 12usernull closed 1 month ago

12usernull commented 1 month ago

Compilation error: invalid user-defined conversion from 'SINRICPRO_3_0_1::SinricProClass::Proxy' to 'SinricProDoorbell&&' {aka 'SINRICPRO_3_0_1::SinricProDoorbell&&'} [-fpermissive]

/*
 * Example for how to use SinricPro Doorbell device:
 * - setup a doorbell device
 * - send event to sinricPro server if button is pressed
 * 
 * If you encounter any issues:
 * - check the readme.md at https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md
 * - ensure all dependent libraries are installed
 *   - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#arduinoide
 *   - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#dependencies
 * - open serial monitor and check whats happening
 * - check full user documentation at https://sinricpro.github.io/esp8266-esp32-sdk
 * - visit https://github.com/sinricpro/esp8266-esp32-sdk/issues and check for existing issues or open a new one
 */

#ifdef ENABLE_DEBUG
  #define DEBUG_ESP_PORT Serial
  #define NODEBUG_WEBSOCKETS
  #define NDEBUG
#endif 

#include <Arduino.h>
#if defined(ESP8266)
  #include <ESP8266WiFi.h>
#elif defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
  #include <WiFi.h>
#endif
#include "Vector.h"
#include "SinricPro.h"
#include "SinricProDoorbell.h"

#define WIFI_SSID         "ErtuModem"
#define WIFI_PASS         "223355668899"
#define APP_KEY           "a1ab36f4-a0e0-4a10-a018-17ab1ecf83c6"
#define APP_SECRET        "c391f084-9568-489f-93fd-39640d9f9743-b467c085-2cf8-4025-ba5d-0831c5261884"
#define DOORBELL_ID       "665580a35d818a66fab18011"  

#define BAUD_RATE         115200                // Change baudrate to your need

#define BUTTON_PIN         0

// checkButtonpress
// reads if BUTTON_PIN gets LOW and send Event
void checkButtonPress() {
  if (SinricPro.isConnected() == false) {
    Serial.printf("Not connected to Sinric Pro...!\r\n");
    return; 
  }

  static unsigned long lastBtnPress;
  unsigned long actualMillis = millis();

  if (actualMillis-lastBtnPress > 500) {
    if (digitalRead(BUTTON_PIN)==LOW) {
      Serial.printf("Ding dong...\r\n");
      lastBtnPress = actualMillis;

      // get Doorbell device back
      SinricProDoorbell& myDoorbell = SinricPro[DOORBELL_ID];

      // send doorbell event
      myDoorbell.sendDoorbellEvent();
    }
  }
}

// setup function for WiFi connection
void setupWiFi() {
  Serial.printf("\r\n[Wifi]: Connecting");

  #if defined(ESP8266)
    WiFi.setSleepMode(WIFI_NONE_SLEEP); 
    WiFi.setAutoReconnect(true);
  #elif defined(ESP32)
    WiFi.setSleep(false); 
    WiFi.setAutoReconnect(true);
  #endif

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

// setup function for SinricPro
void setupSinricPro() {
  // add doorbell device to SinricPro
  SinricProDoorbell&&myDoorbell = SinricPro[DOORBELL_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(BUTTON_PIN, INPUT);

  Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
  setupWiFi();
  setupSinricPro();
}

void loop() {
  checkButtonPress();
  SinricPro.handle();
}
sivar2311 commented 1 month ago

SinricProDoorbell&&myDoorbell = SinricPro[DOORBELL_ID];

There must be just one &!

sivar2311 commented 1 month ago

The reason is the second ampersand character.

12usernull commented 1 month ago

😑 : ( Compilation error: invalid user-defined conversion from 'SINRICPRO_3_0_1::SinricProClass::Proxy' to 'SinricProDoorbell&&' {aka 'SINRICPRO_3_0_1::SinricProDoorbell&&'} [-fpermissive]

12usernull commented 1 month ago

Same error

sivar2311 commented 1 month ago

Change SinricProDoorbell&&myDoorbell = SinricPro[DOORBELL_ID]; to SinricProDorbell& myDoorBell=SinricPro[DOORBELL_ID];

Just one "&" not two!