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
231 stars 124 forks source link

Error while creating web server #180

Closed smartswitchsio closed 3 years ago

smartswitchsio commented 3 years ago

I try to create a web server from the example sketch (MultiSwitch_beginner.ino), i just added the header file #include . how to create a web server?

Getting below errors.

In file included from C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricPro.h:15:0, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:34: C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h: In function 'String HMACbase64(const String&, const String&)': C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:45:3: error: 'base64_encodestate' was not declared in this scope base64_encodestate _state; ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:45:3: note: suggested alternative: In file included from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:24:0, from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer.h:259, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:28: C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/libb64/cencode.h:31:3: note: 'esp8266webserver::base64_encodestate' } base64_encodestate; ^ In file included from C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricPro.h:15:0, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:34: C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:45:22: error: expected ';' before '_state' base64_encodestate _state; ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:46:28: error: '_state' was not declared in this scope base64_init_encodestate(&_state); ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:46:34: error: 'base64_init_encodestate' was not declared in this scope base64_init_encodestate(&_state); ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:46:34: note: suggested alternative: In file included from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:24:0, from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer.h:259, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:28: C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/libb64/cencode.h:33:6: note: 'esp8266webserver::base64_init_encodestate' void base64_init_encodestate(base64_encodestate state_in); ^ In file included from C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricPro.h:15:0, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:34: C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:51:89: error: 'base64_encode_block' was not declared in this scope int len = base64_encode_block((const char )hmacResult, 32, base64encodedHMAC, &_state); ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:51:89: note: suggested alternative: In file included from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:24:0, from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer.h:259, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:28: C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/libb64/cencode.h:38:5: note: 'esp8266webserver::base64_encode_block' int base64_encode_block(const char plaintext_in, int length_in, char code_out, base64_encodestate state_in); ^ In file included from C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricPro.h:15:0, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:34: C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:52:60: error: 'base64_encode_blockend' was not declared in this scope base64_encode_blockend((base64encodedHMAC + len), &_state); ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:52:60: note: suggested alternative: In file included from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:24:0, from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer.h:259, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:28: C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/libb64/cencode.h:40:5: note: 'esp8266webserver::base64_encode_blockend' int base64_encode_blockend(char code_out, base64_encodestate* state_in); ^ Multiple libraries were found for "Hash.h" Used: C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\Hash Not used: C:\Users\Education\Documents\Arduino\libraries\ElectronicDIYsOTA Not used: C:\Users\Education\Documents\Arduino\libraries\AsyncElegantOTA exit status 1 Error compiling for board NodeMCU 1.0 (ESP-12E Module).

kakopappa commented 3 years ago

Multiple libraries were found for "Hash.h" Used: C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\Hash Not used: C:\Users\Education\Documents\Arduino\libraries\ElectronicDIYsOTA Not used: C:\Users\Education\Documents\Arduino\libraries\AsyncElegantOTA exit status 1 Error compiling for board NodeMCU 1.0 (ESP-12E Module). Any idea why does it link AsyncElegantOTA? You should try removing it

On Wed, 21 Apr 2021 at 7:54 PM Rajasekar @.***> wrote:

I try to create a web server from the example sketch (MultiSwitch_beginner.ino), i just added the header file #include

