Closed wendellmeloo009 closed 1 year ago
Hi @wendellmeloo009
The line of code you are referring to is not part of the SinricPro library. Please show the sketch you are trying to compile and the complete error message.
/*
* ADVANCED example for: how to use up to N SinricPro Switch devices on one ESP module
* to control N relays and N flipSwitches for manually control:
* - setup N SinricPro switch devices
* - setup N relays
* - setup N flipSwitches to control relays manually
* (flipSwitch can be a tactile button or a toggle switch and is setup in line #52)
*
* - handle request using just one callback to switch relay
* - handle flipSwitches to switch relays manually and send event to sinricPro server
*
* - SinricPro deviceId and PIN configuration for relays and buttins is done in std::map<String, deviceConfig_t> devices
*
* 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>
#include <WiFi.h>
#include "SinricPro.h"
#include "SinricProSwitch.h"
#include <map>
#define WIFI_SSID '' ssd"
#define WIFI_PASS "senha"
#define APP_KEY "#######"
#define APP_SECRET "#######"
// comment the following line if you use a toggle switches instead of tactile buttons
#define BAUD_RATE 115200
#define DEBOUNCE_TIME 250
#define RELAYPIN_1 27
#define RELAYPIN_2 26
typedef struct { // struct for the std::map below
int relayPIN;
int flipSwitchPIN;
bool activeLow;
} deviceConfig_t;
// this is the main configuration
// please put in your deviceId, the PIN for Relay and PIN for flipSwitch
// this can be up to N devices...depending on how much pin's available on your device ;)
// right now we have 4 devicesIds going to 4 relays and 4 flip switches to switch the relay manually
std::map<String, deviceConfig_t> devices = {
//{deviceId, {relayPIN, flipSwitchPIN, activeLow}}
{"64a1ebc3743f91207045a999", { 27, 18, false }},
{"64a1ea9d743f91207045a80e", { 26, 17, false }},
};
typedef struct { // struct for the std::map below
String deviceId;
bool lastFlipSwitchState;
unsigned long lastFlipSwitchChange;
bool activeLow;
} flipSwitchConfig_t;
std::map<int, flipSwitchConfig_t> flipSwitches; // this map is used to map flipSwitch PINs to deviceId and handling debounce and last flipSwitch state checks
// it will be setup in "setupFlipSwitches" function, using informations from devices map
void setupRelays() {
for (auto &device : devices) { // for each device (relay, flipSwitch combination)
int relayPIN = device.second.relayPIN; // get the relay pin
pinMode(relayPIN, OUTPUT); // set relay pin to OUTPUT
}
}
void setupFlipSwitches() {
for (auto &device : devices) { // for each device (relay / flipSwitch combination)
flipSwitchConfig_t flipSwitchConfig; // create a new flipSwitch configuration
flipSwitchConfig.deviceId = device.first; // set the deviceId
flipSwitchConfig.lastFlipSwitchChange = 0; // set debounce time
flipSwitchConfig.lastFlipSwitchState = false; // set lastFlipSwitchState to false (LOW)
int flipSwitchPIN = device.second.flipSwitchPIN; // get the flipSwitchPIN
bool activeLow = device.second.activeLow; // set the activeLow
flipSwitchConfig.activeLow = activeLow;
flipSwitches[flipSwitchPIN] = flipSwitchConfig; // save the flipSwitch config to flipSwitches map
if(activeLow) {
pinMode(flipSwitchPIN, INPUT_PULLUP); // set the flipSwitch pin to INPUT_PULLUP
}
else {
pinMode(flipSwitchPIN, INPUT); // set the flipSwitch pin to INPUT
}
}
}
bool onPowerState(String deviceId, bool &state) {
Serial.printf("%s: %s\r\n", deviceId.c_str(), state ? "on" : "off");
int relayPIN = devices[deviceId].relayPIN; // get the relay pin for corresponding device
digitalWrite(relayPIN, !state); // set the new relay state
return true;
}
void handleFlipSwitches() {
unsigned long actualMillis = millis(); // get actual millis
for (auto &flipSwitch : flipSwitches) { // for each flipSwitch in flipSwitches map
unsigned long lastFlipSwitchChange = flipSwitch.second.lastFlipSwitchChange; // get the timestamp when flipSwitch was pressed last time (used to debounce / limit events)
if (actualMillis - lastFlipSwitchChange > DEBOUNCE_TIME) { // if time is > debounce time...
int flipSwitchPIN = flipSwitch.first; // get the flipSwitch pin from configuration
bool lastFlipSwitchState = flipSwitch.second.lastFlipSwitchState; // get the lastFlipSwitchState
bool activeLow = flipSwitch.second.activeLow;
bool flipSwitchState = digitalRead(flipSwitchPIN); // read the current flipSwitch state
if(activeLow) flipSwitchState = !flipSwitchState;
if (flipSwitchState != lastFlipSwitchState) { // if the flipSwitchState has changed...
#ifdef TACTILE_BUTTON
if (flipSwitchState) { // if the tactile button is pressed
#endif
flipSwitch.second.lastFlipSwitchChange = actualMillis; // update lastFlipSwitchChange time
String deviceId = flipSwitch.second.deviceId; // get the deviceId from config
int relayPIN = devices[deviceId].relayPIN; // get the relayPIN from config
bool newRelayState = !digitalRead(relayPIN); // set the new relay State
digitalWrite(relayPIN, newRelayState); // set the trelay to the new state
SinricProSwitch &mySwitch = SinricPro[deviceId]; // get Switch device from SinricPro
mySwitch.sendPowerStateEvent(newRelayState); // send the event
#ifdef TACTILE_BUTTON
}
#endif
flipSwitch.second.lastFlipSwitchState = flipSwitchState; // update lastFlipSwitchState
}
}
}
}
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());
}
void setupSinricPro() {
for (auto &device : devices) {
const char *deviceId = device.first.c_str();
SinricProSwitch &mySwitch = SinricPro[deviceId];
mySwitch.onPowerState(onPowerState);
}
SinricPro.begin(APP_KEY, APP_SECRET);
}
void setup() {
Serial.begin(BAUD_RATE);
setupRelays();
setupFlipSwitches();
setupWiFi();
setupSinricPro();
}
void loop() {
SinricPro.handle();
handleFlipSwitches();
}
esse é o esboço so removi as chaves a a senha do wifi para mandar aque
Please also show the complete error message
Por favor, mostre também a mensagem de erro completa
'setlnsecure'
_cliente. ssl->setlnsecure(); código de retorno não é 0
só aparece isso
e todas as blibioteca estão em ultima versão
Por favor, mostre também a mensagem de erro completa
e o hardware que estou usando é um doite esp32 dev kit v1
'setlnsecure'
_cliente. ssl->setlnsecure(); código de retorno não é 0
só aparece isso
This is not the full error message. Please copy and paste the full error message.
The multiswitch_advanced examples compiles fine for ESP32 devkit V1.
Used versions:
Also compiles fine using the following versions:
Os exemplos multiswitch_advanced compilam bem para ESP32 devkit V1.
Versões usadas:
- Arduino-Core 2.0.7
- SinricPro 2.11.1
- ArduinoJson 6.21.2
- WebSockets 2.4.1
a bom eu não estava usando arduino core vou tentar novamente e ja lhe dou resposta
Unfortunately I don't understand this, because SinricPro is an Arduino library and can only be used with the Arduino framework.
Also the FULL error message is still missing...
(Answers from you in English would also be very kind, as I cannot read / write your native language.)
sorry I'll use Google translate is I tried several ways but not concigo compile the code I believe it is my version of Windows that is very limited if I send you the file in .ino you would be kind enough to compile and send me in .bin it would help a lot
I don't think that this is a Windows issue. But anyways... send me your .ino file and I'll send you the .bin
Eu não acho que isso seja um problema do Windows. Mas de qualquer forma... envie-me seu arquivo .ino e eu lhe enviarei o .bin
you have email or WhatsApp so I can send you do not know if aque on github has private chat
Send it to sivar2311@gmail.com
Hi @wendellmeloo009
I have not received an email yet. Have you sent one yet?
'setlnsecure'
_cliente. ssl->setlnsecure(); return code is not 0