Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSockets.cpp:485:77: error: 'sha1' was not declared in this scope #266

Closed
ghost opened this issue Dec 20, 2017 · 10 comments
Closed

WebSockets.cpp:485:77: error: 'sha1' was not declared in this scope #266

ghost opened this issue Dec 20, 2017 · 10 comments

Comments

@ghost
Copy link

ghost commented Dec 20, 2017

Hello, I am using one of your examples to test and I got a compilation error "WebSockets.cpp:485:77: error: 'sha1' was not declared in this scope". How can I fix it?

/*
 * WebSocketClientSocketIO.ino
 *
 *  Created on: 06.06.2016
 *
 */

#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <WebSocketsClient.h>

#include <Hash.h>

ESP8266WiFiMulti WiFiMulti;
WebSocketsClient webSocket;


#define USE_SERIAL Serial1

#define MESSAGE_INTERVAL 30000
#define HEARTBEAT_INTERVAL 25000

uint64_t messageTimestamp = 0;
uint64_t heartbeatTimestamp = 0;
bool isConnected = false;

void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {


    switch(type) {
        case WStype_DISCONNECTED:
            USE_SERIAL.printf("[WSc] Disconnected!\n");
            isConnected = false;
            break;
        case WStype_CONNECTED:
            {
                USE_SERIAL.printf("[WSc] Connected to url: %s\n",  payload);
                isConnected = true;

			    // send message to server when Connected
                // socket.io upgrade confirmation message (required)
				webSocket.sendTXT("5");
            }
            break;
        case WStype_TEXT:
            USE_SERIAL.printf("[WSc] get text: %s\n", payload);

			// send message to server
			// webSocket.sendTXT("message here");
            break;
        case WStype_BIN:
            USE_SERIAL.printf("[WSc] get binary length: %u\n", length);
            hexdump(payload, length);

            // send data to server
            // webSocket.sendBIN(payload, length);
            break;
    }

}

void setup() {
    // USE_SERIAL.begin(921600);
    USE_SERIAL.begin(115200);

    //Serial.setDebugOutput(true);
    USE_SERIAL.setDebugOutput(true);

    USE_SERIAL.println();
    USE_SERIAL.println();
    USE_SERIAL.println();

      for(uint8_t t = 4; t > 0; t--) {
          USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t);
          USE_SERIAL.flush();
          delay(1000);
      }

    WiFiMulti.addAP("SSID", "passpasspass");

    //WiFi.disconnect();
    while(WiFiMulti.run() != WL_CONNECTED) {
        delay(100);
    }

    webSocket.beginSocketIO("192.168.0.123", 81);
    //webSocket.setAuthorization("user", "Password"); // HTTP Basic Authorization
    webSocket.onEvent(webSocketEvent);

}

void loop() {
    webSocket.loop();

    if(isConnected) {

        uint64_t now = millis();

        if(now - messageTimestamp > MESSAGE_INTERVAL) {
            messageTimestamp = now;
            // example socket.io message with type "messageType" and JSON payload
            webSocket.sendTXT("42[\"messageType\",{\"greeting\":\"hello\"}]");
        }
        if((now - heartbeatTimestamp) > HEARTBEAT_INTERVAL) {
            heartbeatTimestamp = now;
            // socket.io heartbeat message
            webSocket.sendTXT("2");
        }
    }
}
@Links2004
Copy link
Owner

Hi,

is the problem still pressend?
if yes feel free to reopen.

which board / µ do you use?
which version of the lib?

@marciopamplona
Copy link

Same problem here!
ESP8266
lib version: 1.1.1

@Xenoman
Copy link

Xenoman commented Aug 22, 2018

Hi there!
I found a workaround for this problem.
In the crypto pachage the sha1 deprecated/removed. You can use the legacy one, like:
lib_deps = ...
https://github.com/me-no-dev/ESPAsyncWebServer.git
CryptoLegacy
...

@Kunsi
Copy link

Kunsi commented Dec 5, 2021

Apparently, this issue still occurs. Also, it seems the CryptoLegacy library is no longer available, so the mentioned workaround doesn't work anymore.