. getting below error. how to create a web server? In file included from C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricPro.h:15:0, from C:\Users\EDUCAT 1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:34: C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h: In function 'String HMACbase64(const String&, const String&)': C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:45:3: error: 'base64_encodestate' was not declared in this scope base64_encodestate _state; ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:45:3: note: suggested alternative: In file included from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:24:0, from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer.h:259, from C:\Users\EDUCAT 1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:28: C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/libb64/cencode.h:31:3: note: 'esp8266webserver::base64_encodestate' } base64_encodestate; ^ In file included from C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricPro.h:15:0, from C:\Users\EDUCAT 1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:34: C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:45:22: error: expected ';' before '_state' base64_encodestate _state; ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:46:28: error: '_state' was not declared in this scope base64_init_encodestate(&_state); ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:46:34: error: 'base64_init_encodestate' was not declared in this scope base64_init_encodestate(&_state); ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:46:34: note: suggested alternative: In file included from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:24:0, from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer.h:259, from C:\Users\EDUCAT 1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:28: C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/libb64/cencode.h:33:6: note: 'esp8266webserver::base64_init_encodestate' void base64_init_encodestate(base64_encodestate* state_in); ^ In file included from C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricPro.h:15:0, from C:\Users\EDUCAT 1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:34: C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:51:89: error: 'base64_encode_block' was not declared in this scope int len = base64_encode_block((const char *)hmacResult, 32, base64encodedHMAC, &_state); ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:51:89: note: suggested alternative: In file included from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:24:0, from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer.h:259, from C:\Users\EDUCAT 1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:28: C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/libb64/cencode.h:38:5: note: 'esp8266webserver::base64_encode_block' int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in); ^ In file included from C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricPro.h:15:0, from C:\Users\EDUCAT 1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:34: C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:52:60: error: 'base64_encode_blockend' was not declared in this scope base64_encode_blockend((base64encodedHMAC + len), &_state); ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:52:60: note: suggested alternative: In file included from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:24:0, from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer.h:259, from C:\Users\EDUCAT 1\AppData\Local\Temp\arduino_modified_sketch_718966\MultiSwitch_beginner.ino:28: C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/libb64/cencode.h:40:5: note: 'esp8266webserver::base64_encode_blockend' int base64_encode_blockend(char* code_out, base64_encodestate* state_in); ^ Multiple libraries were found for "Hash.h" Used: C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\Hash Not used: C:\Users\Education\Documents\Arduino\libraries\ElectronicDIYsOTA Not used: C:\Users\Education\Documents\Arduino\libraries\AsyncElegantOTA exit status 1 Error compiling for board NodeMCU 1.0 (ESP-12E Module). — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or unsubscribe .
smartswitchsio commented 3 years ago

After removed AsyncElegantOTA, below error

In file included from C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricPro.h:15:0, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_34367\MultiSwitch_beginner.ino:34: C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h: In function 'String HMACbase64(const String&, const String&)': C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:45:3: error: 'base64_encodestate' was not declared in this scope base64_encodestate _state; ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:45:3: note: suggested alternative: In file included from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:24:0, from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer.h:259, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_34367\MultiSwitch_beginner.ino:28: C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/libb64/cencode.h:31:3: note: 'esp8266webserver::base64_encodestate' } base64_encodestate; ^ In file included from C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricPro.h:15:0, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_34367\MultiSwitch_beginner.ino:34: C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:45:22: error: expected ';' before '_state' base64_encodestate _state; ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:46:28: error: '_state' was not declared in this scope base64_init_encodestate(&_state); ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:46:34: error: 'base64_init_encodestate' was not declared in this scope base64_init_encodestate(&_state); ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:46:34: note: suggested alternative: In file included from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:24:0, from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer.h:259, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_34367\MultiSwitch_beginner.ino:28: C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/libb64/cencode.h:33:6: note: 'esp8266webserver::base64_init_encodestate' void base64_init_encodestate(base64_encodestate state_in); ^ In file included from C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricPro.h:15:0, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_34367\MultiSwitch_beginner.ino:34: C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:51:89: error: 'base64_encode_block' was not declared in this scope int len = base64_encode_block((const char )hmacResult, 32, base64encodedHMAC, &_state); ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:51:89: note: suggested alternative: In file included from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:24:0, from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer.h:259, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_34367\MultiSwitch_beginner.ino:28: C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/libb64/cencode.h:38:5: note: 'esp8266webserver::base64_encode_block' int base64_encode_block(const char plaintext_in, int length_in, char code_out, base64_encodestate state_in); ^ In file included from C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricPro.h:15:0, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_34367\MultiSwitch_beginner.ino:34: C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:52:60: error: 'base64_encode_blockend' was not declared in this scope base64_encode_blockend((base64encodedHMAC + len), &_state); ^ C:\Users\Education\Documents\Arduino\libraries\esp8266-esp32-sdk\src/SinricProSignature.h:52:60: note: suggested alternative: In file included from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:24:0, from C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer.h:259, from C:\Users\EDUCAT~1\AppData\Local\Temp\arduino_modified_sketch_34367\MultiSwitch_beginner.ino:28: C:\Users\Education\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/libb64/cencode.h:40:5: note: 'esp8266webserver::base64_encode_blockend' int base64_encode_blockend(char code_out, base64_encodestate* state_in); ^ exit status 1 Error compiling for board NodeMCU 1.0 (ESP-12E Module).

kakopappa commented 3 years ago

include "SinricPro.h"

include "SinricProSwitch.h"

include // Should be below Sinric pro definitions

image

sivar2311 commented 3 years ago

