mirror of
https://github.com/Links2004/arduinoWebSockets.git
synced 2025-06-27 07:51:37 +02:00
Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
6972f7a84e | |||
93b0b9eeaf | |||
dd14850bb6 | |||
d36f7bb100 | |||
10a8d3ca67 | |||
4f55c36c80 | |||
b3efb316ed | |||
ea997cf977 | |||
a103bb915c | |||
bc58d75d71 | |||
d7be7cd2fe | |||
73faf7e6b6 | |||
00be8c7833 | |||
5b4eaa0b11 | |||
8988faf5f0 | |||
1ebae1d3e1 |
@ -19,6 +19,10 @@ a WebSocket Server and Client for Arduino based on RFC6455.
|
|||||||
- max output length has no limit (the hardware is the limit)
|
- max output length has no limit (the hardware is the limit)
|
||||||
- Client send big frames with mask 0x00000000 (on AVR all frames)
|
- Client send big frames with mask 0x00000000 (on AVR all frames)
|
||||||
|
|
||||||
|
##### Limitations for Async #####
|
||||||
|
- Functions called from within the context of the websocket event might not honor `yield()` and/or `delay()`. See [this issue](https://github.com/Links2004/arduinoWebSockets/issues/58#issuecomment-192376395) for more info and a potential workaround.
|
||||||
|
- wss / SSL is not possible.
|
||||||
|
|
||||||
##### Supported Hardware #####
|
##### Supported Hardware #####
|
||||||
- ESP8266 [Arduino for ESP8266](https://github.com/Links2004/Arduino)
|
- ESP8266 [Arduino for ESP8266](https://github.com/Links2004/Arduino)
|
||||||
- ESP31B
|
- ESP31B
|
||||||
@ -45,8 +49,6 @@ The mode can be aktivated in the ```WebSockets.h``` (see WEBSOCKETS_NETWORK_TYPE
|
|||||||
|
|
||||||
[ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP) libary is required.
|
[ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP) libary is required.
|
||||||
|
|
||||||
Note: in this mode wss / SSL is not possible.
|
|
||||||
|
|
||||||
### Issues ###
|
### Issues ###
|
||||||
Submit issues to: https://github.com/Links2004/arduinoWebSockets/issues
|
Submit issues to: https://github.com/Links2004/arduinoWebSockets/issues
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ WebSocketsClient webSocket;
|
|||||||
|
|
||||||
#define USE_SERIAL Serial1
|
#define USE_SERIAL Serial1
|
||||||
|
|
||||||
void webSocketEvent(WStype_t type, uint8_t * payload, size_t lenght) {
|
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
|
||||||
|
|
||||||
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
@ -44,11 +44,11 @@ void webSocketEvent(WStype_t type, uint8_t * payload, size_t lenght) {
|
|||||||
// webSocket.sendTXT("message here");
|
// webSocket.sendTXT("message here");
|
||||||
break;
|
break;
|
||||||
case WStype_BIN:
|
case WStype_BIN:
|
||||||
USE_SERIAL.printf("[WSc] get binary lenght: %u\n", lenght);
|
USE_SERIAL.printf("[WSc] get binary length: %u\n", length);
|
||||||
hexdump(payload, lenght);
|
hexdump(payload, length);
|
||||||
|
|
||||||
// send data to server
|
// send data to server
|
||||||
// webSocket.sendBIN(payload, lenght);
|
// webSocket.sendBIN(payload, length);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
name=WebSockets
|
name=WebSockets
|
||||||
version=2.0
|
version=2.0.2
|
||||||
author=Markus Sattler
|
author=Markus Sattler
|
||||||
maintainer=Markus Sattler
|
maintainer=Markus Sattler
|
||||||
sentence=WebSockets for Arduino (Server + Client)
|
sentence=WebSockets for Arduino (Server + Client)
|
||||||
paragraph=use 2.0 for ESP and 1.3 for AVR
|
paragraph=use 2.x.x for ESP and 1.3 for AVR
|
||||||
category=Communication
|
category=Communication
|
||||||
url=https://github.com/Links2004/arduinoWebSockets
|
url=https://github.com/Links2004/arduinoWebSockets
|
||||||
architectures=*
|
architectures=*
|
||||||
|
@ -181,6 +181,7 @@ typedef struct {
|
|||||||
WSMessageHeader_t cWsHeaderDecode;
|
WSMessageHeader_t cWsHeaderDecode;
|
||||||
|
|
||||||
String base64Authorization; ///< Base64 encoded Auth request
|
String base64Authorization; ///< Base64 encoded Auth request
|
||||||
|
String plainAuthorization; ///< Base64 encoded Auth request
|
||||||
|
|
||||||
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
||||||
String cHttpLine; ///< HTTP header lines
|
String cHttpLine; ///< HTTP header lines
|
||||||
|
@ -62,6 +62,7 @@ void WebSocketsClient::begin(const char *host, uint16_t port, const char * url,
|
|||||||
_client.cExtensions = "";
|
_client.cExtensions = "";
|
||||||
_client.cVersion = 0;
|
_client.cVersion = 0;
|
||||||
_client.base64Authorization = "";
|
_client.base64Authorization = "";
|
||||||
|
_client.plainAuthorization = "";
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
randomSeed(RANDOM_REG32);
|
randomSeed(RANDOM_REG32);
|
||||||
@ -228,7 +229,8 @@ void WebSocketsClient::setAuthorization(const char * user, const char * password
|
|||||||
*/
|
*/
|
||||||
void WebSocketsClient::setAuthorization(const char * auth) {
|
void WebSocketsClient::setAuthorization(const char * auth) {
|
||||||
if(auth) {
|
if(auth) {
|
||||||
_client.base64Authorization = auth;
|
//_client.base64Authorization = auth;
|
||||||
|
_client.plainAuthorization = auth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,14 +394,18 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
String handshake = "GET " + client->cUrl + " HTTP/1.1\r\n"
|
String handshake = "GET " + client->cUrl + " HTTP/1.1\r\n"
|
||||||
"Host: " + _host + "\r\n"
|
"Host: " + _host + ":" + _port + "\r\n"
|
||||||
"Upgrade: websocket\r\n"
|
|
||||||
"Connection: Upgrade\r\n"
|
"Connection: Upgrade\r\n"
|
||||||
|
"Upgrade: websocket\r\n"
|
||||||
|
"Origin: file://\r\n"
|
||||||
"User-Agent: arduino-WebSocket-Client\r\n"
|
"User-Agent: arduino-WebSocket-Client\r\n"
|
||||||
"Sec-WebSocket-Version: 13\r\n"
|
"Sec-WebSocket-Version: 13\r\n"
|
||||||
"Sec-WebSocket-Protocol: " + client->cProtocol +"\r\n"
|
|
||||||
"Sec-WebSocket-Key: " + client->cKey + "\r\n";
|
"Sec-WebSocket-Key: " + client->cKey + "\r\n";
|
||||||
|
|
||||||
|
if(client->cProtocol.length() > 0) {
|
||||||
|
handshake += "Sec-WebSocket-Protocol: " + client->cProtocol + "\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
if(client->cExtensions.length() > 0) {
|
if(client->cExtensions.length() > 0) {
|
||||||
handshake += "Sec-WebSocket-Extensions: " + client->cExtensions + "\r\n";
|
handshake += "Sec-WebSocket-Extensions: " + client->cExtensions + "\r\n";
|
||||||
}
|
}
|
||||||
@ -408,6 +414,10 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
|
|||||||
handshake += "Authorization: Basic " + client->base64Authorization + "\r\n";
|
handshake += "Authorization: Basic " + client->base64Authorization + "\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(client->plainAuthorization.length() > 0) {
|
||||||
|
handshake += "Authorization: " + client->plainAuthorization + "\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
handshake += "\r\n";
|
handshake += "\r\n";
|
||||||
|
|
||||||
client->tcp->write(handshake.c_str(), handshake.length());
|
client->tcp->write(handshake.c_str(), handshake.length());
|
||||||
@ -439,7 +449,7 @@ void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) {
|
|||||||
String headerValue = headerLine->substring(headerLine->indexOf(':') + 2);
|
String headerValue = headerLine->substring(headerLine->indexOf(':') + 2);
|
||||||
|
|
||||||
if(headerName.equalsIgnoreCase("Connection")) {
|
if(headerName.equalsIgnoreCase("Connection")) {
|
||||||
if(headerValue.indexOf("Upgrade") >= 0) {
|
if(headerValue.equalsIgnoreCase("upgrade")) {
|
||||||
client->cIsUpgrade = true;
|
client->cIsUpgrade = true;
|
||||||
}
|
}
|
||||||
} else if(headerName.equalsIgnoreCase("Upgrade")) {
|
} else if(headerName.equalsIgnoreCase("Upgrade")) {
|
||||||
@ -617,6 +627,3 @@ void WebSocketsClient::asyncConnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -627,7 +627,7 @@ void WebSocketsServer::handleHeader(WSclient_t * client, String * headerLine) {
|
|||||||
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] - cProtocol: %s\n", client->num, client->cProtocol.c_str());
|
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] - cProtocol: %s\n", client->num, client->cProtocol.c_str());
|
||||||
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] - cExtensions: %s\n", client->num, client->cExtensions.c_str());
|
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] - cExtensions: %s\n", client->num, client->cExtensions.c_str());
|
||||||
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] - cVersion: %d\n", client->num, client->cVersion);
|
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] - cVersion: %d\n", client->num, client->cVersion);
|
||||||
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] - base64Authorization: %s\n", client->num, client->base64Authorization);
|
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] - base64Authorization: %s\n", client->num, client->base64Authorization.c_str());
|
||||||
|
|
||||||
bool ok = (client->cIsUpgrade && client->cIsWebsocket);
|
bool ok = (client->cIsUpgrade && client->cIsWebsocket);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user