Am i missing something, or is this just broken?

@Links2004
Copy link
Owner

Is it possible to get details on how to reproduce this?

the CI building with the Arduino IDE and latest dev ESP8266 and ESP32 core are working.
my local builds with latest releases of the ESP8266 and ESP32 core and platform IO are ok too.

looks like there is some other factor at play,
but with out more details its hard to say where the problem is Incoming from.

@Links2004
Copy link
Owner

sha1 is part of the "Hash" lib in the ESP8266 which is still there in the latest master:
https://github.com/esp8266/Arduino/blob/master/libraries/Hash/src/Hash.cpp

@Kunsi
Copy link

Kunsi commented Dec 9, 2021

@Links2004 I'm using this code: https://git.franzi.business/kunsi/obs-websocket-tally/src/branch/main/src/main.cpp - works fine if you don't use OBS_PASS, but it won't compile when it's set.

Compiling .pio/build/default/lib20e/WebSockets/WebSocketsServer.cpp.o
.pio/libdeps/default/WebSockets/src/WebSockets.cpp: In member function 'String WebSockets::acceptKey(String&)':
.pio/libdeps/default/WebSockets/src/WebSockets.cpp:544:77: error: 'sha1' was not declared in this scope
     sha1(clientKey + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", &sha1HashBin[0]);
                                                                             ^
Compiling .pio/build/default/lib20e/WebSockets/libb64/cdecode.c.o
*** [.pio/build/default/lib20e/WebSockets/WebSockets.cpp.o] Error 1

@Links2004
Copy link
Owner

Links2004 commented Dec 12, 2021

ok in your case it the fault of the rweather/Crypto lib which breaks the ESP8266 build in Hash library.
there is nothing I can do to fix this in my lib.
this comes form the fact that the rweather/Crypto has a Hash.h too.
and PlatformIO selects the Hash.h from rweather/Crypto and not the ESP8266 build in one.

this can be seen at the beging of the build.
wrong:

Dependency Graph
|-- <ArduinoJson> 6.18.0
|-- <FastLED> 3.4.0
|-- <Base64> 1.0.0
|-- <WebSockets> 2.3.6
|   |-- <Crypto> 0.2.0
|   |-- <ESP8266WiFi> 1.0
|-- <Crypto> 0.2.0
|-- <ESP8266WiFi> 1.0

good:

Dependency Graph
|-- <ArduinoJson> 6.18.0
|-- <FastLED> 3.4.0
|-- <Base64> 1.0.0
|-- <WebSockets> 2.3.6
|   |-- <Hash> 1.0
|   |-- <ESP8266WiFi> 1.0
|-- <Hash> 1.0
|-- <ESP8266WiFi> 1.0

@Links2004
Copy link
Owner

with some changes to the code PlatformIO will do it correctly.

diff --git a/platformio.ini b/platformio.ini
index 8a53e25..72cfa7f 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -14,9 +14,10 @@ framework = arduino
 monitor_speed = 115200
 platform = espressif8266
 upload_protocol = esptool
+lib_ldf_mode = chain+
 lib_deps = 
        bblanchon/ArduinoJson@^6.17.3
        fastled/FastLED@^3.4.0
        agdl/Base64@^1.0.0
        links2004/WebSockets@^2.3.6
-       rweather/Crypto@^0.2.0
+       Hash
diff --git a/src/main.cpp b/src/main.cpp
index 5d87a78..f013565 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,7 +7,7 @@
 
 #define OBS_HOST ""
 #define OBS_PORT 4444
-//#define OBS_PASS ""
+#define OBS_PASS ""
 
 #define OBS_SOURCE "ATEM"
 
@@ -15,6 +15,7 @@
 
 // END CONFIGURATION
 
+#include <Arduino.h>
 #include <Hash.h>
 #include <ESP8266WiFi.h>
 #include <WebSocketsClient.h>

@Kunsi
Copy link

Kunsi commented Dec 12, 2021

You're correct, it works this way. Thank you for your help, even if it wasn't caused by your library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants