Currently, I am working on an IoT project that combines Arduino with ModuleSIM7600 to transmit data to the web via WebSocket.
But when using the library
ArduinoWebSockets, a library error occurs that the string library cannot be found in the file ws_common.hpp or memory
in the websockets_endpoint.hpp file. Error as below. I hope everyone can help me soon.
n file included from C:\Users\Kythu\Documents\Arduino\libraries\ArduinoWebsockets\src/tiny_websockets/message.hpp:3:0,
from C:\Users\Kythu\Documents\Arduino\libraries\ArduinoWebsockets\src/ArduinoWebsockets.h:4,
from C:\Users\Kythu\Documents\Arduino\Project\Project.ino:1:
C:\Users\Kythu\Documents\Arduino\libraries\ArduinoWebsockets\src/tiny_websockets/internals/ws_common.hpp:4:10: fatal error: string: No such file or directory #include
^~~~~~~~
compilation terminated.
In my novice eyes, it is strange to see Windows "backslash" mixed with Linux "solidus/slash" in the same command line. Not that this comment brings resolution...
#include "ArduinoWebsockets.h"
#include <WebSockets.h>
#include <WebSocketsClient.h>
#include <WebSocketsServer.h>
WebSocketsClient webSocket;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); // Khởi tạo kết nối Serial để truyền dữ liệu đến máy tính
connectWebSocket();
startInternet();
}
void loop() {
// put your main code here, to run repeatedly:
webSocket.loop();
}
void connectWebSocket() {
webSocket.begin("", 80, "/"); // Địa chỉ websocket server, port và URL
webSocket.onEvent(webSocketEvent);
// webSocket.setAuthorization("user", "password"); // Sử dụng thông tin chứng thực nếu cần
webSocket.setReconnectInterval(5000); // Thử lại sau 5s nếu kết nối không thành công
}
void startInternet() { // Kết nối vào mạng Internet
}
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
switch (type) {
case WStype_DISCONNECTED: // Sự kiện khi client ngắt kết nối
Serial.printf("[WSc] Disconnected!\n");
connectWebSocket();
break;
case WStype_CONNECTED: // Sự kiện khi client kết nối
Serial.printf("[WSc] Connected to url: %s\n", payload);
webSocket.sendTXT("Connected"); // Thông báo kết nối thành công
break;
case WStype_TEXT: // Sự kiện khi nhận được thông điệp dạng TEXT
Serial.printf("[WSc] get text: %s\n", payload);
webSocket.sendTXT("Hi Server!"); // Gởi thông điệp đến server
break;
//case WStype_BIN: // Sự kiện khi nhận được thông điệp dạng BINARY
// Serial.printf("[WSc] get binary length: %u\n", length);
// hexdump(payload, length);
// // webSocket.sendBIN(payload, length);
// break;
}
}
i taked ArduinoWebsokets.h in Arduino IDE ( Sketch > Include Librari > Manage libraries > ArduinoWebSockets ( by GilMaimon version 0.5.3)
now when i changed to < string.h> in file ws_common.hpp and to <memory.h> in file websockets_endpoint.hpp , the problem is still not resolved and i get the following output.
In file included from C:\Users\Kythu\Documents\Arduino\libraries\ArduinoWebsockets\src/tiny_websockets/client.hpp:6:0,
from C:\Users\Kythu\Documents\Arduino\libraries\ArduinoWebsockets\src/ArduinoWebsockets.h:5,
from C:\Users\Kythu\Documents\Arduino\Project\Project.ino:1:
C:\Users\Kythu\Documents\Arduino\libraries\ArduinoWebsockets\src/tiny_websockets/internals/websockets_endpoint.hpp:7:10: fatal error: memory.h: No such file or directory #include <memory.h>
^~~~~~~~~~
compilation terminated.