After some hours of investigation it was found that if ESP8266WebServer.h is included, libb64/cencode.h cannot be used anymore. This error is not related to SinricPro and is caused by ESP8266WebServer.h or libb64/cencode.h.

I have released a new version of SinricPro 2.9.4 which bypasses this error. The new version should be available in a few hours via the Arduino Libraries Manager.

Update to version 2.9.4, then the order of the include does not matter anymore and the error will not occur.

stale[bot] commented 3 years ago

This issue has gone quiet. Spooky quiet. We currently close issues after 14 days of inactivity. It’s been at least 7 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder, the best way to fix this or any other problem is to provide a detailed error description including a serial log. Thanks for being a part of the SinricPro community!

smartswitchsio commented 3 years ago

If i use ESPAsyncWebServer with websocket the webpage not loading from spiffs even small file.

sivar2311 commented 3 years ago

I use ESPAsyncWebSErver & SinricPro in my sketch without any issues. So you must be doing something wrong.

Do you know exactly that this issue is caused by SinricPro-Library? Did you test without SinricPro?

sivar2311 commented 3 years ago

Btw now you're back on ESPAsyncWebServer, not ESP8266WebServer ??

smartswitchsio commented 3 years ago

Without websocket is working fine, if i use websocket server then have a issue with loading page

sivar2311 commented 3 years ago

Sorry, but this doesnt make sense. Do you have a problem using SinricPro or do you have a problem using WebSocket??

smartswitchsio commented 3 years ago

i don't have problem with websockets , working fine. if i add a SinricPro then only i have problem because two different web socket working at same time in the background , so that i request you to give basic sketch (switch on off)completely with Asyn websocket (ESPAsyncWebServer).

sivar2311 commented 3 years ago

SinricPro does not run a websocket server... only a client. Sould no problem to run a server...

I don't have a "basic sketch" running a websocket server.

What exactly is the problem with your websocket server? Which websocket server do you use?

sivar2311 commented 3 years ago

Use the following "basic sketch" and please tell me finaly and detailed where the issue is!

// 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 <SinricProSwitch.h>
#include <ESPAsyncWebServer.h>

#define SSID        ""
#define PASS        ""

#define APP_KEY     ""
#define APP_SECRET  ""
#define DEVICE_ID   ""

/************************************
 * AsyncWebServer / AsyncWebSocket  *
 ************************************/ 

AsyncWebServer server(80);
AsyncWebSocket ws("/ws");

void onEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
  if(type == WS_EVT_CONNECT){
    //client connected
    Serial.printf("ws[%s][%u] connect\n", server->url(), client->id());
    client->printf("Hello Client %u :)", client->id());
    client->ping();
  } else if(type == WS_EVT_DISCONNECT){
    //client disconnected
    Serial.printf("ws[%s][%u] disconnect \r\n", server->url(), client->id());
  } else if(type == WS_EVT_ERROR){
    //error was received from the other end
    Serial.printf("ws[%s][%u] error(%u): %s\n", server->url(), client->id(), *((uint16_t*)arg), (char*)data);
  } else if(type == WS_EVT_PONG){
    //pong message was received (in response to a ping request maybe)
    Serial.printf("ws[%s][%u] pong[%u]: %s\n", server->url(), client->id(), len, (len)?(char*)data:"");
  } else if(type == WS_EVT_DATA){
    //data packet
    AwsFrameInfo * info = (AwsFrameInfo*)arg;
    if(info->final && info->index == 0 && info->len == len){
      //the whole message is in a single frame and we got all of it's data
      Serial.printf("ws[%s][%u] %s-message[%llu]: ", server->url(), client->id(), (info->opcode == WS_TEXT)?"text":"binary", info->len);
      if(info->opcode == WS_TEXT){
        data[len] = 0;
        Serial.printf("%s\n", (char*)data);
      } else {
        for(size_t i=0; i < info->len; i++){
          Serial.printf("%02x ", data[i]);
        }
        Serial.printf("\n");
      }
      if(info->opcode == WS_TEXT)
        client->text("I got your text message");
      else
        client->binary("I got your binary message");
    } else {
      //message is comprised of multiple frames or the frame is split into multiple packets
      if(info->index == 0){
        if(info->num == 0)
          Serial.printf("ws[%s][%u] %s-message start\n", server->url(), client->id(), (info->message_opcode == WS_TEXT)?"text":"binary");
        Serial.printf("ws[%s][%u] frame[%u] start[%llu]\n", server->url(), client->id(), info->num, info->len);
      }

      Serial.printf("ws[%s][%u] frame[%u] %s[%llu - %llu]: ", server->url(), client->id(), info->num, (info->message_opcode == WS_TEXT)?"text":"binary", info->index, info->index + len);
      if(info->message_opcode == WS_TEXT){
        data[len] = 0;
        Serial.printf("%s\n", (char*)data);
      } else {
        for(size_t i=0; i < len; i++){
          Serial.printf("%02x ", data[i]);
        }
        Serial.printf("\n");
      }

      if((info->index + len) == info->len){
        Serial.printf("ws[%s][%u] frame[%u] end[%llu]\n", server->url(), client->id(), info->num, info->len);
        if(info->final){
          Serial.printf("ws[%s][%u] %s-message end\n", server->url(), client->id(), (info->message_opcode == WS_TEXT)?"text":"binary");
          if(info->message_opcode == WS_TEXT)
            client->text("I got your text message");
          else
            client->binary("I got your binary message");
        }
      }
    }
  }
}

