Arduino + websocket + socketIo

  arduino, arduino-uno, c++, websocket

Actually I have created a node server for storing data, and i want to implement web socket connection from nodemcu to node.js server.

For that I’m using SocketIoClient library, following is the code:

#include <Arduino.h>

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

#include <SocketIoClient.h>

#define USE_SERIAL Serial

ESP8266WiFiMulti WiFiMulti;
SocketIoClient webSocket;

void event(const char * payload, size_t length) {
  USE_SERIAL.printf("got message: %sn", payload);
}

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

    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");

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

    webSocket.on("event", event);
    webSocket.begin("my.socket-io.server");
    // use HTTP Basic Authorization this is optional remove if not needed
    webSocket.setAuthorization("username", "password");
}

void loop() {
    webSocket.loop();
}

while compiling this code, I’m getting the following error:

Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: "NodeMCU 0.9 (ESP-12 Module), 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, 115200"




C:UsersOneDriveDocumentsArduinolibrariesSocketIoClientSocketIoClient.cpp: In member function 'void SocketIoClient::beginSSL(const char*, int, const char*, const char*)':

C:UsersOneDriveDocumentsArduinolibrariesSocketIoClientSocketIoClient.cpp:47:50: error: invalid conversion from 'const char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]

  _webSocket.beginSSL(host, port, url, fingerprint);

                                                  ^

In file included from C:UsersOneDriveDocumentsArduinolibrariesSocketIoClient/SocketIoClient.h:7:0,

                 from C:UsersOneDriveDocumentsArduinolibrariesSocketIoClientSocketIoClient.cpp:1:

C:UsersOneDriveDocumentsArduinolibrariesWebSocketssrc/WebSocketsClient.h:50:10: error:   initializing argument 4 of 'void WebSocketsClient::beginSSL(const char*, uint16_t, const char*, const uint8_t*, const char*)' [-fpermissive]

     void beginSSL(const char * host, uint16_t port, const char * url = "/", const uint8_t * fingerprint = NULL, const char * protocol = "arduino");

          ^

exit status 1

Error compiling for board NodeMCU 0.9 (ESP-12 Module).


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Source: Windows Questions C++

LEAVE A COMMENT