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
236 stars 125 forks source link

Can not get it to flash please help! #22

Closed computerfreek274 closed 4 years ago

computerfreek274 commented 4 years ago

I need a good code for a LOCK i do not see one there so i am just trying to flash a switch one for now. but getting errors.

             from C:\Users\admin\AppData\Local\Temp\arduino_modified_sketch_633916\Switch.ino:34:

C:\Users\admin\Documents\Arduino\libraries\esp8266-esp32-sdk-master\src/SinricProWebsocket.h: In member function 'void websocketListener::begin(String, String, String, SinricProQueue_t*)':

C:\Users\admin\Documents\Arduino\libraries\esp8266-esp32-sdk-master\src/SinricProWebsocket.h:100:13: error: 'class WebSocketsClient' has no member named 'enableHeartbeat'

webSocket.enableHeartbeat(WEBSOCKET_PING_INTERVAL, WEBSOCKET_PING_TIMEOUT, WEBSOCKET_RETRY_COUNT);

         ^

Multiple libraries were found for "ESP8266WiFi.h" Used: C:\Users\admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.0\libraries\ESP8266WiFi Multiple libraries were found for "SinricPro.h" Used: C:\Users\admin\Documents\Arduino\libraries\esp8266-esp32-sdk-master Multiple libraries were found for "ArduinoJson.h" Used: C:\Users\admin\Documents\Arduino\libraries\ArduinoJson Not used: C:\Users\admin\Documents\Arduino\libraries\ArduinoJson-6.x Not used: C:\Users\admin\Documents\Arduino\libraries\CoogleIOT Not used: C:\Users\admin\Documents\Arduino\libraries\arduino_408104 Multiple libraries were found for "WebSocketsClient.h" Used: C:\Users\admin\Documents\Arduino\libraries\WebSockets Not used: C:\Users\admin\Documents\Arduino\libraries\arduinoWebSockets-2.1.0 Multiple libraries were found for "Hash.h" Used: C:\Users\admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.0\libraries\Hash Using library ESP8266WiFi at version 1.0 in folder: C:\Users\admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.0\libraries\ESP8266WiFi Using library esp8266-esp32-sdk-master at version 2.2.7 in folder: C:\Users\admin\Documents\Arduino\libraries\esp8266-esp32-sdk-master Using library ArduinoJson at version 6.13.0 in folder: C:\Users\admin\Documents\Arduino\libraries\ArduinoJson Using library WebSockets at version 2.1.1 in folder: C:\Users\admin\Documents\Arduino\libraries\WebSockets Using library Hash at version 1.0 in folder: C:\Users\admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.0\libraries\Hash exit status 1 Error compiling for board NodeMCU 1.0 (ESP-12E Module).

kakopappa commented 4 years ago

Your problem is

master\src/SinricProWebsocket.h💯13: error: 'class WebSocketsClient' has no member named 'enableHeartbeat'

you should upgrade to latest version of arduinoWebSockets

https://github.com/Links2004/arduinoWebSockets

sivar2311 commented 4 years ago

Using library WebSockets at version 2.1.1 in folder: C:\Users\admin\Documents\Arduino\libraries\WebSockets

You're using wrong websocket library version. You have to use at least WebSocketsClient 2.20 Please check Dependencies Section

computerfreek274 commented 4 years ago

Thank you so much. I knew it was my system but it was so outdated I have not used it for this in over a year. I think Tommorow I will start clean and also switch to platform io. Thanks again.

computerfreek274 commented 4 years ago

Starting Clean Worked Thank you. my IO and IDE where so out of date.

computerfreek274 commented 4 years ago

Using library WebSockets at version 2.1.1 in folder: C:\Users\admin\Documents\Arduino\libraries\WebSockets

You're using wrong websocket library version. You have to use at least WebSocketsClient 2.20 Please check Dependencies Section

Now that i am able to upload again. What i am looking for is a door unlock and lock without any reed switch or stops as i will be right there when it opens unlike the GarageDoor code you have there. I need it to open an hidden door / safe i have an Solenoid Electric Door Lock just need to dumb down the code for GarageDoor i guess but I have tried and get lots off errors. is there anyway you can put up an example code for such a thing. I really like to use pro and pay for it. I can even pay a little bit for the example code. thanks Craig C

sivar2311 commented 4 years ago