/**************
 * SinricPro  *
 **************/

SinricProSwitch &mySwitch = SinricPro[DEVICE_ID];

bool onPowerState(const String &deviceId, bool &state) {
  Serial.printf("\"%s\" turned %s\r\n", deviceId.c_str(), state?"on":"off");
  return true;
}

/*********
 * setup *
 *********/ 

void setupSinricPro() {
  mySwitch.onPowerState(onPowerState);

  SinricPro.onConnected([] { Serial.printf("[SinricPro]: Connected\r\n"); });
  SinricPro.onDisconnected([] { Serial.printf("[SinricPro]: Disconnected\r\n"); });
  SinricPro.begin(APP_KEY, APP_SECRET);
};

void setupWiFi() {
  WiFi.begin(SSID, PASS);
  Serial.printf("[WiFi]: Connecting to %s", SSID);
  while (WiFi.status() != WL_CONNECTED)  {
    Serial.printf(".");
    delay(250);
  }
  Serial.printf("connected. IP is %s\r\n", WiFi.localIP().toString().c_str());
}

void setupServer() {
  ws.onEvent(onEvent);
  server.addHandler(&ws);
  server.begin();
}

void setup() {
  Serial.begin(115200);
  setupWiFi();
  setupServer();
  setupSinricPro();
}

/********
 * loop *
********/

void loop() {
  SinricPro.handle();
}
sivar2311 commented 3 years ago

Serving a 582kB JPEG Image from LittleFS takes on my ESP8266 between 1.9 and 2.15 seconds. This was measured with the sketch from above running

The sketch was extended by these three lines:

#include <LittleFS.h>

in setupServer():

  server.serveStatic("/", LittleFS, "/www/");

in setup():

  LittleFS.begin();

Measurements: image image image image

Awaiting your response....

sivar2311 commented 3 years ago

@smartswitchsio I got an email notification that you have written a new comment... but i cannot see it ?!

smartswitchsio commented 3 years ago

without this library webpage is working fine with any JavaScript/ jquery but with this library jquery.min.js or any JavaScript pages not loading.

  1. Without any JavaScript/ jquery the page is loading good with this library . see the below picture image

  2. I just added a jquery.min.js without any JavaScript page not loading with this library see the below picture image

sivar2311 commented 3 years ago

hm... different files shown in the screenshot. Your jQuery.min.js is only 97 bytes and you have a server error (HTTP response 500!) I guess the delay comes from this.

I use the same technique (serving jQuery.min.js from spiffs) and i dont have the issues you have. SinricProSDK is not related to a running webserver or servring files from spiffs.

I don't think the issue comes from SinricPro library. Do you have the same issues running my sketch from above? (Put a huge jpg image on spiffs... and try to load...)

smartswitchsio commented 3 years ago

//1. Added without Jquery only the below code also page not loading with this library

var gateway = ws://${window.location.hostname}/ws; var websocket;

// ---------------------------------------------------------------------------- // Initialization // ----------------------------------------------------------------------------

window.addEventListener('load', onLoad);

