From 4fc80871a605694bf09f3c0503fabd43e3bd2150 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Sun, 30 Jul 2017 00:18:37 +0200 Subject: [PATCH 01/26] Update WebSockets.h --- src/WebSockets.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/WebSockets.h b/src/WebSockets.h index 41cbe7d..3c08deb 100644 --- a/src/WebSockets.h +++ b/src/WebSockets.h @@ -70,6 +70,7 @@ #define NETWORK_ESP8266 (1) #define NETWORK_W5100 (2) #define NETWORK_ENC28J60 (3) +#define NETWORK_ESP32 (4) // max size of the WS Message Header #define WEBSOCKETS_MAX_HEADER_SIZE (14) @@ -80,6 +81,8 @@ #define WEBSOCKETS_NETWORK_TYPE NETWORK_ESP8266 //#define WEBSOCKETS_NETWORK_TYPE NETWORK_ESP8266_ASYNC //#define WEBSOCKETS_NETWORK_TYPE NETWORK_W5100 +#elif defined(ESP32) +#define WEBSOCKETS_NETWORK_TYPE NETWORK_ESP32 #else #define WEBSOCKETS_NETWORK_TYPE NETWORK_W5100 #endif @@ -137,6 +140,13 @@ #define WEBSOCKETS_NETWORK_CLASS UIPClient #define WEBSOCKETS_NETWORK_SERVER_CLASS UIPServer +#elif (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) + +#include +#include +#define WEBSOCKETS_NETWORK_CLASS WiFiClient +#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer + #else #error "no network type selected!" #endif @@ -201,7 +211,7 @@ typedef struct { bool isSocketIO; ///< client for socket.io server -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) bool isSSL; ///< run in ssl mode WiFiClientSecure * ssl; #endif From 8c19d7ba48e90280868c4146616a15b6e29e760a Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Sun, 30 Jul 2017 00:21:13 +0200 Subject: [PATCH 02/26] Update WebSockets.cpp added esp32 hwcrypto for sha1 --- src/WebSockets.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/WebSockets.cpp b/src/WebSockets.cpp index 118ebb7..a713625 100644 --- a/src/WebSockets.cpp +++ b/src/WebSockets.cpp @@ -38,6 +38,8 @@ extern "C" { #ifdef ESP8266 #include +#elif defined(ESP32) +#include #else extern "C" { @@ -483,6 +485,9 @@ String WebSockets::acceptKey(String & clientKey) { uint8_t sha1HashBin[20] = { 0 }; #ifdef ESP8266 sha1(clientKey + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", &sha1HashBin[0]); +#elif defined(ESP32) + String data = clientKey + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; + esp_sha(SHA1, (unsigned char*)data.c_str(), data.length(), &sha1HashBin[0]); #else clientKey += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; SHA1_CTX ctx; From a388676b40040be56f61db1d9ca86a839441c539 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Sun, 30 Jul 2017 00:22:23 +0200 Subject: [PATCH 03/26] added remoteIP for esp32 --- src/WebSocketsServer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebSocketsServer.h b/src/WebSocketsServer.h index 3550c6a..72169df 100644 --- a/src/WebSocketsServer.h +++ b/src/WebSocketsServer.h @@ -92,7 +92,7 @@ public: void setAuthorization(const char * user, const char * password); void setAuthorization(const char * auth); -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) IPAddress remoteIP(uint8_t num); #endif From 1d40160d99e5987ae745fa62c328679ffbbdc632 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Sun, 30 Jul 2017 00:54:17 +0200 Subject: [PATCH 04/26] added esp32 support --- src/WebSocketsServer.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/WebSocketsServer.cpp b/src/WebSocketsServer.cpp index 9b8cfe7..d8017e6 100644 --- a/src/WebSocketsServer.cpp +++ b/src/WebSocketsServer.cpp @@ -52,6 +52,8 @@ WebSocketsServer::~WebSocketsServer() { #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) _server->close(); +#elif (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) + _server->end(); #else // TODO how to close server? #endif @@ -75,7 +77,7 @@ void WebSocketsServer::begin(void) { client->num = i; client->status = WSC_NOT_CONNECTED; client->tcp = NULL; -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) client->isSSL = false; client->ssl = NULL; #endif @@ -98,6 +100,9 @@ void WebSocketsServer::begin(void) { #ifdef ESP8266 randomSeed(RANDOM_REG32); +#elif defined(ESP32) + #define DR_REG_RNG_BASE 0x3ff75144 + randomSeed(READ_PERI_REG(DR_REG_RNG_BASE)); #else // TODO find better seed randomSeed(millis()); @@ -386,7 +391,7 @@ void WebSocketsServer::setAuthorization(const char * auth) { } } -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) /** * get an IP for a client * @param num uint8_t client id @@ -423,7 +428,7 @@ bool WebSocketsServer::newClient(WEBSOCKETS_NETWORK_CLASS * TCPclient) { client->tcp = TCPclient; -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) client->isSSL = false; client->tcp->setNoDelay(true); #endif @@ -432,7 +437,7 @@ bool WebSocketsServer::newClient(WEBSOCKETS_NETWORK_CLASS * TCPclient) { client->tcp->setTimeout(WEBSOCKETS_TCP_TIMEOUT); #endif client->status = WSC_HEADER; -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) IPAddress ip = client->tcp->remoteIP(); DEBUG_WEBSOCKETS("[WS-Server][%d] new client from %d.%d.%d.%d\n", client->num, ip[0], ip[1], ip[2], ip[3]); #else @@ -496,7 +501,7 @@ void WebSocketsServer::messageReceived(WSclient_t * client, WSopcode_t opcode, u void WebSocketsServer::clientDisconnect(WSclient_t * client) { -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) if(client->isSSL && client->ssl) { if(client->ssl->connected()) { client->ssl->flush(); @@ -584,10 +589,12 @@ void WebSocketsServer::handleNewClients(void) { #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) while(_server->hasClient()) { +#elif (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) + while(_server->available()) { #endif bool ok = false; -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) // store new connection WEBSOCKETS_NETWORK_CLASS * tcpClient = new WEBSOCKETS_NETWORK_CLASS(_server->available()); #else @@ -603,7 +610,7 @@ void WebSocketsServer::handleNewClients(void) { if(!ok) { // no free space to handle client -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) IPAddress ip = tcpClient->remoteIP(); DEBUG_WEBSOCKETS("[WS-Server] no free space new client from %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]); #else @@ -612,11 +619,10 @@ void WebSocketsServer::handleNewClients(void) { tcpClient->stop(); } -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) delay(0); - } #endif - + } } From dbabc1025bc2d942a801965e1f67d45b79b90148 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Sun, 30 Jul 2017 00:58:15 +0200 Subject: [PATCH 05/26] added esp32 support --- src/WebSocketsClient.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/WebSocketsClient.h b/src/WebSocketsClient.h index 7390a76..3ca2698 100644 --- a/src/WebSocketsClient.h +++ b/src/WebSocketsClient.h @@ -42,7 +42,7 @@ class WebSocketsClient: private WebSockets { void begin(const char *host, uint16_t port, const char * url = "/", const char * protocol = "arduino"); void begin(String host, uint16_t port, String url = "/", String protocol = "arduino"); -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) void beginSSL(const char *host, uint16_t port, const char * url = "/", const char * = "", const char * protocol = "arduino"); void beginSSL(String host, uint16_t port, String url = "/", String fingerprint = "", String protocol = "arduino"); #endif @@ -50,7 +50,7 @@ class WebSocketsClient: private WebSockets { void beginSocketIO(const char *host, uint16_t port, const char * url = "/socket.io/?EIO=3", const char * protocol = "arduino"); void beginSocketIO(String host, uint16_t port, String url = "/socket.io/?EIO=3", String protocol = "arduino"); -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) void beginSocketIOSSL(const char *host, uint16_t port, const char * url = "/socket.io/?EIO=3", const char * protocol = "arduino"); void beginSocketIOSSL(String host, uint16_t port, String url = "/socket.io/?EIO=3", String protocol = "arduino"); #endif @@ -87,7 +87,7 @@ class WebSocketsClient: private WebSockets { String _host; uint16_t _port; -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) String _fingerprint; #endif WSclient_t _client; From 4c1c5378cb84838ae590f7dd7a138ef5d848cc3f Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Sun, 30 Jul 2017 01:40:36 +0200 Subject: [PATCH 06/26] esp32 no hasClient function --- src/WebSocketsServer.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/WebSocketsServer.cpp b/src/WebSocketsServer.cpp index d8017e6..4f6400e 100644 --- a/src/WebSocketsServer.cpp +++ b/src/WebSocketsServer.cpp @@ -589,8 +589,6 @@ void WebSocketsServer::handleNewClients(void) { #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) while(_server->hasClient()) { -#elif (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) - while(_server->available()) { #endif bool ok = false; @@ -621,8 +619,9 @@ void WebSocketsServer::handleNewClients(void) { #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) delay(0); -#endif } +#endif + } From 83a1539e1e583323ba07cf03df4540cdcf73b0c7 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Sun, 3 Sep 2017 09:55:15 +0200 Subject: [PATCH 07/26] fix: ESP32 new client connection --- src/WebSocketsServer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebSocketsServer.cpp b/src/WebSocketsServer.cpp index 4f6400e..72bca56 100644 --- a/src/WebSocketsServer.cpp +++ b/src/WebSocketsServer.cpp @@ -587,7 +587,7 @@ bool WebSocketsServer::clientIsConnected(WSclient_t * client) { */ void WebSocketsServer::handleNewClients(void) { -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) while(_server->hasClient()) { #endif bool ok = false; From a93a8457805816abe178382ce907655ae4f9a3f5 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Sun, 3 Sep 2017 10:06:00 +0200 Subject: [PATCH 08/26] add: ESP32 support --- src/WebSocketsClient.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index 3faae99..541e30f 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -42,14 +42,14 @@ WebSocketsClient::~WebSocketsClient() { void WebSocketsClient::begin(const char *host, uint16_t port, const char * url, const char * protocol) { _host = host; _port = port; -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) _fingerprint = ""; #endif _client.num = 0; _client.status = WSC_NOT_CONNECTED; _client.tcp = NULL; -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) _client.isSSL = false; _client.ssl = NULL; #endif @@ -81,7 +81,7 @@ void WebSocketsClient::begin(String host, uint16_t port, String url, String prot begin(host.c_str(), port, url.c_str(), protocol.c_str()); } -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) void WebSocketsClient::beginSSL(const char *host, uint16_t port, const char * url, const char * fingerprint, const char * protocol) { begin(host, port, url, protocol); _client.isSSL = true; @@ -102,7 +102,7 @@ void WebSocketsClient::beginSocketIO(String host, uint16_t port, String url, Str beginSocketIO(host.c_str(), port, url.c_str(), protocol.c_str()); } -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) void WebSocketsClient::beginSocketIOSSL(const char *host, uint16_t port, const char * url, const char * protocol) { begin(host, port, url, protocol); _client.isSocketIO = true; @@ -122,7 +122,7 @@ void WebSocketsClient::beginSocketIOSSL(String host, uint16_t port, String url, void WebSocketsClient::loop(void) { if(!clientIsConnected(&_client)) { -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) if(_client.isSSL) { DEBUG_WEBSOCKETS("[WS-Client] connect wss...\n"); if(_client.ssl) { @@ -322,7 +322,7 @@ void WebSocketsClient::clientDisconnect(WSclient_t * client) { bool event = false; -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) if(client->isSSL && client->ssl) { if(client->ssl->connected()) { client->ssl->flush(); @@ -421,7 +421,7 @@ void WebSocketsClient::handleClientData(void) { break; } } -#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) +#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) delay(0); #endif } From 1d300084e0bdcdb74fc32c7c7b01a9d94fdb69ea Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 6 Feb 2018 09:57:04 +0100 Subject: [PATCH 09/26] fix --- .../WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino b/examples/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino index f737d7f..913b799 100644 --- a/examples/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino +++ b/examples/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino @@ -23,7 +23,7 @@ ESP8266WiFiMulti WiFiMulti; -ESP8266WebServer server = ESP8266WebServer(80); +ESP8266WebServer server(80); WebSocketsServer webSocket = WebSocketsServer(81); void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) { From 0b102995495bc07b67163fd1d5b98c6b6eda1f7e Mon Sep 17 00:00:00 2001 From: Links Date: Tue, 6 Feb 2018 20:22:29 +0100 Subject: [PATCH 10/26] travis builds for ESP32 --- .travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.travis.yml b/.travis.yml index 881c97f..b731a64 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,10 +20,20 @@ script: - git clone https://github.com/esp8266/Arduino.git esp8266 - cd esp8266/tools - python get.py + - cd $HOME/arduino_ide/hardware + - mkdir espressif + - cd espressif + - git clone https://github.com/espressif/arduino-esp32.git esp32 + - cd esp32/tools + - python get.py + - cd $TRAVIS_BUILD_DIR - source $TRAVIS_BUILD_DIR/travis/common.sh - arduino --board esp8266com:esp8266:generic --save-prefs - arduino --get-pref sketchbook.path - build_sketches arduino $HOME/Arduino/libraries/arduinoWebSockets esp8266 + - arduino --board espressif:esp32:esp32:FlashFreq=80 --save-prefs + - arduino --get-pref sketchbook.path + - build_sketches arduino $HOME/Arduino/libraries/arduinoWebSockets esp32 notifications: email: From 30b6deedd272f156350dbcfb3ef76536598f1556 Mon Sep 17 00:00:00 2001 From: Links Date: Tue, 6 Feb 2018 20:41:36 +0100 Subject: [PATCH 11/26] use travis matrix --- .travis.yml | 34 +++++++++++++--------------------- travis/common.sh | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index b731a64..29f1cbe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,38 +2,30 @@ sudo: false language: bash os: - linux +env: + global: + - IDE_VERSION=1.6.5 + matrix: + CPU="esp8266" BOARD="esp8266com:esp8266:generic" + CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" script: - /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16 - sleep 3 - export DISPLAY=:1.0 - - wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz - - tar xf arduino-1.6.5-linux64.tar.xz - - mv arduino-1.6.5 $HOME/arduino_ide + - wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz + - tar xf arduino-$IDE_VERSION-linux64.tar.xz + - mv arduino-$IDE_VERSION $HOME/arduino_ide - export PATH="$HOME/arduino_ide:$PATH" - which arduino - mkdir -p $HOME/Arduino/libraries - cp -r $TRAVIS_BUILD_DIR $HOME/Arduino/libraries/arduinoWebSockets - - cd $HOME/arduino_ide/hardware - - mkdir esp8266com - - cd esp8266com - - git clone https://github.com/esp8266/Arduino.git esp8266 - - cd esp8266/tools - - python get.py - - cd $HOME/arduino_ide/hardware - - mkdir espressif - - cd espressif - - git clone https://github.com/espressif/arduino-esp32.git esp32 - - cd esp32/tools - - python get.py - - cd $TRAVIS_BUILD_DIR - source $TRAVIS_BUILD_DIR/travis/common.sh - - arduino --board esp8266com:esp8266:generic --save-prefs + - get_core $CPU + - cd $TRAVIS_BUILD_DIR + - arduino --board $BOARD --save-prefs - arduino --get-pref sketchbook.path - - build_sketches arduino $HOME/Arduino/libraries/arduinoWebSockets esp8266 - - arduino --board espressif:esp32:esp32:FlashFreq=80 --save-prefs - - arduino --get-pref sketchbook.path - - build_sketches arduino $HOME/Arduino/libraries/arduinoWebSockets esp32 + - build_sketches arduino $HOME/Arduino/libraries/arduinoWebSockets $CPU notifications: email: diff --git a/travis/common.sh b/travis/common.sh index 4bcd81b..1cf8bff 100644 --- a/travis/common.sh +++ b/travis/common.sh @@ -22,3 +22,25 @@ function build_sketches() done } + +function get_core() +{ + cd $HOME/arduino_ide/hardware + + if [ "$1" = "esp8266" ] ; then + mkdir esp8266com + cd esp8266com + git clone https://github.com/esp8266/Arduino.git esp8266 + cd esp8266/tools + python get.py + fi + + if [ "$1" = "esp32" ] ; then + mkdir espressif + cd espressif + git clone https://github.com/espressif/arduino-esp32.git esp32 + cd esp32/tools + python get.py + fi + +} From 5e1f9b1c267ce0b780e597f620496c53183ff27e Mon Sep 17 00:00:00 2001 From: Links Date: Tue, 6 Feb 2018 20:44:10 +0100 Subject: [PATCH 12/26] CORE_HAS_LIBB64 for ESP32 --- src/libb64/cdecode.c | 8 ++++++-- src/libb64/cencode.c | 14 +++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/libb64/cdecode.c b/src/libb64/cdecode.c index 0d86d0e..e135da2 100644 --- a/src/libb64/cdecode.c +++ b/src/libb64/cdecode.c @@ -9,6 +9,10 @@ For details, see http://sourceforge.net/projects/libb64 #include #endif +#if defined(ESP32) +#define CORE_HAS_LIBB64 +#endif + #ifndef CORE_HAS_LIBB64 #include "cdecode_inc.h" @@ -32,9 +36,9 @@ int base64_decode_block(const char* code_in, const int length_in, char* plaintex const char* codechar = code_in; char* plainchar = plaintext_out; char fragment; - + *plainchar = state_in->plainchar; - + switch (state_in->step) { while (1) diff --git a/src/libb64/cencode.c b/src/libb64/cencode.c index 7367135..afe1463 100644 --- a/src/libb64/cencode.c +++ b/src/libb64/cencode.c @@ -9,6 +9,10 @@ For details, see http://sourceforge.net/projects/libb64 #include #endif +#if defined(ESP32) +#define CORE_HAS_LIBB64 +#endif + #ifndef CORE_HAS_LIBB64 #include "cencode_inc.h" @@ -35,9 +39,9 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, char* codechar = code_out; char result; char fragment; - + result = state_in->result; - + switch (state_in->step) { while (1) @@ -76,7 +80,7 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, *codechar++ = base64_encode_value(result); result = (fragment & 0x03f) >> 0; *codechar++ = base64_encode_value(result); - + ++(state_in->stepcount); if (state_in->stepcount == CHARS_PER_LINE/4) { @@ -92,7 +96,7 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, int base64_encode_blockend(char* code_out, base64_encodestate* state_in) { char* codechar = code_out; - + switch (state_in->step) { case step_B: @@ -108,7 +112,7 @@ int base64_encode_blockend(char* code_out, base64_encodestate* state_in) break; } *codechar++ = 0x00; - + return codechar - code_out; } From 255f40eaa700ec5dd5fd61a8957d8313e818c0b9 Mon Sep 17 00:00:00 2001 From: Links Date: Tue, 6 Feb 2018 20:46:17 +0100 Subject: [PATCH 13/26] travis.yml --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 29f1cbe..f24935f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,8 @@ env: global: - IDE_VERSION=1.6.5 matrix: - CPU="esp8266" BOARD="esp8266com:esp8266:generic" - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" + - CPU="esp8266" BOARD="esp8266com:esp8266:generic" + - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" script: - /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16 From 0b35e32b2a1d59041a87dc1216ad04eb616b50f7 Mon Sep 17 00:00:00 2001 From: Links Date: Tue, 6 Feb 2018 21:10:29 +0100 Subject: [PATCH 14/26] examples for ESP32 --- examples/WebSocketClient/WebSocketClient.ino | 34 ++++++++++++++++++- examples/WebSocketServer/WebSocketServer.ino | 35 ++++++++++++++++++-- travis/common.sh | 4 ++- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/examples/WebSocketClient/WebSocketClient.ino b/examples/WebSocketClient/WebSocketClient.ino index 3ce8498..689dada 100644 --- a/examples/WebSocketClient/WebSocketClient.ino +++ b/examples/WebSocketClient/WebSocketClient.ino @@ -10,15 +10,30 @@ #include #include +#if defined(ESP8266) + #include #include + #include #include + ESP8266WiFiMulti WiFiMulti; +#elif defined(ESP32) + #include + #include + WiFiMulti WiFiMulti; + + HardwareSerial Serial1(2); +#endif + #include #include -ESP8266WiFiMulti WiFiMulti; WebSocketsClient webSocket; #define USE_SERIAL Serial1 +#ifndef ESP8266 +void hexdump(const void *mem, uint32_t len, uint8_t cols = 16); +#endif + void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { switch(type) { @@ -90,3 +105,20 @@ void setup() { void loop() { webSocket.loop(); } + + + +#ifndef ESP8266 +void hexdump(const void *mem, uint32_t len, uint8_t cols) { + 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"); +} +#endif diff --git a/examples/WebSocketServer/WebSocketServer.ino b/examples/WebSocketServer/WebSocketServer.ino index 5e266a2..de9c63e 100644 --- a/examples/WebSocketServer/WebSocketServer.ino +++ b/examples/WebSocketServer/WebSocketServer.ino @@ -7,8 +7,18 @@ #include -#include -#include +#if defined(ESP8266) + #include #include + #include #include + ESP8266WiFiMulti WiFiMulti; +#elif defined(ESP32) + #include + #include + WiFiMulti WiFiMulti; + + HardwareSerial Serial1(2); +#endif + #include #include @@ -18,6 +28,11 @@ WebSocketsServer webSocket = WebSocketsServer(81); #define USE_SERIAL Serial1 + +#ifndef ESP8266 +void hexdump(const void *mem, uint32_t len, uint8_t cols = 16); +#endif + void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) { switch(type) { @@ -28,7 +43,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length { IPAddress ip = webSocket.remoteIP(num); USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload); - + // send message to client webSocket.sendTXT(num, "Connected"); } @@ -84,3 +99,17 @@ void loop() { webSocket.loop(); } +#ifndef ESP8266 +void hexdump(const void *mem, uint32_t len, uint8_t cols) { + 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"); +} +#endif diff --git a/travis/common.sh b/travis/common.sh index 1cf8bff..10237bb 100644 --- a/travis/common.sh +++ b/travis/common.sh @@ -25,6 +25,8 @@ function build_sketches() function get_core() { + echo Setup core for $1 + cd $HOME/arduino_ide/hardware if [ "$1" = "esp8266" ] ; then @@ -42,5 +44,5 @@ function get_core() cd esp32/tools python get.py fi - + } From 46cff38287eda8594e20c5d03cb4b9d741840ca4 Mon Sep 17 00:00:00 2001 From: Links Date: Tue, 6 Feb 2018 21:12:39 +0100 Subject: [PATCH 15/26] fix ESP32 sha1 problem --- src/libsha1/libsha1.c | 2 +- src/libsha1/libsha1.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libsha1/libsha1.c b/src/libsha1/libsha1.c index 7ff3846..fcf01c5 100644 --- a/src/libsha1/libsha1.c +++ b/src/libsha1/libsha1.c @@ -18,7 +18,7 @@ A million repetitions of "a" /* #define LITTLE_ENDIAN * This should be #define'd already, if true. */ /* #define SHA1HANDSOFF * Copies data before messing with it. */ -#ifndef ESP8266 +#if !defined(ESP8266) && !defined(ESP32) #define SHA1HANDSOFF diff --git a/src/libsha1/libsha1.h b/src/libsha1/libsha1.h index 1f08d0e..40afa61 100644 --- a/src/libsha1/libsha1.h +++ b/src/libsha1/libsha1.h @@ -5,7 +5,7 @@ By Steve Reid 100% Public Domain */ -#ifndef ESP8266 +#if !defined(ESP8266) && !defined(ESP32) typedef struct { uint32_t state[5]; @@ -18,4 +18,4 @@ void SHA1Init(SHA1_CTX* context); void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len); void SHA1Final(unsigned char digest[20], SHA1_CTX* context); -#endif \ No newline at end of file +#endif From 05f4cfd7bf01143d22cf29c5e1bbd6458a717f1c Mon Sep 17 00:00:00 2001 From: Links Date: Tue, 6 Feb 2018 21:17:14 +0100 Subject: [PATCH 16/26] fix includes for WebSocketClient.ino --- examples/WebSocketClient/WebSocketClient.ino | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/WebSocketClient/WebSocketClient.ino b/examples/WebSocketClient/WebSocketClient.ino index 689dada..baac0f0 100644 --- a/examples/WebSocketClient/WebSocketClient.ino +++ b/examples/WebSocketClient/WebSocketClient.ino @@ -7,9 +7,6 @@ #include -#include -#include - #if defined(ESP8266) #include #include #include #include From d340c89b097e6f5b03db5410f0513fd5479426e4 Mon Sep 17 00:00:00 2001 From: Links Date: Tue, 6 Feb 2018 21:26:06 +0100 Subject: [PATCH 17/26] ... --- examples/WebSocketClient/WebSocketClient.ino | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/WebSocketClient/WebSocketClient.ino b/examples/WebSocketClient/WebSocketClient.ino index baac0f0..4dad8e5 100644 --- a/examples/WebSocketClient/WebSocketClient.ino +++ b/examples/WebSocketClient/WebSocketClient.ino @@ -8,8 +8,8 @@ #include #if defined(ESP8266) - #include #include - #include #include + #include + #include ESP8266WiFiMulti WiFiMulti; #elif defined(ESP32) #include @@ -20,7 +20,6 @@ #endif #include - #include WebSocketsClient webSocket; From f62aa6478d8b329945746310421b54ddf84b40b7 Mon Sep 17 00:00:00 2001 From: Links Date: Tue, 6 Feb 2018 21:36:44 +0100 Subject: [PATCH 18/26] more ESP32 stuff --- examples/WebSocketClient/WebSocketClient.ino | 7 ++----- src/WebSockets.h | 6 +++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/examples/WebSocketClient/WebSocketClient.ino b/examples/WebSocketClient/WebSocketClient.ino index 4dad8e5..fe602aa 100644 --- a/examples/WebSocketClient/WebSocketClient.ino +++ b/examples/WebSocketClient/WebSocketClient.ino @@ -14,22 +14,20 @@ #elif defined(ESP32) #include #include + #include WiFiMulti WiFiMulti; HardwareSerial Serial1(2); #endif #include + #include WebSocketsClient webSocket; #define USE_SERIAL Serial1 -#ifndef ESP8266 -void hexdump(const void *mem, uint32_t len, uint8_t cols = 16); -#endif - void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { switch(type) { @@ -103,7 +101,6 @@ void loop() { } - #ifndef ESP8266 void hexdump(const void *mem, uint32_t len, uint8_t cols) { const uint8_t* src = (const uint8_t*) mem; diff --git a/src/WebSockets.h b/src/WebSockets.h index a10aab9..c63bb5e 100644 --- a/src/WebSockets.h +++ b/src/WebSockets.h @@ -48,7 +48,7 @@ #define NODEBUG_WEBSOCKETS #endif -#ifdef ESP8266 +#if defined(ESP8266) || defined(ESP32) #define WEBSOCKETS_MAX_DATA_SIZE (15*1024) #define WEBSOCKETS_USE_BIG_MEM #define GET_FREE_HEAP ESP.getFreeHeap() @@ -78,7 +78,7 @@ // max size of the WS Message Header #define WEBSOCKETS_MAX_HEADER_SIZE (14) -#if !defined(WEBSOCKETS_NETWORK_TYPE) +#if !defined(WEBSOCKETS_NETWORK_TYPE) // select Network type based #if defined(ESP8266) || defined(ESP31B) #define WEBSOCKETS_NETWORK_TYPE NETWORK_ESP8266 @@ -97,7 +97,7 @@ // No SSL/WSS support for client in Async mode // TLS lib need a sync interface! -#if !defined(ESP8266) && !defined(ESP31B) +#if !defined(ESP8266) && !defined(ESP31B) && !defined(ESP32) #error "network type ESP8266 ASYNC only possible on the ESP mcu!" #endif From d73e3ecc9c4f2a1c121703c488dbe5f40ec74930 Mon Sep 17 00:00:00 2001 From: Links Date: Tue, 6 Feb 2018 21:37:24 +0100 Subject: [PATCH 19/26] skip some test for ESP32 --- examples/ParticleWebSocketClient/.esp32.skip | 0 examples/WebSocketClientAVR/.esp32.skip | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 examples/ParticleWebSocketClient/.esp32.skip create mode 100644 examples/WebSocketClientAVR/.esp32.skip diff --git a/examples/ParticleWebSocketClient/.esp32.skip b/examples/ParticleWebSocketClient/.esp32.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/WebSocketClientAVR/.esp32.skip b/examples/WebSocketClientAVR/.esp32.skip new file mode 100644 index 0000000..e69de29 From 86074c90aea6c5b9a6e8728a9240f876fbbff02a Mon Sep 17 00:00:00 2001 From: Links Date: Tue, 6 Feb 2018 21:41:47 +0100 Subject: [PATCH 20/26] update IDE test --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f24935f..9ccd59e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ os: env: global: - IDE_VERSION=1.6.5 + - IDE_VERSION=1.8.5 matrix: - CPU="esp8266" BOARD="esp8266com:esp8266:generic" - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" From 2df62558f1bc0dcef29ea79fa7ad78cd4797a065 Mon Sep 17 00:00:00 2001 From: Links Date: Tue, 6 Feb 2018 21:48:49 +0100 Subject: [PATCH 21/26] more verbose verify step --- travis/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis/common.sh b/travis/common.sh index 10237bb..062ba05 100644 --- a/travis/common.sh +++ b/travis/common.sh @@ -13,7 +13,7 @@ function build_sketches() continue fi echo -e "\n\n ------------ Building $sketch ------------ \n\n"; - $arduino --verify $sketch; + $arduino --verify --verbose $sketch; local result=$? if [ $result -ne 0 ]; then echo "Build failed ($1)" From 94eb4b12e5de0f803b350e883001c200667c3a57 Mon Sep 17 00:00:00 2001 From: Links Date: Tue, 6 Feb 2018 21:52:13 +0100 Subject: [PATCH 22/26] IDE version --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9ccd59e..a555767 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,7 @@ os: - linux env: global: - - IDE_VERSION=1.6.5 - - IDE_VERSION=1.8.5 + - IDE_VERSION=1.8.2 matrix: - CPU="esp8266" BOARD="esp8266com:esp8266:generic" - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" From a09b8c48ee465b317cff93ff9514154247025837 Mon Sep 17 00:00:00 2001 From: Links Date: Tue, 6 Feb 2018 21:58:26 +0100 Subject: [PATCH 23/26] ide version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a555767..f24935f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ os: - linux env: global: - - IDE_VERSION=1.8.2 + - IDE_VERSION=1.6.5 matrix: - CPU="esp8266" BOARD="esp8266com:esp8266:generic" - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" From b059d0711c5771e0fbfa24cd2e736ffb7888599b Mon Sep 17 00:00:00 2001 From: Links Date: Wed, 7 Feb 2018 17:28:17 +0100 Subject: [PATCH 24/26] sort examples by platform rework the travis tests create ESP32 examples --- .travis.yml | 11 +- examples/ParticleWebSocketClient/.esp32.skip | 0 .../ParticleWebSocketClient/.esp8266.skip | 0 examples/WebSocketClientAVR/.esp32.skip | 0 examples/WebSocketClientAVR/.esp8266.skip | 0 .../WebSocketClientAVR/WebSocketClientAVR.ino | 0 .../WebSocketClient/WebSocketClient.ino | 51 ++++----- .../WebSocketClientSSL/WebSocketClientSSL.ino | 102 ++++++++++++++++++ .../WebSocketServer/WebSocketServer.ino | 51 ++++----- .../WebSocketClient/WebSocketClient.ino | 92 ++++++++++++++++ .../WebSocketClientSSL/WebSocketClientSSL.ino | 0 .../WebSocketClientSocketIO.ino | 0 .../WebSocketClientStomp.ino | 0 .../WebSocketClientStompOverSockJs.ino | 0 .../WebSocketServer/WebSocketServer.ino | 86 +++++++++++++++ .../WebSocketServerFragmentation.ino | 0 .../WebSocketServerHttpHeaderValidation.ino | 0 .../WebSocketServer_LEDcontrol.ino | 1 - .../ParticleWebSocketClient/application.cpp | 0 src/WebSockets.h | 30 ++++-- travis/common.sh | 9 +- 21 files changed, 352 insertions(+), 81 deletions(-) delete mode 100644 examples/ParticleWebSocketClient/.esp32.skip delete mode 100644 examples/ParticleWebSocketClient/.esp8266.skip delete mode 100644 examples/WebSocketClientAVR/.esp32.skip delete mode 100644 examples/WebSocketClientAVR/.esp8266.skip rename examples/{ => avr}/WebSocketClientAVR/WebSocketClientAVR.ino (100%) rename examples/{ => esp32}/WebSocketClient/WebSocketClient.ino (80%) create mode 100644 examples/esp32/WebSocketClientSSL/WebSocketClientSSL.ino rename examples/{ => esp32}/WebSocketServer/WebSocketServer.ino (78%) create mode 100644 examples/esp8266/WebSocketClient/WebSocketClient.ino rename examples/{ => esp8266}/WebSocketClientSSL/WebSocketClientSSL.ino (100%) rename examples/{ => esp8266}/WebSocketClientSocketIO/WebSocketClientSocketIO.ino (100%) rename examples/{ => esp8266}/WebSocketClientStomp/WebSocketClientStomp.ino (100%) rename examples/{ => esp8266}/WebSocketClientStompOverSockJs/WebSocketClientStompOverSockJs.ino (100%) create mode 100644 examples/esp8266/WebSocketServer/WebSocketServer.ino rename examples/{ => esp8266}/WebSocketServerFragmentation/WebSocketServerFragmentation.ino (100%) rename examples/{ => esp8266}/WebSocketServerHttpHeaderValidation/WebSocketServerHttpHeaderValidation.ino (100%) rename examples/{ => esp8266}/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino (96%) rename examples/{ => particle}/ParticleWebSocketClient/application.cpp (100%) diff --git a/.travis.yml b/.travis.yml index f24935f..b15fc0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,11 +3,12 @@ language: bash os: - linux env: - global: - - IDE_VERSION=1.6.5 matrix: - - CPU="esp8266" BOARD="esp8266com:esp8266:generic" - - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" + - CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80" IDE_VERSION=1.6.5 + - CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80" IDE_VERSION=1.8.5 + - CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80,Debug=Serial1" IDE_VERSION=1.6.5 + - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" IDE_VERSION=1.6.5 + - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" IDE_VERSION=1.8.5 script: - /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16 @@ -25,7 +26,7 @@ script: - cd $TRAVIS_BUILD_DIR - arduino --board $BOARD --save-prefs - arduino --get-pref sketchbook.path - - build_sketches arduino $HOME/Arduino/libraries/arduinoWebSockets $CPU + - build_sketches arduino $HOME/Arduino/libraries/arduinoWebSockets/examples/$CPU $CPU notifications: email: diff --git a/examples/ParticleWebSocketClient/.esp32.skip b/examples/ParticleWebSocketClient/.esp32.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/ParticleWebSocketClient/.esp8266.skip b/examples/ParticleWebSocketClient/.esp8266.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/WebSocketClientAVR/.esp32.skip b/examples/WebSocketClientAVR/.esp32.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/WebSocketClientAVR/.esp8266.skip b/examples/WebSocketClientAVR/.esp8266.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/WebSocketClientAVR/WebSocketClientAVR.ino b/examples/avr/WebSocketClientAVR/WebSocketClientAVR.ino similarity index 100% rename from examples/WebSocketClientAVR/WebSocketClientAVR.ino rename to examples/avr/WebSocketClientAVR/WebSocketClientAVR.ino diff --git a/examples/WebSocketClient/WebSocketClient.ino b/examples/esp32/WebSocketClient/WebSocketClient.ino similarity index 80% rename from examples/WebSocketClient/WebSocketClient.ino rename to examples/esp32/WebSocketClient/WebSocketClient.ino index fe602aa..7483b6b 100644 --- a/examples/WebSocketClient/WebSocketClient.ino +++ b/examples/esp32/WebSocketClient/WebSocketClient.ino @@ -7,39 +7,44 @@ #include -#if defined(ESP8266) - #include - #include - ESP8266WiFiMulti WiFiMulti; -#elif defined(ESP32) - #include - #include - #include - WiFiMulti WiFiMulti; - - HardwareSerial Serial1(2); -#endif +#include +#include +#include #include -#include +WiFiMulti WiFiMulti; WebSocketsClient webSocket; +HardwareSerial Serial1(2); + #define USE_SERIAL Serial1 +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: { + 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); @@ -99,19 +104,3 @@ void setup() { void loop() { webSocket.loop(); } - - -#ifndef ESP8266 -void hexdump(const void *mem, uint32_t len, uint8_t cols) { - 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"); -} -#endif diff --git a/examples/esp32/WebSocketClientSSL/WebSocketClientSSL.ino b/examples/esp32/WebSocketClientSSL/WebSocketClientSSL.ino new file mode 100644 index 0000000..5b4f3a5 --- /dev/null +++ b/examples/esp32/WebSocketClientSSL/WebSocketClientSSL.ino @@ -0,0 +1,102 @@ +/* + * WebSocketClientSSL.ino + * + * Created on: 10.12.2015 + * + * note SSL is only possible with the ESP8266 + * + */ + +#include + +#include +#include +#include + +#include + + +WiFiMulti WiFiMulti; +WebSocketsClient webSocket; + +HardwareSerial Serial1(2); + +#define USE_SERIAL Serial1 + +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; + } + +} + +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.beginSSL("192.168.0.123", 81); + webSocket.onEvent(webSocketEvent); + +} + +void loop() { + webSocket.loop(); +} diff --git a/examples/WebSocketServer/WebSocketServer.ino b/examples/esp32/WebSocketServer/WebSocketServer.ino similarity index 78% rename from examples/WebSocketServer/WebSocketServer.ino rename to examples/esp32/WebSocketServer/WebSocketServer.ino index de9c63e..da7d38f 100644 --- a/examples/WebSocketServer/WebSocketServer.ino +++ b/examples/esp32/WebSocketServer/WebSocketServer.ino @@ -7,31 +7,31 @@ #include -#if defined(ESP8266) - #include #include - #include #include - ESP8266WiFiMulti WiFiMulti; -#elif defined(ESP32) - #include - #include - WiFiMulti WiFiMulti; - - HardwareSerial Serial1(2); -#endif +#include +#include +#include #include -#include - -ESP8266WiFiMulti WiFiMulti; +WiFiMulti WiFiMulti; WebSocketsServer webSocket = WebSocketsServer(81); +HardwareSerial Serial1(2); + #define USE_SERIAL Serial1 - -#ifndef ESP8266 -void hexdump(const void *mem, uint32_t len, uint8_t cols = 16); -#endif +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(uint8_t num, WStype_t type, uint8_t * payload, size_t length) { @@ -98,18 +98,3 @@ void setup() { void loop() { webSocket.loop(); } - -#ifndef ESP8266 -void hexdump(const void *mem, uint32_t len, uint8_t cols) { - 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"); -} -#endif diff --git a/examples/esp8266/WebSocketClient/WebSocketClient.ino b/examples/esp8266/WebSocketClient/WebSocketClient.ino new file mode 100644 index 0000000..3ce8498 --- /dev/null +++ b/examples/esp8266/WebSocketClient/WebSocketClient.ino @@ -0,0 +1,92 @@ +/* + * WebSocketClient.ino + * + * Created on: 24.05.2015 + * + */ + +#include + +#include +#include + +#include + +#include + +ESP8266WiFiMulti WiFiMulti; +WebSocketsClient webSocket; + +#define USE_SERIAL Serial1 + +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; + } + +} + +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); + } + + // server address, port and URL + webSocket.begin("192.168.0.123", 81, "/"); + + // event handler + webSocket.onEvent(webSocketEvent); + + // use HTTP Basic Authorization this is optional remove if not needed + webSocket.setAuthorization("user", "Password"); + + // try ever 5000 again if connection has failed + webSocket.setReconnectInterval(5000); + +} + +void loop() { + webSocket.loop(); +} diff --git a/examples/WebSocketClientSSL/WebSocketClientSSL.ino b/examples/esp8266/WebSocketClientSSL/WebSocketClientSSL.ino similarity index 100% rename from examples/WebSocketClientSSL/WebSocketClientSSL.ino rename to examples/esp8266/WebSocketClientSSL/WebSocketClientSSL.ino diff --git a/examples/WebSocketClientSocketIO/WebSocketClientSocketIO.ino b/examples/esp8266/WebSocketClientSocketIO/WebSocketClientSocketIO.ino similarity index 100% rename from examples/WebSocketClientSocketIO/WebSocketClientSocketIO.ino rename to examples/esp8266/WebSocketClientSocketIO/WebSocketClientSocketIO.ino diff --git a/examples/WebSocketClientStomp/WebSocketClientStomp.ino b/examples/esp8266/WebSocketClientStomp/WebSocketClientStomp.ino similarity index 100% rename from examples/WebSocketClientStomp/WebSocketClientStomp.ino rename to examples/esp8266/WebSocketClientStomp/WebSocketClientStomp.ino diff --git a/examples/WebSocketClientStompOverSockJs/WebSocketClientStompOverSockJs.ino b/examples/esp8266/WebSocketClientStompOverSockJs/WebSocketClientStompOverSockJs.ino similarity index 100% rename from examples/WebSocketClientStompOverSockJs/WebSocketClientStompOverSockJs.ino rename to examples/esp8266/WebSocketClientStompOverSockJs/WebSocketClientStompOverSockJs.ino diff --git a/examples/esp8266/WebSocketServer/WebSocketServer.ino b/examples/esp8266/WebSocketServer/WebSocketServer.ino new file mode 100644 index 0000000..5e266a2 --- /dev/null +++ b/examples/esp8266/WebSocketServer/WebSocketServer.ino @@ -0,0 +1,86 @@ +/* + * WebSocketServer.ino + * + * Created on: 22.05.2015 + * + */ + +#include + +#include +#include +#include +#include + +ESP8266WiFiMulti WiFiMulti; + +WebSocketsServer webSocket = WebSocketsServer(81); + +#define USE_SERIAL Serial1 + +void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) { + + switch(type) { + case WStype_DISCONNECTED: + USE_SERIAL.printf("[%u] Disconnected!\n", num); + break; + case WStype_CONNECTED: + { + IPAddress ip = webSocket.remoteIP(num); + USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload); + + // send message to client + webSocket.sendTXT(num, "Connected"); + } + break; + case WStype_TEXT: + USE_SERIAL.printf("[%u] get Text: %s\n", num, payload); + + // send message to client + // webSocket.sendTXT(num, "message here"); + + // send data to all connected clients + // webSocket.broadcastTXT("message here"); + break; + case WStype_BIN: + USE_SERIAL.printf("[%u] get binary length: %u\n", num, length); + hexdump(payload, length); + + // send message to client + // webSocket.sendBIN(num, 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"); + + while(WiFiMulti.run() != WL_CONNECTED) { + delay(100); + } + + webSocket.begin(); + webSocket.onEvent(webSocketEvent); +} + +void loop() { + webSocket.loop(); +} + diff --git a/examples/WebSocketServerFragmentation/WebSocketServerFragmentation.ino b/examples/esp8266/WebSocketServerFragmentation/WebSocketServerFragmentation.ino similarity index 100% rename from examples/WebSocketServerFragmentation/WebSocketServerFragmentation.ino rename to examples/esp8266/WebSocketServerFragmentation/WebSocketServerFragmentation.ino diff --git a/examples/WebSocketServerHttpHeaderValidation/WebSocketServerHttpHeaderValidation.ino b/examples/esp8266/WebSocketServerHttpHeaderValidation/WebSocketServerHttpHeaderValidation.ino similarity index 100% rename from examples/WebSocketServerHttpHeaderValidation/WebSocketServerHttpHeaderValidation.ino rename to examples/esp8266/WebSocketServerHttpHeaderValidation/WebSocketServerHttpHeaderValidation.ino diff --git a/examples/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino b/examples/esp8266/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino similarity index 96% rename from examples/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino rename to examples/esp8266/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino index 913b799..7915409 100644 --- a/examples/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino +++ b/examples/esp8266/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino @@ -119,4 +119,3 @@ void loop() { webSocket.loop(); server.handleClient(); } - diff --git a/examples/ParticleWebSocketClient/application.cpp b/examples/particle/ParticleWebSocketClient/application.cpp similarity index 100% rename from examples/ParticleWebSocketClient/application.cpp rename to examples/particle/ParticleWebSocketClient/application.cpp diff --git a/src/WebSockets.h b/src/WebSockets.h index c63bb5e..0d930f7 100644 --- a/src/WebSockets.h +++ b/src/WebSockets.h @@ -49,23 +49,28 @@ #endif #if defined(ESP8266) || defined(ESP32) + #define WEBSOCKETS_MAX_DATA_SIZE (15*1024) #define WEBSOCKETS_USE_BIG_MEM #define GET_FREE_HEAP ESP.getFreeHeap() // moves all Header strings to Flash (~300 Byte) //#define WEBSOCKETS_SAVE_RAM -#else -#ifdef STM32_DEVICE + +#elif defined(STM32_DEVICE) + #define WEBSOCKETS_MAX_DATA_SIZE (15*1024) #define WEBSOCKETS_USE_BIG_MEM #define GET_FREE_HEAP System.freeMemory() + #else + //atmega328p has only 2KB ram! #define WEBSOCKETS_MAX_DATA_SIZE (1024) // moves all Header strings to Flash #define WEBSOCKETS_SAVE_RAM + #endif -#endif + #define WEBSOCKETS_TCP_TIMEOUT (2000) @@ -84,28 +89,35 @@ #define WEBSOCKETS_NETWORK_TYPE NETWORK_ESP8266 //#define WEBSOCKETS_NETWORK_TYPE NETWORK_ESP8266_ASYNC //#define WEBSOCKETS_NETWORK_TYPE NETWORK_W5100 + #elif defined(ESP32) #define WEBSOCKETS_NETWORK_TYPE NETWORK_ESP32 + #else #define WEBSOCKETS_NETWORK_TYPE NETWORK_W5100 + #endif #endif +// Includes and defined based on Network Type #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) // Note: // No SSL/WSS support for client in Async mode // TLS lib need a sync interface! -#if !defined(ESP8266) && !defined(ESP31B) && !defined(ESP32) + +#if defined(ESP8266) +#include +#elif defined(ESP32) +#include +#include +#elif defined(ESP31B) +#include +#else #error "network type ESP8266 ASYNC only possible on the ESP mcu!" #endif -#ifdef ESP8266 -#include -#else -#include -#endif #include #include #define WEBSOCKETS_NETWORK_CLASS AsyncTCPbuffer diff --git a/travis/common.sh b/travis/common.sh index 062ba05..be959fa 100644 --- a/travis/common.sh +++ b/travis/common.sh @@ -13,10 +13,15 @@ function build_sketches() continue fi echo -e "\n\n ------------ Building $sketch ------------ \n\n"; - $arduino --verify --verbose $sketch; + $arduino --verify $sketch; local result=$? if [ $result -ne 0 ]; then - echo "Build failed ($1)" + echo "Build failed ($sketch) build verbose..." + $arduino --verify --verbose --preserve-temp-files $sketch + result=$? + fi + if [ $result -ne 0 ]; then + echo "Build failed ($1) $sketch" return $result fi done From 48e690a42af2a94aaeb47fa000a37578765db628 Mon Sep 17 00:00:00 2001 From: Links Date: Wed, 7 Feb 2018 18:11:08 +0100 Subject: [PATCH 25/26] bump version to 2.1.0 travis arduino 1.8.5 --- .travis.yml | 2 +- README.md | 3 ++- library.json | 2 +- library.properties | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index b15fc0d..8e4397d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ os: env: matrix: - CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80" IDE_VERSION=1.6.5 - - CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80" IDE_VERSION=1.8.5 + - CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80,FlashSize=1M0" IDE_VERSION=1.8.5 - CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80,Debug=Serial1" IDE_VERSION=1.6.5 - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" IDE_VERSION=1.6.5 - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" IDE_VERSION=1.8.5 diff --git a/README.md b/README.md index 0c49b48..81b4107 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,8 @@ a WebSocket Server and Client for Arduino based on RFC6455. - wss / SSL is not possible. ##### Supported Hardware ##### - - ESP8266 [Arduino for ESP8266](https://github.com/Links2004/Arduino) + - ESP8266 [Arduino for ESP8266](https://github.com/esp8266/Arduino/) + - ESP32 [Arduino for ESP32](https://github.com/espressif/arduino-esp32) - ESP31B - Particle with STM32 ARM Cortex M3 - ATmega328 with Ethernet Shield (ATmega branch) diff --git a/library.json b/library.json index 35289fc..a019efb 100644 --- a/library.json +++ b/library.json @@ -13,7 +13,7 @@ "type": "git", "url": "https://github.com/Links2004/arduinoWebSockets.git" }, - "version": "2.0.10", + "version": "2.1.0", "license": "LGPL-2.1", "export": { "exclude": [ diff --git a/library.properties b/library.properties index 6ae767e..14e1fe9 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WebSockets -version=2.0.10 +version=2.1.0 author=Markus Sattler maintainer=Markus Sattler sentence=WebSockets for Arduino (Server + Client) From 4759a66a62f86911b2eb0d19080d0cea54aadbad Mon Sep 17 00:00:00 2001 From: Links Date: Wed, 7 Feb 2018 18:15:50 +0100 Subject: [PATCH 26/26] Arduino 1.8.5 is very peaky with the board parameters --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8e4397d..14693dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ os: env: matrix: - CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80" IDE_VERSION=1.6.5 - - CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80,FlashSize=1M0" IDE_VERSION=1.8.5 + - CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80,FlashSize=1M0,FlashMode=qio,FlashFreq=80" IDE_VERSION=1.8.5 - CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80,Debug=Serial1" IDE_VERSION=1.6.5 - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" IDE_VERSION=1.6.5 - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" IDE_VERSION=1.8.5