What you are looking for is a simple Lock. Please have a look at our Lock example (it is in the dev branch but will merged into master with the next version). You only have to change the onLockState callback to your need (controlling your lock device). Meaning of the lockState parameter in onLockState: lockState == false unlock the door / door is unlocked lockState == true lock the door / door is locked

What kind of errors did you get?

computerfreek274 commented 4 years ago

I am not very good at programing at alI can build stuff but not program! So I tried the new code you sent and can get it to upload fine and get it talking to Sinric just fine now I need it to talk to the relay I would like it on the same pin as the LED I think D0. How do I go about doing this ? For helping me I will send you some money and sign up on PRO. would really appreciate it.

/ /

// 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 "SinricProLock.h"

define WIFI_SSID "x"

define WIFI_PASS "x"

define APP_KEY "x" //

Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"

define APP_SECRET

"x" // Should look like "x"

define LOCK_ID "x" // Should look like

"5dc1564130xxxxxxxxxxxxxx"

define BAUD_RATE 115200 // Change baudrate to

your need

define BTN_FLASH 0

unsigned long lastBtnPress = 0;

/ bool onPowerState(String deviceId, bool &state)

void handleButtonPress() { unsigned long actualMillis = millis(); // get actual millis() and keep it in variable actualMillis if (digitalRead(BTN_FLASH) == LOW && actualMillis - lastBtnPress > 1000) { // is button pressed (inverted logic! button pressed = LOW) and debounced? if (myLockState) { // flip myPowerState: if it was true, set it to false, vice versa myPowerState = false; } else { myLockState = true; } digitalWrite(LED_BUILTIN, myPowerState?LOW:HIGH); // if myPowerState indicates device turned on: turn on led (builtin led uses inverted logic: LOW = LED ON / HIGH = LED OFF)

// get Switch device back
SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];
// send powerstate event
mySwitch.sendPowerStateEvent(myLockState); // send the new powerState to SinricPro server
Serial.printf("Device %s turned %s (manually via flashbutton)\r\n", mySwitch.getDeviceId(), myPowerState?"on":"off");

lastBtnPress = actualMillis;  // update last button press variable

} }