function onLoad(event) { initWebSocket(); //initButton(); }

// ---------------------------------------------------------------------------- // WebSocket handling // ----------------------------------------------------------------------------

function initWebSocket() { console.log('Trying to open a WebSocket connection...'); websocket = new WebSocket(gateway); websocket.onopen = onOpen; websocket.onclose = onClose; websocket.onmessage = onMessage; }

function onOpen(event) { console.log('Connection opened'); }

function onClose(event) { console.log('Connection closed'); setTimeout(initWebSocket, 2000); }

function onMessage(event) { console.log(event);

}

sivar2311 commented 3 years ago

?? JS code ??

I guess your issues come from something else, but i cannot analyze your JS scripts...

So, please perform a simple test as i recommended in my last comment.

sivar2311 commented 3 years ago

image Here are my results from a different project running AsyncWebServer + SinricPro + other stuff i cannot share here on a ESP32

smartswitchsio commented 3 years ago

image Here are my results from a different project running AsyncWebServer + SinricPro + other stuff i cannot share here on a ESP32

Kindly share the code to my email id if you ok . smartswitchsio@gmail.com or pls give some example

sivar2311 commented 3 years ago

Sorry, this is a commercial project. i cannot share this code... but my example from above should be fine for you.

smartswitchsio commented 3 years ago

websocket working but jquery getting error if i use with this library without this library loading good image

sivar2311 commented 3 years ago

did you made the test with my example (+ the 3 additional lines) ?

as written before : i dont have the issue.

smartswitchsio commented 3 years ago

See the below code added webserver only ` // 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

include

endif

ifdef ESP32

include

endif

include

include

include

define SSID ""

define PASS ""

define APP_KEY ""

define APP_SECRET ""

define DEVICE_ID ""

/****

AsyncWebServer server(80); AsyncWebSocket ws("/ws");

void onEvent(AsyncWebSocket server, AsyncWebSocketClient client, AwsEventType type, void arg, uint8_t data, size_t len){ if(type == WS_EVT_CONNECT){ //client connected Serial.printf("ws[%s][%u] connect\n", server->url(), client->id()); client->printf("Hello Client %u :)", client->id()); client->ping(); } else if(type == WS_EVT_DISCONNECT){ //client disconnected Serial.printf("ws[%s][%u] disconnect \r\n", server->url(), client->id()); } else if(type == WS_EVT_ERROR){ //error was received from the other end Serial.printf("ws[%s][%u] error(%u): %s\n", server->url(), client->id(), ((uint16_t)arg), (char)data); } else if(type == WS_EVT_PONG){ //pong message was received (in response to a ping request maybe) Serial.printf("ws[%s][%u] pong[%u]: %s\n", server->url(), client->id(), len, (len)?(char)data:""); } else if(type == WS_EVT_DATA){ //data packet AwsFrameInfo info = (AwsFrameInfo)arg; if(info->final && info->index == 0 && info->len == len){ //the whole message is in a single frame and we got all of it's data Serial.printf("ws[%s][%u] %s-message[%llu]: ", server->url(), client->id(), (info->opcode == WS_TEXT)?"text":"binary", info->len); if(info->opcode == WS_TEXT){ data[len] = 0; Serial.printf("%s\n", (char*)data); } else { for(size_t i=0; i < info->len; i++){ Serial.printf("%02x ", data[i]); } Serial.printf("\n"); } if(info->opcode == WS_TEXT) client->text("I got your text message"); else client->binary("I got your binary message"); } else { //message is comprised of multiple frames or the frame is split into multiple packets if(info->index == 0){ if(info->num == 0) Serial.printf("ws[%s][%u] %s-message start\n", server->url(), client->id(), (info->message_opcode == WS_TEXT)?"text":"binary"); Serial.printf("ws[%s][%u] frame[%u] start[%llu]\n", server->url(), client->id(), info->num, info->len); }

  Serial.printf("ws[%s][%u] frame[%u] %s[%llu - %llu]: ", server->url(), client->id(), info->num, (info->message_opcode == WS_TEXT)?"text":"binary", info->index, info->index + len);
  if(info->message_opcode == WS_TEXT){
    data[len] = 0;
    Serial.printf("%s\n", (char*)data);
  } else {
    for(size_t i=0; i < len; i++){
      Serial.printf("%02x ", data[i]);
    }
    Serial.printf("\n");
  }

  if((info->index + len) == info->len){
    Serial.printf("ws[%s][%u] frame[%u] end[%llu]\n", server->url(), client->id(), info->num, info->len);
    if(info->final){
      Serial.printf("ws[%s][%u] %s-message end\n", server->url(), client->id(), (info->message_opcode == WS_TEXT)?"text":"binary");
      if(info->message_opcode == WS_TEXT)
        client->text("I got your text message");
      else
        client->binary("I got your binary message");
    }
  }
}

} } /**

SinricProSwitch &mySwitch = SinricPro[DEVICE_ID];

bool onPowerState(const String &deviceId, bool &state) { Serial.printf("\"%s\" turned %s\r\n", deviceId.c_str(), state?"on":"off"); return true; } /*****

void setupSinricPro() { mySwitch.onPowerState(onPowerState);

SinricPro.onConnected([] { Serial.printf("[SinricPro]: Connected\r\n"); }); SinricPro.onDisconnected([] { Serial.printf("[SinricPro]: Disconnected\r\n"); }); SinricPro.begin(APP_KEY, APP_SECRET); };

void setupWiFi() { WiFi.begin(SSID, PASS); Serial.printf("[WiFi]: Connecting to %s", SSID); while (WiFi.status() != WL_CONNECTED) { Serial.printf("."); delay(250); } Serial.printf("connected. IP is %s\r\n", WiFi.localIP().toString().c_str()); }

void setupServer() { ws.onEvent(onEvent); server.addHandler(&ws); //server.begin(); }

// ---------------------------------------------------------------------------- // Web server initialization // ----------------------------------------------------------------------------

/*String processor(const String &var) { return String(var == "STATE" && led0.on ? "on" : "off"); }

void onRootRequest(AsyncWebServerRequest request) { request->send(SPIFFS, "/index.html", "text/html", false); }/

void initWebServer() {

server.on("/", HTTP_ANY, [](AsyncWebServerRequest *request){
request->send(SPIFFS, "/index.html");

}); server.begin(); }

void setup() { Serial.begin(115200); SPIFFS.begin(); setupWiFi(); setupServer(); setupSinricPro(); initWebServer(); }

/****

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

smartswitchsio commented 3 years ago

//1. Added without Jquery only the below code also page not loading with this library

var gateway = ws://${window.location.hostname}/ws; var websocket;

// ---------------------------------------------------------------------------- // Initialization // ----------------------------------------------------------------------------

window.addEventListener('load', onLoad);

function onLoad(event) { initWebSocket(); //initButton(); }

// ---------------------------------------------------------------------------- // WebSocket handling // ----------------------------------------------------------------------------

function initWebSocket() { console.log('Trying to open a WebSocket connection...'); websocket = new WebSocket(gateway); websocket.onopen = onOpen; websocket.onclose = onClose; websocket.onmessage = onMessage; }

function onOpen(event) { console.log('Connection opened'); }

function onClose(event) { console.log('Connection closed'); setTimeout(initWebSocket, 2000); }

function onMessage(event) { console.log(event);

}

is there is any issue with this code because if i use only this code also getting error with sinricpro library

smartswitchsio commented 3 years ago

//1. Added without Jquery only the below code also page not loading with this library var gateway = ws://${window.location.hostname}/ws; var websocket; // ---------------------------------------------------------------------------- // Initialization // ---------------------------------------------------------------------------- window.addEventListener('load', onLoad); function onLoad(event) { initWebSocket(); //initButton(); } // ---------------------------------------------------------------------------- // WebSocket handling // ---------------------------------------------------------------------------- function initWebSocket() { console.log('Trying to open a WebSocket connection...'); websocket = new WebSocket(gateway); websocket.onopen = onOpen; websocket.onclose = onClose; websocket.onmessage = onMessage; } function onOpen(event) { console.log('Connection opened'); } function onClose(event) { console.log('Connection closed'); setTimeout(initWebSocket, 2000); } function onMessage(event) { console.log(event); }

is there is any issue with this code because if i use only this code also getting error with sinricpro library

This code is loading jquery not loading

smartswitchsio commented 3 years ago

what version jquery are you using iam using 3.6 page not loading if jquery loaded also

sivar2311 commented 3 years ago

I am not on my pc right now, but what i can see: Yes there is! Your code only serves index.html from Spiffs. Use serveStatic!!

sivar2311 commented 3 years ago

jQuery version is irrelevant here. but for your info: i downloaded the latest version a few days ago.

the issue is in your server setup. use serveStatic, use my example from above...

smartswitchsio commented 3 years ago

I am not on my pc right now, but what i can see: Yes there is! Your code only serves index.html from Spiffs. Use serveStatic!!

i serve separately also not page loading

sivar2311 commented 3 years ago

the issue you have is not related to sinric pro library. i can give you only same advices again and again and again. use the code i provided.

smartswitchsio commented 3 years ago

Thanks for you support, I will try again.