mirror of
https://github.com/Links2004/arduinoWebSockets.git
synced 2025-12-18 13:06:55 +01:00
Compare commits
1 Commits
2.7.0
...
printf_deb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83a87f7877 |
2
.github/workflows/arduino-lint.yaml
vendored
2
.github/workflows/arduino-lint.yaml
vendored
@@ -5,6 +5,6 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: arduino/arduino-lint-action@v2
|
- uses: arduino/arduino-lint-action@v1
|
||||||
with:
|
with:
|
||||||
library-manager: update
|
library-manager: update
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ a WebSocket Server and Client for Arduino based on RFC6455.
|
|||||||
### wss / SSL ###
|
### wss / SSL ###
|
||||||
supported for:
|
supported for:
|
||||||
- wss client on the ESP8266
|
- wss client on the ESP8266
|
||||||
- wss / SSL for ESP32 in client mode
|
|
||||||
- wss / SSL is not natively supported in WebSocketsServer however it is possible to achieve secure websockets
|
- wss / SSL is not natively supported in WebSocketsServer however it is possible to achieve secure websockets
|
||||||
by running the device behind an SSL proxy. See [Nginx](examples/Nginx/esp8266.ssl.reverse.proxy.conf) for a
|
by running the device behind an SSL proxy. See [Nginx](examples/Nginx/esp8266.ssl.reverse.proxy.conf) for a
|
||||||
sample Nginx server configuration file to enable this.
|
sample Nginx server configuration file to enable this.
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ void socketIOEvent(socketIOmessageType_t type, uint8_t * payload, size_t length)
|
|||||||
|
|
||||||
// Message Includes a ID for a ACK (callback)
|
// Message Includes a ID for a ACK (callback)
|
||||||
if(id) {
|
if(id) {
|
||||||
// create JSON message for Socket.IO (ack)
|
// creat JSON message for Socket.IO (ack)
|
||||||
DynamicJsonDocument docOut(1024);
|
DynamicJsonDocument docOut(1024);
|
||||||
JsonArray array = docOut.to<JsonArray>();
|
JsonArray array = docOut.to<JsonArray>();
|
||||||
|
|
||||||
@@ -130,11 +130,11 @@ void loop() {
|
|||||||
if(now - messageTimestamp > 2000) {
|
if(now - messageTimestamp > 2000) {
|
||||||
messageTimestamp = now;
|
messageTimestamp = now;
|
||||||
|
|
||||||
// create JSON message for Socket.IO (event)
|
// creat JSON message for Socket.IO (event)
|
||||||
DynamicJsonDocument doc(1024);
|
DynamicJsonDocument doc(1024);
|
||||||
JsonArray array = doc.to<JsonArray>();
|
JsonArray array = doc.to<JsonArray>();
|
||||||
|
|
||||||
// add event name
|
// add evnet name
|
||||||
// Hint: socket.on('event_name', ....
|
// Hint: socket.on('event_name', ....
|
||||||
array.add("event_name");
|
array.add("event_name");
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ void loop() {
|
|||||||
JsonObject param1 = array.createNestedObject();
|
JsonObject param1 = array.createNestedObject();
|
||||||
param1["now"] = (uint32_t) now;
|
param1["now"] = (uint32_t) now;
|
||||||
|
|
||||||
// JSON to String (serialization)
|
// JSON to String (serializion)
|
||||||
String output;
|
String output;
|
||||||
serializeJson(doc, output);
|
serializeJson(doc, output);
|
||||||
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
BasedOnStyle: Google
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
.pio
|
|
||||||
.vscode
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
; PlatformIO Project Configuration File
|
|
||||||
;
|
|
||||||
; Build options: build flags, source filter
|
|
||||||
; Upload options: custom upload port, speed and extra flags
|
|
||||||
; Library options: dependencies, extra library storages
|
|
||||||
; Advanced options: extra scripting
|
|
||||||
;
|
|
||||||
; Please visit documentation for the other options and examples
|
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
|
||||||
|
|
||||||
[env:esp32dev]
|
|
||||||
platform = espressif32@6.11.0
|
|
||||||
board = esp32dev
|
|
||||||
framework = arduino
|
|
||||||
monitor_speed = 115200
|
|
||||||
upload_speed = 921600
|
|
||||||
build_flags =
|
|
||||||
-DCORE_DEBUG_LEVEL=5
|
|
||||||
-D WEBSOCKETS_NETWORK_TYPE=10
|
|
||||||
-D TINY_GSM_MODEM_SIM7600
|
|
||||||
lib_deps =
|
|
||||||
digitaldragon/SSLClient@^1.3.2
|
|
||||||
vshymanskyy/StreamDebugger@^1.0.1
|
|
||||||
vshymanskyy/TinyGSM@^0.12.0
|
|
||||||
symlink://../../..
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
This example project shows how to use a custom NetworkClient class to switch between two underlying network interfaces.
|
|
||||||
|
|
||||||
In this case it shows how a board can support Wi-Fi as well as GSM/LTE connectivity. It uses a shim to switch between the two network interfaces, thereby allowing a single binary to handle both interfaces without needing to reboot. This example can be extended to cover other network interfaces that conform to the Client() class interface.
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
* main.cpp
|
|
||||||
*
|
|
||||||
* Created on: 15.06.2024
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include <WebSocketsClient.h>
|
|
||||||
#include <WiFiMulti.h>
|
|
||||||
|
|
||||||
#include "network_client_impl.h"
|
|
||||||
|
|
||||||
WiFiMulti wifiMulti;
|
|
||||||
WebSocketsClient webSocket;
|
|
||||||
|
|
||||||
#define USE_SERIAL Serial
|
|
||||||
|
|
||||||
void setClock() {
|
|
||||||
configTime(0, 0, "pool.ntp.org", "time.nist.gov");
|
|
||||||
|
|
||||||
USE_SERIAL.print(F("Waiting for NTP time sync: "));
|
|
||||||
time_t nowSecs = time(nullptr);
|
|
||||||
while (nowSecs < 8 * 3600 * 2) {
|
|
||||||
delay(500);
|
|
||||||
USE_SERIAL.print(F("."));
|
|
||||||
yield();
|
|
||||||
nowSecs = time(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
USE_SERIAL.println();
|
|
||||||
struct tm timeinfo;
|
|
||||||
gmtime_r(&nowSecs, &timeinfo);
|
|
||||||
USE_SERIAL.print(F("Current time: "));
|
|
||||||
USE_SERIAL.print(asctime(&timeinfo));
|
|
||||||
}
|
|
||||||
|
|
||||||
void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) {
|
|
||||||
const uint8_t *src = (const uint8_t *)mem;
|
|
||||||
USE_SERIAL.printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)",
|
|
||||||
(ptrdiff_t)src, len, len);
|
|
||||||
for (uint32_t i = 0; i < len; i++) {
|
|
||||||
if (i % cols == 0) {
|
|
||||||
USE_SERIAL.printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i);
|
|
||||||
}
|
|
||||||
USE_SERIAL.printf("%02X ", *src);
|
|
||||||
src++;
|
|
||||||
}
|
|
||||||
USE_SERIAL.printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void webSocketEvent(WStype_t type, uint8_t *payload, size_t length) {
|
|
||||||
switch (type) {
|
|
||||||
case WStype_DISCONNECTED:
|
|
||||||
USE_SERIAL.printf("[WSc] Disconnected!\n");
|
|
||||||
break;
|
|
||||||
case WStype_CONNECTED:
|
|
||||||
USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload);
|
|
||||||
|
|
||||||
// send message to server when Connected
|
|
||||||
webSocket.sendTXT("Connected");
|
|
||||||
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;
|
|
||||||
case WStype_ERROR:
|
|
||||||
case WStype_FRAGMENT_TEXT_START:
|
|
||||||
case WStype_FRAGMENT_BIN_START:
|
|
||||||
case WStype_FRAGMENT:
|
|
||||||
case WStype_FRAGMENT_FIN:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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("Berge", "BlauerHimmel!");
|
|
||||||
|
|
||||||
// WiFi.disconnect();
|
|
||||||
while (wifiMulti.run() != WL_CONNECTED) {
|
|
||||||
delay(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call to enable WiFi interface to be used by the webSocketClient
|
|
||||||
WebSocketsNetworkClient::Impl::enableWifi();
|
|
||||||
|
|
||||||
setClock();
|
|
||||||
|
|
||||||
// server address, port and URL. This server can be flakey.
|
|
||||||
// Expected response: Request served by 0123456789abcdef
|
|
||||||
webSocket.beginSSL("echo.websocket.org", 443, "/");
|
|
||||||
|
|
||||||
// event handler
|
|
||||||
webSocket.onEvent(webSocketEvent);
|
|
||||||
|
|
||||||
// use HTTP Basic Authorization this is optional enable if needed
|
|
||||||
// webSocket.setAuthorization("user", "Password");
|
|
||||||
|
|
||||||
// try ever 5000 again if connection has failed
|
|
||||||
webSocket.setReconnectInterval(5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() { webSocket.loop(); }
|
|
||||||
@@ -1,148 +0,0 @@
|
|||||||
#include "network_client_impl.h"
|
|
||||||
|
|
||||||
WebSocketsNetworkClient::WebSocketsNetworkClient()
|
|
||||||
: _impl(new WebSocketsNetworkClient::Impl()) {}
|
|
||||||
WebSocketsNetworkClient::WebSocketsNetworkClient(WiFiClient wifi_client)
|
|
||||||
: _impl(new WebSocketsNetworkClient::Impl()) {}
|
|
||||||
WebSocketsNetworkClient::~WebSocketsNetworkClient() {}
|
|
||||||
|
|
||||||
int WebSocketsNetworkClient::connect(IPAddress ip, uint16_t port) {
|
|
||||||
if (_impl->gsm_client_) {
|
|
||||||
return _impl->gsm_client_->connect(ip, port);
|
|
||||||
} else if (_impl->wifi_client_) {
|
|
||||||
return _impl->wifi_client_->connect(ip, port);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int WebSocketsNetworkClient::connect(const char *host, uint16_t port) {
|
|
||||||
if (_impl->gsm_client_) {
|
|
||||||
return _impl->gsm_client_->connect(host, port);
|
|
||||||
} else if (_impl->wifi_client_) {
|
|
||||||
return _impl->wifi_client_->connect(host, port);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int WebSocketsNetworkClient::connect(const char *host, uint16_t port,
|
|
||||||
int32_t timeout_ms) {
|
|
||||||
if (_impl->gsm_client_) {
|
|
||||||
return _impl->gsm_client_->connect(host, port, timeout_ms);
|
|
||||||
} else if (_impl->wifi_client_) {
|
|
||||||
return _impl->wifi_client_->connect(host, port, timeout_ms);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t WebSocketsNetworkClient::write(uint8_t data) {
|
|
||||||
if (_impl->gsm_client_) {
|
|
||||||
return _impl->gsm_client_->write(data);
|
|
||||||
} else if (_impl->wifi_client_) {
|
|
||||||
return _impl->wifi_client_->write(data);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t WebSocketsNetworkClient::write(const uint8_t *buf, size_t size) {
|
|
||||||
Serial.printf("Send_: %zu\n", size);
|
|
||||||
if (_impl->gsm_client_) {
|
|
||||||
return _impl->gsm_client_->write(buf, size);
|
|
||||||
} else if (_impl->wifi_client_) {
|
|
||||||
return _impl->wifi_client_->write(buf, size);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t WebSocketsNetworkClient::write(const char *str) {
|
|
||||||
const int size = strlen(str);
|
|
||||||
Serial.printf("Send: %zu\n", size);
|
|
||||||
if (_impl->gsm_client_) {
|
|
||||||
return _impl->gsm_client_->write((const uint8_t *)str, size);
|
|
||||||
} else if (_impl->wifi_client_) {
|
|
||||||
return _impl->wifi_client_->write((const uint8_t *)str, size);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int WebSocketsNetworkClient::available() {
|
|
||||||
if (_impl->gsm_client_) {
|
|
||||||
return _impl->gsm_client_->available();
|
|
||||||
} else if (_impl->wifi_client_) {
|
|
||||||
return _impl->wifi_client_->available();
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int WebSocketsNetworkClient::read() {
|
|
||||||
if (_impl->gsm_client_) {
|
|
||||||
return _impl->gsm_client_->read();
|
|
||||||
} else if (_impl->wifi_client_) {
|
|
||||||
return _impl->wifi_client_->read();
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int WebSocketsNetworkClient::read(uint8_t *buf, size_t size) {
|
|
||||||
if (_impl->gsm_client_) {
|
|
||||||
return _impl->gsm_client_->read(buf, size);
|
|
||||||
} else if (_impl->wifi_client_) {
|
|
||||||
return _impl->wifi_client_->read(buf, size);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int WebSocketsNetworkClient::peek() {
|
|
||||||
if (_impl->gsm_client_) {
|
|
||||||
return _impl->gsm_client_->peek();
|
|
||||||
} else if (_impl->wifi_client_) {
|
|
||||||
return _impl->wifi_client_->peek();
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebSocketsNetworkClient::flush() {
|
|
||||||
if (_impl->gsm_client_) {
|
|
||||||
return _impl->gsm_client_->flush();
|
|
||||||
} else if (_impl->wifi_client_) {
|
|
||||||
return _impl->wifi_client_->flush();
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebSocketsNetworkClient::stop() {
|
|
||||||
if (_impl->gsm_client_) {
|
|
||||||
return _impl->gsm_client_->stop();
|
|
||||||
} else if (_impl->wifi_client_) {
|
|
||||||
return _impl->wifi_client_->stop();
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t WebSocketsNetworkClient::connected() {
|
|
||||||
if (_impl->gsm_client_) {
|
|
||||||
return _impl->gsm_client_->connected();
|
|
||||||
} else if (_impl->wifi_client_) {
|
|
||||||
return _impl->wifi_client_->connected();
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
WebSocketsNetworkClient::operator bool() {
|
|
||||||
if (_impl->gsm_client_) {
|
|
||||||
return _impl->gsm_client_->operator bool();
|
|
||||||
} else if (_impl->wifi_client_) {
|
|
||||||
return _impl->wifi_client_->operator bool();
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#include "network_client_impl.h"
|
|
||||||
|
|
||||||
std::unique_ptr<WiFiClient> WebSocketsNetworkClient::Impl::wifi_client_ = nullptr;
|
|
||||||
std::unique_ptr<WiFiClientSecure> WebSocketsNetworkClient::Impl::wifi_client_secure_ =
|
|
||||||
nullptr;
|
|
||||||
std::unique_ptr<TinyGsmClient> WebSocketsNetworkClient::Impl::gsm_client_ = nullptr;
|
|
||||||
std::unique_ptr<SSLClient> WebSocketsNetworkClient::Impl::gsm_client_secure_ = nullptr;
|
|
||||||
const char *WebSocketsNetworkClient::Impl::no_interface_error_ = "No interface";
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SSLClient.h>
|
|
||||||
#include <TinyGSM.h>
|
|
||||||
#include <WebSocketsNetworkClientSecure.h>
|
|
||||||
#include <WiFiClientSecure.h>
|
|
||||||
|
|
||||||
struct WebSocketsNetworkClient::Impl {
|
|
||||||
static void enableWifi() {
|
|
||||||
// Do nothing if already enabled
|
|
||||||
if (wifi_client_ && wifi_client_secure_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
wifi_client_ = std::unique_ptr<WiFiClient>(new WiFiClient());
|
|
||||||
wifi_client_secure_ =
|
|
||||||
std::unique_ptr<WiFiClientSecure>(new WiFiClientSecure());
|
|
||||||
}
|
|
||||||
static void disableWifi() {
|
|
||||||
wifi_client_ = nullptr;
|
|
||||||
wifi_client_secure_ = nullptr;
|
|
||||||
}
|
|
||||||
static void enableGsm(TinyGsm* tiny_gsm) {
|
|
||||||
// Do nothing if already enabled
|
|
||||||
if (gsm_client_ && gsm_client_secure_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
gsm_client_ = std::unique_ptr<TinyGsmClient>(new TinyGsmClient(*tiny_gsm));
|
|
||||||
gsm_client_secure_ =
|
|
||||||
std::unique_ptr<SSLClient>(new SSLClient(gsm_client_.get()));
|
|
||||||
}
|
|
||||||
static void disableGsm() {
|
|
||||||
if (gsm_client_secure_) {
|
|
||||||
gsm_client_secure_->stop();
|
|
||||||
}
|
|
||||||
gsm_client_secure_ = nullptr;
|
|
||||||
gsm_client_ = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::unique_ptr<WiFiClient> wifi_client_;
|
|
||||||
static std::unique_ptr<WiFiClientSecure> wifi_client_secure_;
|
|
||||||
static std::unique_ptr<TinyGsmClient> gsm_client_;
|
|
||||||
static std::unique_ptr<SSLClient> gsm_client_secure_;
|
|
||||||
|
|
||||||
static const char* no_interface_error_;
|
|
||||||
};
|
|
||||||
@@ -1,191 +0,0 @@
|
|||||||
#include "network_client_impl.h"
|
|
||||||
|
|
||||||
WebSocketsNetworkClientSecure::WebSocketsNetworkClientSecure() {}
|
|
||||||
WebSocketsNetworkClientSecure::WebSocketsNetworkClientSecure(
|
|
||||||
WiFiClient wifi_client) {}
|
|
||||||
WebSocketsNetworkClientSecure::~WebSocketsNetworkClientSecure() {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
_impl->gsm_client_secure_->stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int WebSocketsNetworkClientSecure::connect(IPAddress ip, uint16_t port) {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
return _impl->gsm_client_secure_->connect(ip, port);
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->connect(ip, port);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int WebSocketsNetworkClientSecure::connect(const char *host, uint16_t port) {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
return _impl->gsm_client_secure_->connect(host, port);
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->connect(host, port);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int WebSocketsNetworkClientSecure::connect(const char *host, uint16_t port,
|
|
||||||
int32_t timeout_ms) {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
// Ignore timeout as will cause read() to block for specified time
|
|
||||||
return _impl->gsm_client_secure_->connect(host, port);
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->connect(host, port, timeout_ms);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t WebSocketsNetworkClientSecure::write(uint8_t data) {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
return _impl->gsm_client_secure_->write(data);
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->write(data);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t WebSocketsNetworkClientSecure::write(const uint8_t *buf, size_t size) {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
return _impl->gsm_client_secure_->write(buf, size);
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->write(buf, size);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t WebSocketsNetworkClientSecure::write(const char *str) {
|
|
||||||
const int size = strlen(str);
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
return _impl->gsm_client_secure_->write((const uint8_t *)str, size);
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->write((const uint8_t *)str, size);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int WebSocketsNetworkClientSecure::available() {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
return _impl->gsm_client_secure_->available();
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->available();
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int WebSocketsNetworkClientSecure::read() {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
return _impl->gsm_client_secure_->read();
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->read();
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int WebSocketsNetworkClientSecure::read(uint8_t *buf, size_t size) {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
return _impl->gsm_client_secure_->read(buf, size);
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->read(buf, size);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int WebSocketsNetworkClientSecure::peek() {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
return _impl->gsm_client_secure_->peek();
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->peek();
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebSocketsNetworkClientSecure::flush() {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
return _impl->gsm_client_secure_->flush();
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->flush();
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebSocketsNetworkClientSecure::stop() {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
return _impl->gsm_client_secure_->stop();
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->stop();
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t WebSocketsNetworkClientSecure::connected() {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
return _impl->gsm_client_secure_->connected();
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->connected();
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
WebSocketsNetworkClientSecure::operator bool() {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
return _impl->gsm_client_secure_->operator bool();
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->operator bool();
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebSocketsNetworkClientSecure::setCACert(const char *rootCA) {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
return _impl->gsm_client_secure_->setCertificate(rootCA);
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->setCACert(rootCA);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebSocketsNetworkClientSecure::setCACertBundle(const uint8_t *bundle) {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
return _impl->gsm_client_secure_->setCACertBundle(bundle);
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->setCACertBundle(bundle);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebSocketsNetworkClientSecure::setInsecure() {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
_impl->gsm_client_secure_->setInsecure();
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
_impl->wifi_client_secure_->setInsecure();
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WebSocketsNetworkClientSecure::verify(const char *fingerprint,
|
|
||||||
const char *domain_name) {
|
|
||||||
if (_impl->gsm_client_secure_) {
|
|
||||||
// Simply calling SSLClient::verify() will break TLS handshake
|
|
||||||
// Can be skipped as verification is done by SSLClient itself,
|
|
||||||
// ArduinoWebSockets need not call it
|
|
||||||
return true;
|
|
||||||
} else if (_impl->wifi_client_secure_) {
|
|
||||||
return _impl->wifi_client_secure_->verify(fingerprint, domain_name);
|
|
||||||
}
|
|
||||||
Serial.println(_impl->no_interface_error_);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@@ -21,5 +21,5 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/Links2004/arduinoWebSockets.git"
|
"url": "https://github.com/Links2004/arduinoWebSockets.git"
|
||||||
},
|
},
|
||||||
"version": "2.7.0"
|
"version": "2.6.1"
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
name=WebSockets
|
name=WebSockets
|
||||||
version=2.7.0
|
version=2.6.1
|
||||||
author=Markus Sattler
|
author=Markus Sattler
|
||||||
maintainer=Markus Sattler
|
maintainer=Markus Sattler
|
||||||
sentence=WebSockets for Arduino (Server + Client)
|
sentence=WebSockets for Arduino (Server + Client)
|
||||||
|
|||||||
@@ -50,7 +50,10 @@
|
|||||||
DEBUG_ESP_PORT.flush(); \
|
DEBUG_ESP_PORT.flush(); \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// #define DEBUG_WEBSOCKETS(...) os_printf( __VA_ARGS__ )
|
#ifdef DEBUG_PORT
|
||||||
|
#define DEBUG_WEBSOCKETS(...) websocket_debug_printf(__VA_ARGS__)
|
||||||
|
void websocket_debug_printf(const char * format, ...);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -135,7 +138,6 @@
|
|||||||
#define NETWORK_UNOWIFIR4 (7)
|
#define NETWORK_UNOWIFIR4 (7)
|
||||||
#define NETWORK_WIFI_NINA (8)
|
#define NETWORK_WIFI_NINA (8)
|
||||||
#define NETWORK_SAMD_SEED (9)
|
#define NETWORK_SAMD_SEED (9)
|
||||||
#define NETWORK_CUSTOM (10)
|
|
||||||
|
|
||||||
// max size of the WS Message Header
|
// max size of the WS Message Header
|
||||||
#define WEBSOCKETS_MAX_HEADER_SIZE (14)
|
#define WEBSOCKETS_MAX_HEADER_SIZE (14)
|
||||||
@@ -287,14 +289,6 @@
|
|||||||
#define WEBSOCKETS_NETWORK_CLASS WiFiClient
|
#define WEBSOCKETS_NETWORK_CLASS WiFiClient
|
||||||
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
|
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
|
||||||
|
|
||||||
#elif (WEBSOCKETS_NETWORK_TYPE == NETWORK_CUSTOM)
|
|
||||||
#include <WebSocketsNetworkClientSecure.h>
|
|
||||||
#include <WiFiServer.h>
|
|
||||||
|
|
||||||
#define SSL_AXTLS
|
|
||||||
#define WEBSOCKETS_NETWORK_CLASS WebSocketsNetworkClient
|
|
||||||
#define WEBSOCKETS_NETWORK_SSL_CLASS WebSocketsNetworkClientSecure
|
|
||||||
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
|
|
||||||
#else
|
#else
|
||||||
#error "no network type selected!"
|
#error "no network type selected!"
|
||||||
#endif
|
#endif
|
||||||
@@ -377,7 +371,7 @@ typedef struct {
|
|||||||
|
|
||||||
#if defined(HAS_SSL)
|
#if defined(HAS_SSL)
|
||||||
bool isSSL = false; ///< run in ssl mode
|
bool isSSL = false; ///< run in ssl mode
|
||||||
WEBSOCKETS_NETWORK_SSL_CLASS * ssl = nullptr;
|
WEBSOCKETS_NETWORK_SSL_CLASS * ssl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
String cUrl; ///< http url
|
String cUrl; ///< http url
|
||||||
|
|||||||
@@ -525,7 +525,7 @@ void WebSocketsClient::messageReceived(WSclient_t * client, WSopcode_t opcode, u
|
|||||||
void WebSocketsClient::clientDisconnect(WSclient_t * client) {
|
void WebSocketsClient::clientDisconnect(WSclient_t * client) {
|
||||||
bool event = false;
|
bool event = false;
|
||||||
|
|
||||||
#ifdef HAS_SSL
|
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_RP2040)
|
||||||
if(client->isSSL && client->ssl) {
|
if(client->isSSL && client->ssl) {
|
||||||
if(client->ssl->connected()) {
|
if(client->ssl->connected()) {
|
||||||
client->ssl->flush();
|
client->ssl->flush();
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Client.h>
|
|
||||||
#include <WiFiClient.h>
|
|
||||||
|
|
||||||
class WebSocketsNetworkClient : public Client {
|
|
||||||
public:
|
|
||||||
struct Impl;
|
|
||||||
std::unique_ptr<Impl> _impl;
|
|
||||||
|
|
||||||
WebSocketsNetworkClient();
|
|
||||||
WebSocketsNetworkClient(WiFiClient wifi_client);
|
|
||||||
virtual ~WebSocketsNetworkClient();
|
|
||||||
|
|
||||||
virtual int connect(IPAddress ip, uint16_t port);
|
|
||||||
virtual int connect(const char * host, uint16_t port);
|
|
||||||
virtual int connect(const char * host, uint16_t port, int32_t timeout);
|
|
||||||
virtual size_t write(uint8_t);
|
|
||||||
virtual size_t write(const uint8_t * buf, size_t size);
|
|
||||||
virtual size_t write(const char * str);
|
|
||||||
virtual int available();
|
|
||||||
virtual int read();
|
|
||||||
virtual int read(uint8_t * buf, size_t size);
|
|
||||||
virtual int peek();
|
|
||||||
virtual void flush();
|
|
||||||
virtual void stop();
|
|
||||||
virtual uint8_t connected();
|
|
||||||
virtual operator bool();
|
|
||||||
};
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <WebSocketsNetworkClient.h>
|
|
||||||
|
|
||||||
class WebSocketsNetworkClientSecure : public WebSocketsNetworkClient {
|
|
||||||
public:
|
|
||||||
WebSocketsNetworkClientSecure();
|
|
||||||
WebSocketsNetworkClientSecure(WiFiClient wifi_client);
|
|
||||||
virtual ~WebSocketsNetworkClientSecure();
|
|
||||||
|
|
||||||
int connect(IPAddress ip, uint16_t port) override;
|
|
||||||
int connect(const char * host, uint16_t port) override;
|
|
||||||
int connect(const char * host, uint16_t port, int32_t timeout) override;
|
|
||||||
size_t write(uint8_t) override;
|
|
||||||
size_t write(const uint8_t * buf, size_t size) override;
|
|
||||||
size_t write(const char * str) override;
|
|
||||||
int available() override;
|
|
||||||
int read() override;
|
|
||||||
int read(uint8_t * buf, size_t size) override;
|
|
||||||
int peek() override;
|
|
||||||
void flush() override;
|
|
||||||
void stop() override;
|
|
||||||
uint8_t connected() override;
|
|
||||||
operator bool() override;
|
|
||||||
|
|
||||||
void setCACert(const char * rootCA);
|
|
||||||
void setCACertBundle(const uint8_t * bundle);
|
|
||||||
void setInsecure();
|
|
||||||
bool verify(const char * fingerprint, const char * domain_name);
|
|
||||||
};
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* @file WebSocketsVersion.h
|
* @file WebSocketsVersion.h
|
||||||
* @date 13.08.2025
|
* @date 06.09.2024
|
||||||
* @author Markus Sattler
|
* @author Markus Sattler
|
||||||
*
|
*
|
||||||
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
||||||
@@ -25,12 +25,12 @@
|
|||||||
#ifndef WEBSOCKETSVERSION_H_
|
#ifndef WEBSOCKETSVERSION_H_
|
||||||
#define WEBSOCKETSVERSION_H_
|
#define WEBSOCKETSVERSION_H_
|
||||||
|
|
||||||
#define WEBSOCKETS_VERSION "2.7.0"
|
#define WEBSOCKETS_VERSION "2.6.1"
|
||||||
|
|
||||||
#define WEBSOCKETS_VERSION_MAJOR 2
|
#define WEBSOCKETS_VERSION_MAJOR 2
|
||||||
#define WEBSOCKETS_VERSION_MINOR 7
|
#define WEBSOCKETS_VERSION_MINOR 6
|
||||||
#define WEBSOCKETS_VERSION_PATCH 0
|
#define WEBSOCKETS_VERSION_PATCH 1
|
||||||
|
|
||||||
#define WEBSOCKETS_VERSION_INT 2007000
|
#define WEBSOCKETS_VERSION_INT 2006001
|
||||||
|
|
||||||
#endif /* WEBSOCKETSVERSION_H_ */
|
#endif /* WEBSOCKETSVERSION_H_ */
|
||||||
|
|||||||
32
src/debug.cpp
Normal file
32
src/debug.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
#include "WebSockets.h"
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#ifdef DEBUG_PORT
|
||||||
|
|
||||||
|
void websocket_debug_printf(const char * format, ...) {
|
||||||
|
va_list arg;
|
||||||
|
va_start(arg, format);
|
||||||
|
char temp[64];
|
||||||
|
char * buffer = temp;
|
||||||
|
size_t len = vsnprintf(temp, sizeof(temp), format, arg);
|
||||||
|
va_end(arg);
|
||||||
|
if(len > sizeof(temp) - 1) {
|
||||||
|
buffer = new(std::nothrow) char[len + 1];
|
||||||
|
if(!buffer) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
va_start(arg, format);
|
||||||
|
vsnprintf(buffer, len + 1, format, arg);
|
||||||
|
va_end(arg);
|
||||||
|
}
|
||||||
|
len = DEBUG_PORT.write((const uint8_t *)buffer, len);
|
||||||
|
if(buffer != temp) {
|
||||||
|
delete[] buffer;
|
||||||
|
}
|
||||||
|
DEBUG_PORT.flush();
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user