bool onLockState(String deviceId, bool &lockState) { Serial.printf("Device %s is %s\r\n", deviceId.c_str(), lockState?"locked":"unlocked"); return true; }

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() { SinricProLock &myLock = SinricPro[LOCK_ID]; myLock.onLockState(onLockState);

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

void setup() { Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n"); setupWiFi(); setupSinricPro(); } // main setup function void setup() { pinMode(BTN_FLASH, INPUT_PULLUP); // GPIO 0 as input, pulled high pinMode(LED_BUILTIN, OUTPUT); // define LED GPIO as output digitalWrite(LED_BUILTIN, HIGH); // turn off LED on bootup

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

void loop() { handleButtonPress(); SinricPro.handle(); }

sivar2311 commented 4 years ago

Let's to this the other way around. What have you built right now and how is it connected to your ESP. And what ESP module do you use?

computerfreek274 commented 4 years ago

Let's to this the other way around. What have you built right now and how is it connected to your ESP. And what ESP module do you use?

https://www.amazon.com/gp/product/B07HF44GBT/ref=ox_sc_saved_title_1?smid=A2K4DGCC72N9AG&psc=1

https://www.amazon.com/uxcell-Electromagnetic-Solenoid-Assembly-Electirc/dp/B07V7W3ZHB

https://www.amazon.com/WINGONEER-KY-019-Channel-Module-arduino/dp/B06XHJ2PBJ/ref=sr_1_6?keywords=esp8266+relay&qid=1578679651&s=industrial&sr=1-6

I also have some wemo relays and also wemos d1 mini it don't matter all the same I know how to hook them up they all work fine with your SWITCH code and Sinric pro.

I like to set it up with the BLUE LED and pin d0 are used for the relay on the lock. Just like how your code for Switch is setup with the blue led. I would like the LED to turn BLUE when unlocked and OFF when locked. My setup is working fine but not with LOCK code I have it working with your Switch code but that is no good as i want Alexa to unlock my lock with pass code.

Hope this info helps.

Thanks So much!

sivar2311 commented 4 years ago

Ok, this is easy. Just use D4 to control your relay / Solenoid (i am not sure about this because i never had one). D4 is also connected to LED_BUILTIN (that's the blue LED directly on the ESP chip. This is defined in following sketch as LOCK_PIN You may also use D0 which is connected to a secondary blue LED located on the NodeMCU board (known as LED_BUILTIN_AUX)

So, just change LOCK_PIN to the pin you want to use, put in your credentials and upload. Should work right out of the box, with the behavior you want to have.

If not, please contact me via e-mail so we can get in touch using a direct messenger like "Telegram"

/*
 * Example for how to use Lock device as garage door opener
 * 
 * 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
 */

// 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 <Arduino.h>
#ifdef ESP8266 
       #include <ESP8266WiFi.h>
#endif 
#ifdef ESP32   
       #include <WiFi.h>
#endif

#include "SinricPro.h"
#include "SinricProLock.h"

#define WIFI_SSID         "YOUR_WIFI_SSID"    
#define WIFI_PASS         "YOUR_WIFI_PASSWORD"
#define APP_KEY           "YOUR_APP_KEY_HERE"      // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET        "YOUR_APP_SECRET_HERE"   // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define LOCK_ID           "YOUR_DEVICE_ID_HERE"    // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE         9600                     // Change baudrate to your need

#define LOCK_PIN          D4                       // PIN which is used for lock / relay / whatever (D4 is also connected to LED_BUILTIN on NodeMCU)

bool onLockState(String deviceId, bool &lockState) {
  Serial.printf("Device %s is %s\r\n", deviceId.c_str(), lockState?"locked":"unlocked");
  digitalWrite(LOCK_PIN, lockState);
  return true;
}

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() {
  SinricProLock &myLock = SinricPro[LOCK_ID];
  myLock.onLockState(onLockState);

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

void setupPINs() {
  pinMode(LOCK_PIN, OUTPUT);
}

void setup() {
  Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
  setupPINs();
  setupWiFi();
  setupSinricPro();
}

void loop() {
  SinricPro.handle();
}
computerfreek274 commented 4 years ago

Getting there Have an error I do not think it will be a good if I touch it. does this help

" bool onLockState(String deviceId, bool &lockState) { Serial.printf("Device %s is %s\r\n", deviceId.c_str(), lockState?"locked":"unlocked"); digitalWrite(LOCK_PIN, state); return true; }

"

C:\Users\admin\Documents\Arduino\NEW_NEW_LOCK\NEW_NEW_LOCK.ino: In function 'bool onLockState(String, bool&)':

NEW_NEW_LOCK:34:26: error: 'state' was not declared in this scope

digitalWrite(LOCK_PIN, state);

                      ^

Multiple libraries were found for "ESP8266WiFi.h" Used: C:\Users\admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi Multiple libraries were found for "SinricPro.h" Used: C:\Users\admin\Documents\Arduino\libraries\esp8266-esp32-sdk-master Multiple libraries were found for "ArduinoJson.h" Used: C:\Users\admin\Documents\Arduino\libraries\ArduinoJson Multiple libraries were found for "WebSocketsClient.h" Used: C:\Users\admin\Documents\Arduino\libraries\arduinoWebSockets-master Multiple libraries were found for "Hash.h" Used: C:\Users\admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\Hash exit status 1 'state' was not declared in this scope

sivar2311 commented 4 years ago

Sorry, there was a small typo. The Code is now updated and compiling.

computerfreek274 commented 4 years ago

Works Great Thank you!!! I was so close I was putting HIGH and LOW in there lol. Thank you this hidden box remote lock should turn out great.

You should add this code to your examples for sure as with the WEMOS and there relay with a little tweak to the code as it on D1 on the wemo relay. you can have a relay small lock setup with a small eclectic lock.

Where can i find your paypal address ? I would love to send you a little something for all the help.

sivar2311 commented 4 years ago

Best support would be to buy a SinricPro device

computerfreek274 commented 4 years ago

Best support would be to buy a SinricPro device

DONE Thank you!

antoniomorsello commented 4 years ago

sorry I'm not very practical, I can't find the websockets 2.2.0 library to use sinric pro with esp32

sivar2311 commented 4 years ago

Link is in readme: https://github.com/sinricpro/esp8266-esp32-sdk#dependencies

antoniomorsello commented 4 years ago

thanks for the answer but I can't find where to download it, I have read the link several times but nothing. Is there a version of the library in zip format?

sivar2311 commented 4 years ago

Just use the latest Version of WebSockets form Markus Sattler...there is a difference in GIT TAG version and real version. You can use PIO LIbrary Manager or IDE Library Manager to install

antoniomorsello commented 4 years ago

I tried to download the file 2.2.0 and added to the libraries, I used a d1 mini and it gives me this:

Arduino: 1.8.12 (Windows 8.1), Board: "WeMos D1 R1, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS: 2MB OTA: ~ 1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 921600 "

In file included from C: \ Users \ wilson \ Documents \ Arduino \ sketch_mar23g \ sketch_mar23g.ino: 1: 0:

C: \ Users \ wilson \ Documents \ Arduino \ libraries \ WebSockets_2.2.0_549 \ src / SocketIOclient.h: 38: 51: error: expected class-name before '{' token

class SocketIOclient: protected WebSocketsClient {

                                               ^

More than one library found for "SocketIOclient.h" Used: C: \ Users \ wilson \ Documents \ Arduino \ libraries \ WebSockets_2.2.0_549 Not used: C: \ Users \ wilson \ Documents \ Arduino \ libraries \ arduinoWebSockets-2.1.4 exit status 1 Error during compilation for the WeMos D1 R1 card.

This report may be richer in information by enabling the option "Show detailed output during compilation" in "File -> Settings

sivar2311 commented 4 years ago

More than one library found for "SocketIOclient.h"

Uninstall all websockets library and reinstall just one

antoniomorsello commented 4 years ago

good evening, I uninstalled all the websockets libraries, downloaded the Markus Sattler library, I zipped it and added it to the library and it gives me this error message: Arduino: 1.8.12 (Windows 8.1), Board: "WeMos D1 R1, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS: 2MB OTA: ~ 1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 921600 "

In file included from C: \ Users \ wilson \ Documents \ Arduino \ sketch_mar23f \ sketch_mar23f.ino: 36: 0:

C: \ Users \ wilson \ Documents \ Arduino \ libraries \ SinricPro \ src / SinricPro.h: 13: 32: fatal error: SinricProWebsocket.h: No such file or directory

include "SinricProWebsocket.h"

                            ^

compilation terminated.

exit status 1 Error during compilation for the WeMos D1 R1 card. Invalid library found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ ArduinoWebsockets: No header file (.h) found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ ArduinoWebsockets \ src Invalid library found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ arduinoWebSockets-2.1.4: No header file (.h) found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ arduinoWebSockets-2.1. 4 \ src Invalid library found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ ArduinoWebsockets: No header file (.h) found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ ArduinoWebsockets \ src Invalid library found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ arduinoWebSockets-2.1.4: No header file (.h) found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ arduinoWebSockets-2.1. 4 \ src

This report may be richer in information by enabling the option "Show detailed output during compilation" in "File -> Settings

sivar2311 commented 4 years ago

Please share your code for analyzing

antoniomorsello commented 4 years ago

Arduino: 1.8.12 (Windows 8.1), Board: "WeMos D1 R1, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS: 2MB OTA: ~ 1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 921600 "

In file included from C: \ Users \ wilson \ Documents \ Arduino \ sketch_mar23f \ sketch_mar23f.ino: 36: 0:

C: \ Users \ wilson \ Documents \ Arduino \ libraries \ SinricPro \ src / SinricPro.h: 13: 32: fatal error: SinricProWebsocket.h: No such file or directory

include "SinricProWebsocket.h"

                            ^

compilation terminated.

exit status 1 Error during compilation for the WeMos D1 R1 card. Invalid library found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ ArduinoWebsockets: No header file (.h) found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ ArduinoWebsockets \ src Invalid library found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ arduinoWebSockets-2.1.4: No header file (.h) found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ arduinoWebSockets-2.1. 4 \ src Invalid library found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ ArduinoWebsockets: No header file (.h) found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ ArduinoWebsockets \ src Invalid library found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ arduinoWebSockets-2.1.4: No header file (.h) found in C: \ Users \ wilson \ Documents \ Arduino \ libraries \ arduinoWebSockets-2.1. 4 \ src

This report may be richer in information by enabling the option "Show detailed output during compilation" in "File -> Settings

sivar2311 commented 4 years ago

Again: Please upload your code, for analyze.

antoniomorsello commented 4 years ago

Sivar2311, thank you for your time and your patience, I have uninstalled everything and reinstalled the bookcases and now it's ok, I can't wait to try.