From 4b56b009c7ae3661043fcf633bc924d5b8feb9a6 Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Wed, 23 Nov 2022 17:06:13 -0500 Subject: [PATCH] Update `README.md` and use `allman` astyle --- CONTRIBUTING.md | 2 +- README.md | 51 +- changelog.md | 8 +- .../AsyncCustomHeader_STM32.ino | 132 +-- examples/AsyncCustomHeader_STM32/defines.h | 102 +-- .../AsyncDweetGet_STM32.ino | 178 ++-- examples/AsyncDweetGet_STM32/defines.h | 102 +-- .../AsyncDweetPost_STM32.ino | 184 ++-- examples/AsyncDweetPost_STM32/defines.h | 102 +-- .../AsyncHTTPMultiRequests_ESP.ino | 172 ++-- .../AsyncHTTPRequest_ESP.ino | 142 +-- .../AsyncHTTPRequest_ESP8266_Ethernet.ino | 198 ++-- .../AsyncHTTPRequest_ESP_Multi.ino | 212 ++--- .../AsyncHTTPRequest_ESP_WiFiManager.ino | 866 +++++++++--------- .../AsyncHTTPRequest_STM32.ino | 116 +-- examples/AsyncHTTPRequest_STM32/defines.h | 102 +-- .../AsyncSimpleGET_STM32.ino | 114 +-- examples/AsyncSimpleGET_STM32/defines.h | 102 +-- .../AsyncWebClientRepeating_STM32.ino | 112 +-- .../AsyncWebClientRepeating_STM32/defines.h | 102 +-- .../AsyncHTTPMultiRequests_WT32_ETH01.ino | 178 ++-- .../AsyncHTTPRequest_WT32_ETH01.ino | 160 ++-- .../multiFileProject/multiFileProject.ino | 20 +- platformio/platformio.ini | 2 +- 24 files changed, 1738 insertions(+), 1721 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 07a0f1f..1d85a1a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,7 +29,7 @@ Please ensure to specify the following: Arduino IDE version: 1.8.19 ESP32 Core Version 2.0.5 OS: Ubuntu 20.04 LTS -Linux xy-Inspiron-3593 5.15.0-52-generic #58~20.04.1-Ubuntu SMP Thu Oct 13 13:09:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux +Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux Context: I encountered a crash while using this library diff --git a/README.md b/README.md index e6fc3ad..437a74f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# AsyncHTTPRequest_Generic +# AsyncHTTPRequest_Generic Library [![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncHTTPRequest_Generic.svg?)](https://www.ardu-badge.com/AsyncHTTPRequest_Generic) [![GitHub release](https://img.shields.io/github/release/khoih-prog/AsyncHTTPRequest_Generic.svg)](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/releases) @@ -6,8 +6,11 @@ [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) [![GitHub issues](https://img.shields.io/github/issues/khoih-prog/AsyncHTTPRequest_Generic.svg)](http://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues) + Donate to my libraries using BuyMeACoffee + + --- --- @@ -212,18 +215,22 @@ The best and easiest way is to use `Arduino Library Manager`. Search for `AsyncH #### 1. For STM32 boards to use LAN8720 +For `Generic STM32F4 series` boards, such as `STM32F407VE`, using `LAN8720`, please use STM32 core `v2.2.0` as breaking core `v2.3.0` creates the compile error. + +--- + To use LAN8720 on some STM32 boards - **Nucleo-144 (F429ZI, NUCLEO_F746NG, NUCLEO_F746ZG, NUCLEO_F756ZG)** - **Discovery (DISCO_F746NG)** - **STM32F4 boards (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE_Mini, DIYMORE_F407VGT, FK407M1)** -you have to copy the files [stm32f4xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.3.0/system/STM32F4xx) and [stm32f7xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.3.0/system/STM32F7xx) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.3.0/system) to overwrite the old files. +you have to copy the files [stm32f4xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.2.0/system/STM32F4xx) and [stm32f7xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.2.0/system/STM32F7xx) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system) to overwrite the old files. -Supposing the STM32 stm32 core version is 2.3.0. These files must be copied into the directory: +Supposing the STM32 stm32 core version is 2.2.0. These files must be copied into the directory: -- `~/.arduino15/packages/STM32/hardware/stm32/2.3.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h` for STM32F4. -- `~/.arduino15/packages/STM32/hardware/stm32/2.3.0/system/STM32F7xx/stm32f7xx_hal_conf_default.h` for Nucleo-144 STM32F7. +- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h` for STM32F4. +- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system/STM32F7xx/stm32f7xx_hal_conf_default.h` for Nucleo-144 STM32F7. Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, these files must be copied into the corresponding directory: @@ -238,14 +245,14 @@ these files must be copied into the corresponding directory: Supposing the STM32 stm32 core version is 2.3.0. These files must be copied into the directory: -- `~/.arduino15/packages/STM32/hardware/stm32/2.3.0/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h` for Nucleo-144 NUCLEO_F767ZI. -- `~/.arduino15/packages/STM32/hardware/stm32/2.3.0/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h` for Nucleo-64 NUCLEO_L053R8. +- `~/.arduino15/packages/STM32/hardware/stm32/2.3.0/variants/NUCLEO_F767ZI/variant.h` for Nucleo-144 NUCLEO_F767ZI. +- `~/.arduino15/packages/STM32/hardware/stm32/2.3.0/variants/NUCLEO_L053R8/variant.h` for Nucleo-64 NUCLEO_L053R8. Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, these files must be copied into the corresponding directory: -- `~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h` -- `~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h` +- `~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/variants/NUCLEO_F767ZI/variant.h` +- `~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/variants/NUCLEO_L053R8/variant.h` --- --- @@ -402,7 +409,7 @@ Connect as follows. To program, use **STM32CubeProgrammer** or Arduino IDE with

- +

--- @@ -495,7 +502,7 @@ https://github.com/khoih-prog/AsyncHTTPRequest_Generic/blob/639ce917e54c296f15fd #### 1. [AsyncHTTPRequest_STM32](examples/AsyncHTTPRequest_STM32) running on STM32F7 Nucleo-144 NUCLEO_F767ZI using built-in LAN8742A -``` +```cpp Start AsyncHTTPRequest_STM32 on NUCLEO_F767ZI AsyncHTTPRequest_Generic v1.10.2 AsyncHTTPRequest @ IP : 192.168.2.178 @@ -540,7 +547,7 @@ week_number: 42 #### 2. [AsyncHTTPRequest_ESP_WiFiManager](examples/AsyncHTTPRequest_ESP_WiFiManager) running on ESP8266_NODEMCU -``` +```cpp Starting AsyncHTTPRequest_ESP_WiFiManager using LittleFS on ESP8266_NODEMCU AsyncHTTPRequest_Generic v1.10.2 Stored: SSID = HueNet1, Pass = 12345678 @@ -572,7 +579,7 @@ HHHHHH #### 3. [AsyncHTTPRequest_ESP_WiFiManager](examples/AsyncHTTPRequest_ESP_WiFiManager) running on ESP32_DEV -``` +```cpp Starting AsyncHTTPRequest_ESP_WiFiManager using SPIFFS on ESP32_DEV AsyncHTTPRequest_Generic v1.10.2 Stored: SSID = HueNet1, Pass = 12345678 @@ -622,7 +629,7 @@ HHHHHHHHH HHHHHHHHHH HHHHHHHHHH #### 4. [AsyncHTTPRequest_ESP](examples/AsyncHTTPRequest_ESP) running on ESP8266_NODEMCU -``` +```cpp Starting AsyncHTTPRequest_ESP using ESP8266_NODEMCU AsyncHTTPRequest_Generic v1.10.2 Connecting to WiFi SSID: HueNet1 @@ -654,7 +661,7 @@ HHHHHHHHH HHHHHHHHHH HHHHHHHHHH H #### 5. [AsyncWebClientRepeating_STM32](examples/AsyncWebClientRepeating_STM32) running on STM32F7 Nucleo-144 NUCLEO_F767ZI using built-in LAN8742A -``` +```cpp Start AsyncWebClientRepeating_STM32 on NUCLEO_F767ZI AsyncHTTPRequest_Generic v1.10.2 AsyncHTTPRequest @ IP : 192.168.2.72 @@ -707,7 +714,7 @@ AsyncHTTPRequest @ IP : 192.168.2.72 #### 6. [AsyncHTTPRequest_WT32_ETH01](examples/WT32_ETH01/AsyncHTTPRequest_WT32_ETH01) on ESP32_DEV with ETH_PHY_LAN8720 -``` +```cpp Starting AsyncHTTPRequest_WT32_ETH01 on ESP32_DEV with ETH_PHY_LAN8720 WebServer_WT32_ETH01 v1.5.1 AsyncHTTPRequest_Generic v1.10.2 @@ -737,7 +744,7 @@ week_number: 45 #### 7. [AsyncHTTPRequest_ESP_WiFiManager](examples/AsyncHTTPRequest_ESP_WiFiManager) running on ESP32C3_DEV -``` +```cpp Starting AsyncHTTPRequest_ESP_WiFiManager using LittleFS on ESP32C3_DEV ESPAsync_WiFiManager v1.15.0 AsyncHTTPRequest_Generic v1.10.2 @@ -788,7 +795,7 @@ week_number: 45 #### 8. [AsyncHTTPRequest_ESP_WiFiManager](examples/AsyncHTTPRequest_ESP_WiFiManager) running on ESP32S3_DEV -``` +```cpp Starting AsyncHTTPRequest_ESP_WiFiManager using LittleFS on ESP32S3_DEV ESPAsync_WiFiManager v1.15.0 AsyncHTTPRequest_Generic v1.10.2 @@ -841,7 +848,7 @@ week_number: 45 The terminal output of [AsyncHTTPRequest_ESP_Multi example](examples/AsyncHTTPRequest_ESP_Multi) running on `ESP32_DEV` to demonstrate how to send requests to multiple addresses and receive responses from them. -``` +```cpp Starting AsyncHTTPRequest_ESP_Multi using ESP32_DEV AsyncHTTPRequest_Generic v1.10.2 Connecting to WiFi SSID: HueNet1 @@ -902,7 +909,7 @@ HHH The terminal output of [AsyncHTTPRequest_ESP8266_Ethernet example](examples/AsyncHTTPRequest_ESP8266_Ethernet) running on `ESP8266_NODEMCU_ESP12E` to demonstrate how to use ESP8266_W5500 Ethernet Async feature. -``` +```cpp Starting AsyncHTTPRequest_ESP8266_Ethernet on ESP8266_NODEMCU_ESP12E using ESP8266_W5500 Ethernet AsyncHTTPRequest_Generic v1.10.2 Connecting ethernet.. @@ -952,7 +959,7 @@ HH The terminal output of [AsyncHTTPRequest_ESP8266_Ethernet example](examples/AsyncHTTPRequest_ESP8266_Ethernet) running on `ESP8266_NODEMCU_ESP12E` to demonstrate how to use ESP8266_ENC28J60 Ethernet Async feature. -``` +```cpp Starting AsyncHTTPRequest_ESP8266_Ethernet on ESP8266_NODEMCU_ESP12E using ESP8266_ENC28J60 Ethernet AsyncHTTPRequest_Generic v1.10.2 Connecting to network : .......................................................... @@ -1124,7 +1131,7 @@ If you want to contribute to this project: Copyright (C) <2018> -Copyright 2020- Khoi Hoang +Copyright (C) 2020- Khoi Hoang diff --git a/changelog.md b/changelog.md index 407c770..64cbc3d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,4 @@ -# AsyncHTTPRequest_Generic +# AsyncHTTPRequest_Generic Library [![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncHTTPRequest_Generic.svg?)](https://www.ardu-badge.com/AsyncHTTPRequest_Generic) [![GitHub release](https://img.shields.io/github/release/khoih-prog/AsyncHTTPRequest_Generic.svg)](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/releases) @@ -6,6 +6,12 @@ [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) [![GitHub issues](https://img.shields.io/github/issues/khoih-prog/AsyncHTTPRequest_Generic.svg)](http://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues) + +Donate to my libraries using BuyMeACoffee + + + + --- --- diff --git a/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino b/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino index ba535ef..82d4b21 100644 --- a/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino +++ b/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino @@ -47,102 +47,102 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS); void sendRequest(void) { - static bool requestOpenResult; + static bool requestOpenResult; - if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) - { - Serial.println("\nSending GET Request to " + String(GET_ServerAddress)); + if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) + { + Serial.println("\nSending GET Request to " + String(GET_ServerAddress)); - requestOpenResult = request.open("GET", GET_ServerAddress); + requestOpenResult = request.open("GET", GET_ServerAddress); - //request.setReqHeader("X-CUSTOM-HEADER", "custom_value"); - if (requestOpenResult) - { - // Only send() if open() returns true, or crash - request.send(); - } - else - { - Serial.println("Can't send bad request"); - } - } - else - { - Serial.println("Can't send request"); - } + //request.setReqHeader("X-CUSTOM-HEADER", "custom_value"); + if (requestOpenResult) + { + // Only send() if open() returns true, or crash + request.send(); + } + else + { + Serial.println("Can't send bad request"); + } + } + else + { + Serial.println("Can't send request"); + } } void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState) { - (void) optParm; + (void) optParm; - if (readyState == readyStateDone) - { - Serial.println(); - AHTTP_LOGDEBUG(F("**************************************")); - AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); + if (readyState == readyStateDone) + { + Serial.println(); + AHTTP_LOGDEBUG(F("**************************************")); + AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); - if (request->responseHTTPcode() == 200) - { - Serial.println(F("**************************************")); - Serial.println(request->responseText()); - Serial.println(F("**************************************")); - } - else - { - AHTTP_LOGERROR(F("Response error")); - } - } + if (request->responseHTTPcode() == 200) + { + Serial.println(F("**************************************")); + Serial.println(request->responseText()); + Serial.println(F("**************************************")); + } + else + { + AHTTP_LOGERROR(F("Response error")); + } + } } void setup(void) { - Serial.begin(115200); + Serial.begin(115200); - while (!Serial && millis() < 5000); + while (!Serial && millis() < 5000); - Serial.print("\nStart AsyncCustomHeader_STM32 on "); - Serial.println(BOARD_NAME); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); + Serial.print("\nStart AsyncCustomHeader_STM32 on "); + Serial.println(BOARD_NAME); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); #if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - { - Serial.print("Warning. Must use this example on Version equal or later than : "); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); - } + if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) + { + Serial.print("Warning. Must use this example on Version equal or later than : "); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); + } #endif - // start the ethernet connection and the server - // Use random mac - uint16_t index = millis() % NUMBER_OF_MAC; + // start the ethernet connection and the server + // Use random mac + uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - // Use DHCP dynamic IP and random mac - Ethernet.begin(mac[index]); + // Use Static IP + //Ethernet.begin(mac[index], ip); + // Use DHCP dynamic IP and random mac + Ethernet.begin(mac[index]); - Serial.print(F("AsyncHTTPRequest @ IP : ")); - Serial.println(Ethernet.localIP()); - Serial.println(); + Serial.print(F("AsyncHTTPRequest @ IP : ")); + Serial.println(Ethernet.localIP()); + Serial.println(); - request.setDebug(false); + request.setDebug(false); - // 5s timeout - request.setTimeout(5); + // 5s timeout + request.setTimeout(5); - request.onReadyStateChange(requestCB); + request.onReadyStateChange(requestCB); - sendHTTPRequest.start(); //start the ticker. + sendHTTPRequest.start(); //start the ticker. - // Send first request now - delay(10000); - sendRequest(); + // Send first request now + delay(10000); + sendRequest(); } void loop(void) { - sendHTTPRequest.update(); + sendHTTPRequest.update(); } diff --git a/examples/AsyncCustomHeader_STM32/defines.h b/examples/AsyncCustomHeader_STM32/defines.h index 44a9364..fd7592b 100644 --- a/examples/AsyncCustomHeader_STM32/defines.h +++ b/examples/AsyncCustomHeader_STM32/defines.h @@ -46,54 +46,54 @@ #if defined(STM32F0) - #warning STM32F0 board selected - #define BOARD_TYPE "STM32F0" + #warning STM32F0 board selected + #define BOARD_TYPE "STM32F0" #elif defined(STM32F1) - #warning STM32F1 board selected - #define BOARD_TYPE "STM32F1" + #warning STM32F1 board selected + #define BOARD_TYPE "STM32F1" #elif defined(STM32F2) - #warning STM32F2 board selected - #define BOARD_TYPE "STM32F2" + #warning STM32F2 board selected + #define BOARD_TYPE "STM32F2" #elif defined(STM32F3) - #warning STM32F3 board selected - #define BOARD_TYPE "STM32F3" + #warning STM32F3 board selected + #define BOARD_TYPE "STM32F3" #elif defined(STM32F4) - #warning STM32F4 board selected - #define BOARD_TYPE "STM32F4" + #warning STM32F4 board selected + #define BOARD_TYPE "STM32F4" #elif defined(STM32F7) - #warning STM32F7 board selected - #define BOARD_TYPE "STM32F7" + #warning STM32F7 board selected + #define BOARD_TYPE "STM32F7" #elif defined(STM32L0) - #warning STM32L0 board selected - #define BOARD_TYPE "STM32L0" + #warning STM32L0 board selected + #define BOARD_TYPE "STM32L0" #elif defined(STM32L1) - #warning STM32L1 board selected - #define BOARD_TYPE "STM32L1" + #warning STM32L1 board selected + #define BOARD_TYPE "STM32L1" #elif defined(STM32L4) - #warning STM32L4 board selected - #define BOARD_TYPE "STM32L4" + #warning STM32L4 board selected + #define BOARD_TYPE "STM32L4" #elif defined(STM32H7) - #warning STM32H7 board selected - #define BOARD_TYPE "STM32H7" + #warning STM32H7 board selected + #define BOARD_TYPE "STM32H7" #elif defined(STM32G0) - #warning STM32G0 board selected - #define BOARD_TYPE "STM32G0" + #warning STM32G0 board selected + #define BOARD_TYPE "STM32G0" #elif defined(STM32G4) - #warning STM32G4 board selected - #define BOARD_TYPE "STM32G4" + #warning STM32G4 board selected + #define BOARD_TYPE "STM32G4" #elif defined(STM32WB) - #warning STM32WB board selected - #define BOARD_TYPE "STM32WB" + #warning STM32WB board selected + #define BOARD_TYPE "STM32WB" #elif defined(STM32MP1) - #warning STM32MP1 board selected - #define BOARD_TYPE "STM32MP1" + #warning STM32MP1 board selected + #define BOARD_TYPE "STM32MP1" #else - #warning STM32 unknown board selected - #define BOARD_TYPE "STM32 Unknown" + #warning STM32 unknown board selected + #define BOARD_TYPE "STM32 Unknown" #endif #ifndef BOARD_NAME - #define BOARD_NAME BOARD_TYPE + #define BOARD_NAME BOARD_TYPE #endif #include @@ -106,26 +106,26 @@ byte mac[][NUMBER_OF_MAC] = { - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, }; // Select the static IP address according to your local network diff --git a/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino b/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino index d00537d..fc6978f 100644 --- a/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino +++ b/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino @@ -61,132 +61,132 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS); void sendRequest(void) { - static bool requestOpenResult; + static bool requestOpenResult; - if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) - { - requestOpenResult = request.open("GET", (GET_ServerAddress + dweetName + String(millis() / 1000)).c_str() ); + if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) + { + requestOpenResult = request.open("GET", (GET_ServerAddress + dweetName + String(millis() / 1000)).c_str() ); - if (requestOpenResult) - { - // Only send() if open() returns true, or crash - request.send(); - } - else - { - Serial.println("Can't send bad request"); - } - } - else - { - Serial.println("Can't send request"); - } + if (requestOpenResult) + { + // Only send() if open() returns true, or crash + request.send(); + } + else + { + Serial.println("Can't send bad request"); + } + } + else + { + Serial.println("Can't send request"); + } } void parseResponse(String responseText) { - /* - Typical response is: - {"this":"succeeded", - "by":"getting", - "the":"dweets", - "with":[{"thing":"my-thing-name", - "created":"2016-02-16T05:10:36.589Z", - "content":{"sensorValue":456}}]} + /* + Typical response is: + {"this":"succeeded", + "by":"getting", + "the":"dweets", + "with":[{"thing":"my-thing-name", + "created":"2016-02-16T05:10:36.589Z", + "content":{"sensorValue":456}}]} - You want "content": numberValue - */ - // now parse the response looking for "content": - int labelStart = responseText.indexOf("content\":"); - // find the first { after "content": - int contentStart = responseText.indexOf("{", labelStart); - // find the following } and get what's between the braces: - int contentEnd = responseText.indexOf("}", labelStart); - String content = responseText.substring(contentStart + 1, contentEnd); + You want "content": numberValue + */ + // now parse the response looking for "content": + int labelStart = responseText.indexOf("content\":"); + // find the first { after "content": + int contentStart = responseText.indexOf("{", labelStart); + // find the following } and get what's between the braces: + int contentEnd = responseText.indexOf("}", labelStart); + String content = responseText.substring(contentStart + 1, contentEnd); - Serial.println(content); + Serial.println(content); - // now get the value after the colon, and convert to an int: - int valueStart = content.indexOf(":"); - String valueString = content.substring(valueStart + 1); - int number = valueString.toInt(); + // now get the value after the colon, and convert to an int: + int valueStart = content.indexOf(":"); + String valueString = content.substring(valueStart + 1); + int number = valueString.toInt(); - Serial.print("Value string: "); - Serial.println(valueString); - Serial.print("Actual value: "); - Serial.println(number); + Serial.print("Value string: "); + Serial.println(valueString); + Serial.print("Actual value: "); + Serial.println(number); } void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState) { - (void) optParm; + (void) optParm; - if (readyState == readyStateDone) - { - Serial.println(); - AHTTP_LOGDEBUG(F("**************************************")); - AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); + if (readyState == readyStateDone) + { + Serial.println(); + AHTTP_LOGDEBUG(F("**************************************")); + AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); - if (request->responseHTTPcode() == 200) - { - String responseText = request->responseText(); + if (request->responseHTTPcode() == 200) + { + String responseText = request->responseText(); - Serial.println("\n**************************************"); - //Serial.println(request->responseText()); - Serial.println(responseText); - Serial.println("**************************************"); + Serial.println("\n**************************************"); + //Serial.println(request->responseText()); + Serial.println(responseText); + Serial.println("**************************************"); - parseResponse(responseText); + parseResponse(responseText); - request->setDebug(false); - } - else - { - AHTTP_LOGERROR(F("Response error")); - } - } + request->setDebug(false); + } + else + { + AHTTP_LOGERROR(F("Response error")); + } + } } void setup(void) { - Serial.begin(115200); + Serial.begin(115200); - while (!Serial && millis() < 5000); + while (!Serial && millis() < 5000); - Serial.print("\nStart AsyncDweetGET_STM32 on "); - Serial.println(BOARD_NAME); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); + Serial.print("\nStart AsyncDweetGET_STM32 on "); + Serial.println(BOARD_NAME); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); #if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - { - Serial.print("Warning. Must use this example on Version equal or later than : "); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); - } + if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) + { + Serial.print("Warning. Must use this example on Version equal or later than : "); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); + } #endif - // start the ethernet connection and the server - // Use random mac - uint16_t index = millis() % NUMBER_OF_MAC; + // start the ethernet connection and the server + // Use random mac + uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - // Use DHCP dynamic IP and random mac - Ethernet.begin(mac[index]); + // Use Static IP + //Ethernet.begin(mac[index], ip); + // Use DHCP dynamic IP and random mac + Ethernet.begin(mac[index]); - Serial.print(F("AsyncHTTPRequest @ IP : ")); - Serial.println(Ethernet.localIP()); - Serial.println(); + Serial.print(F("AsyncHTTPRequest @ IP : ")); + Serial.println(Ethernet.localIP()); + Serial.println(); - request.setDebug(false); + request.setDebug(false); - request.onReadyStateChange(requestCB); - sendHTTPRequest.start(); //start the ticker. + request.onReadyStateChange(requestCB); + sendHTTPRequest.start(); //start the ticker. } void loop(void) { - sendHTTPRequest.update(); + sendHTTPRequest.update(); } diff --git a/examples/AsyncDweetGet_STM32/defines.h b/examples/AsyncDweetGet_STM32/defines.h index 44a9364..fd7592b 100644 --- a/examples/AsyncDweetGet_STM32/defines.h +++ b/examples/AsyncDweetGet_STM32/defines.h @@ -46,54 +46,54 @@ #if defined(STM32F0) - #warning STM32F0 board selected - #define BOARD_TYPE "STM32F0" + #warning STM32F0 board selected + #define BOARD_TYPE "STM32F0" #elif defined(STM32F1) - #warning STM32F1 board selected - #define BOARD_TYPE "STM32F1" + #warning STM32F1 board selected + #define BOARD_TYPE "STM32F1" #elif defined(STM32F2) - #warning STM32F2 board selected - #define BOARD_TYPE "STM32F2" + #warning STM32F2 board selected + #define BOARD_TYPE "STM32F2" #elif defined(STM32F3) - #warning STM32F3 board selected - #define BOARD_TYPE "STM32F3" + #warning STM32F3 board selected + #define BOARD_TYPE "STM32F3" #elif defined(STM32F4) - #warning STM32F4 board selected - #define BOARD_TYPE "STM32F4" + #warning STM32F4 board selected + #define BOARD_TYPE "STM32F4" #elif defined(STM32F7) - #warning STM32F7 board selected - #define BOARD_TYPE "STM32F7" + #warning STM32F7 board selected + #define BOARD_TYPE "STM32F7" #elif defined(STM32L0) - #warning STM32L0 board selected - #define BOARD_TYPE "STM32L0" + #warning STM32L0 board selected + #define BOARD_TYPE "STM32L0" #elif defined(STM32L1) - #warning STM32L1 board selected - #define BOARD_TYPE "STM32L1" + #warning STM32L1 board selected + #define BOARD_TYPE "STM32L1" #elif defined(STM32L4) - #warning STM32L4 board selected - #define BOARD_TYPE "STM32L4" + #warning STM32L4 board selected + #define BOARD_TYPE "STM32L4" #elif defined(STM32H7) - #warning STM32H7 board selected - #define BOARD_TYPE "STM32H7" + #warning STM32H7 board selected + #define BOARD_TYPE "STM32H7" #elif defined(STM32G0) - #warning STM32G0 board selected - #define BOARD_TYPE "STM32G0" + #warning STM32G0 board selected + #define BOARD_TYPE "STM32G0" #elif defined(STM32G4) - #warning STM32G4 board selected - #define BOARD_TYPE "STM32G4" + #warning STM32G4 board selected + #define BOARD_TYPE "STM32G4" #elif defined(STM32WB) - #warning STM32WB board selected - #define BOARD_TYPE "STM32WB" + #warning STM32WB board selected + #define BOARD_TYPE "STM32WB" #elif defined(STM32MP1) - #warning STM32MP1 board selected - #define BOARD_TYPE "STM32MP1" + #warning STM32MP1 board selected + #define BOARD_TYPE "STM32MP1" #else - #warning STM32 unknown board selected - #define BOARD_TYPE "STM32 Unknown" + #warning STM32 unknown board selected + #define BOARD_TYPE "STM32 Unknown" #endif #ifndef BOARD_NAME - #define BOARD_NAME BOARD_TYPE + #define BOARD_NAME BOARD_TYPE #endif #include @@ -106,26 +106,26 @@ byte mac[][NUMBER_OF_MAC] = { - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, }; // Select the static IP address according to your local network diff --git a/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino b/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino index 8dc9e92..c3978b0 100644 --- a/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino +++ b/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino @@ -52,137 +52,137 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS); void sendRequest(void) { - static bool requestOpenResult; + static bool requestOpenResult; - if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) - { - String postData = "sensorValue="; - postData += analogRead(A0); + if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) + { + String postData = "sensorValue="; + postData += analogRead(A0); - Serial.println("\nMaking new POST request"); + Serial.println("\nMaking new POST request"); - requestOpenResult = request.open("POST", (POST_ServerAddress + dweetName + postData).c_str() ); + requestOpenResult = request.open("POST", (POST_ServerAddress + dweetName + postData).c_str() ); - if (requestOpenResult) - { - // Only send() if open() returns true, or crash - request.send(); - } - else - { - Serial.println("Can't send bad request"); - } - } - else - { - Serial.println("Can't send request"); - } + if (requestOpenResult) + { + // Only send() if open() returns true, or crash + request.send(); + } + else + { + Serial.println("Can't send bad request"); + } + } + else + { + Serial.println("Can't send request"); + } } void parseResponse(String responseText) { - /* - Typical response is: - {"this":"succeeded", - "by":"getting", - "the":"dweets", - "with":[{"thing":"my-thing-name", - "created":"2016-02-16T05:10:36.589Z", - "content":{"sensorValue":456}}]} + /* + Typical response is: + {"this":"succeeded", + "by":"getting", + "the":"dweets", + "with":[{"thing":"my-thing-name", + "created":"2016-02-16T05:10:36.589Z", + "content":{"sensorValue":456}}]} - You want "content": numberValue - */ - // now parse the response looking for "content": - int labelStart = responseText.indexOf("content\":"); - // find the first { after "content": - int contentStart = responseText.indexOf("{", labelStart); - // find the following } and get what's between the braces: - int contentEnd = responseText.indexOf("}", labelStart); - String content = responseText.substring(contentStart + 1, contentEnd); + You want "content": numberValue + */ + // now parse the response looking for "content": + int labelStart = responseText.indexOf("content\":"); + // find the first { after "content": + int contentStart = responseText.indexOf("{", labelStart); + // find the following } and get what's between the braces: + int contentEnd = responseText.indexOf("}", labelStart); + String content = responseText.substring(contentStart + 1, contentEnd); - Serial.println(content); + Serial.println(content); - // now get the value after the colon, and convert to an int: - int valueStart = content.indexOf(":"); - String valueString = content.substring(valueStart + 1); - int number = valueString.toInt(); + // now get the value after the colon, and convert to an int: + int valueStart = content.indexOf(":"); + String valueString = content.substring(valueStart + 1); + int number = valueString.toInt(); - Serial.print("Value string: "); - Serial.println(valueString); - Serial.print("Actual value: "); - Serial.println(number); + Serial.print("Value string: "); + Serial.println(valueString); + Serial.print("Actual value: "); + Serial.println(number); } void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState) { - (void) optParm; + (void) optParm; - if (readyState == readyStateDone) - { - Serial.println(); - AHTTP_LOGDEBUG(F("**************************************")); - AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); + if (readyState == readyStateDone) + { + Serial.println(); + AHTTP_LOGDEBUG(F("**************************************")); + AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); - if (request->responseHTTPcode() == 200) - { - String responseText = request->responseText(); + if (request->responseHTTPcode() == 200) + { + String responseText = request->responseText(); - Serial.println("\n**************************************"); - //Serial.println(request->responseText()); - Serial.println(responseText); - Serial.println("**************************************"); + Serial.println("\n**************************************"); + //Serial.println(request->responseText()); + Serial.println(responseText); + Serial.println("**************************************"); - parseResponse(responseText); + parseResponse(responseText); - request->setDebug(false); - } - else - { - AHTTP_LOGERROR(F("Response error")); - } - } + request->setDebug(false); + } + else + { + AHTTP_LOGERROR(F("Response error")); + } + } } void setup(void) { - Serial.begin(115200); + Serial.begin(115200); - while (!Serial && millis() < 5000); + while (!Serial && millis() < 5000); - Serial.print("\nStart AsyncDweetPOST_STM32 on "); - Serial.println(BOARD_NAME); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); + Serial.print("\nStart AsyncDweetPOST_STM32 on "); + Serial.println(BOARD_NAME); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); #if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - { - Serial.print("Warning. Must use this example on Version equal or later than : "); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); - } + if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) + { + Serial.print("Warning. Must use this example on Version equal or later than : "); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); + } #endif - // start the ethernet connection and the server - // Use random mac - uint16_t index = millis() % NUMBER_OF_MAC; + // start the ethernet connection and the server + // Use random mac + uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - // Use DHCP dynamic IP and random mac - Ethernet.begin(mac[index]); + // Use Static IP + //Ethernet.begin(mac[index], ip); + // Use DHCP dynamic IP and random mac + Ethernet.begin(mac[index]); - Serial.print(F("AsyncHTTPRequest @ IP : ")); - Serial.println(Ethernet.localIP()); - Serial.println(); + Serial.print(F("AsyncHTTPRequest @ IP : ")); + Serial.println(Ethernet.localIP()); + Serial.println(); - request.setDebug(false); + request.setDebug(false); - request.onReadyStateChange(requestCB); - sendHTTPRequest.start(); //start the ticker. + request.onReadyStateChange(requestCB); + sendHTTPRequest.start(); //start the ticker. } void loop(void) { - sendHTTPRequest.update(); + sendHTTPRequest.update(); } diff --git a/examples/AsyncDweetPost_STM32/defines.h b/examples/AsyncDweetPost_STM32/defines.h index b652471..844fdba 100644 --- a/examples/AsyncDweetPost_STM32/defines.h +++ b/examples/AsyncDweetPost_STM32/defines.h @@ -46,54 +46,54 @@ #if defined(STM32F0) - #warning STM32F0 board selected - #define BOARD_TYPE "STM32F0" + #warning STM32F0 board selected + #define BOARD_TYPE "STM32F0" #elif defined(STM32F1) - #warning STM32F1 board selected - #define BOARD_TYPE "STM32F1" + #warning STM32F1 board selected + #define BOARD_TYPE "STM32F1" #elif defined(STM32F2) - #warning STM32F2 board selected - #define BOARD_TYPE "STM32F2" + #warning STM32F2 board selected + #define BOARD_TYPE "STM32F2" #elif defined(STM32F3) - #warning STM32F3 board selected - #define BOARD_TYPE "STM32F3" + #warning STM32F3 board selected + #define BOARD_TYPE "STM32F3" #elif defined(STM32F4) - #warning STM32F4 board selected - #define BOARD_TYPE "STM32F4" + #warning STM32F4 board selected + #define BOARD_TYPE "STM32F4" #elif defined(STM32F7) - #warning STM32F7 board selected - #define BOARD_TYPE "STM32F7" + #warning STM32F7 board selected + #define BOARD_TYPE "STM32F7" #elif defined(STM32L0) - #warning STM32L0 board selected - #define BOARD_TYPE "STM32L0" + #warning STM32L0 board selected + #define BOARD_TYPE "STM32L0" #elif defined(STM32L1) - #warning STM32L1 board selected - #define BOARD_TYPE "STM32L1" + #warning STM32L1 board selected + #define BOARD_TYPE "STM32L1" #elif defined(STM32L4) - #warning STM32L4 board selected - #define BOARD_TYPE "STM32L4" + #warning STM32L4 board selected + #define BOARD_TYPE "STM32L4" #elif defined(STM32H7) - #warning STM32H7 board selected - #define BOARD_TYPE "STM32H7" + #warning STM32H7 board selected + #define BOARD_TYPE "STM32H7" #elif defined(STM32G0) - #warning STM32G0 board selected - #define BOARD_TYPE "STM32G0" + #warning STM32G0 board selected + #define BOARD_TYPE "STM32G0" #elif defined(STM32G4) - #warning STM32G4 board selected - #define BOARD_TYPE "STM32G4" + #warning STM32G4 board selected + #define BOARD_TYPE "STM32G4" #elif defined(STM32WB) - #warning STM32WB board selected - #define BOARD_TYPE "STM32WB" + #warning STM32WB board selected + #define BOARD_TYPE "STM32WB" #elif defined(STM32MP1) - #warning STM32MP1 board selected - #define BOARD_TYPE "STM32MP1" + #warning STM32MP1 board selected + #define BOARD_TYPE "STM32MP1" #else - #warning STM32 unknown board selected - #define BOARD_TYPE "STM32 Unknown" + #warning STM32 unknown board selected + #define BOARD_TYPE "STM32 Unknown" #endif #ifndef BOARD_NAME - #define BOARD_NAME BOARD_TYPE + #define BOARD_NAME BOARD_TYPE #endif #include @@ -106,26 +106,26 @@ byte mac[][NUMBER_OF_MAC] = { - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, }; // Select the static IP address according to your local network diff --git a/examples/AsyncHTTPMultiRequests_ESP/AsyncHTTPMultiRequests_ESP.ino b/examples/AsyncHTTPMultiRequests_ESP/AsyncHTTPMultiRequests_ESP.ino index 3f3ea0d..ad3567e 100644 --- a/examples/AsyncHTTPMultiRequests_ESP/AsyncHTTPMultiRequests_ESP.ino +++ b/examples/AsyncHTTPMultiRequests_ESP/AsyncHTTPMultiRequests_ESP.ino @@ -41,7 +41,7 @@ //************************************************************************************************************* #if !( defined(ESP8266) || defined(ESP32) ) - #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting. + #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting. #endif #define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2" @@ -63,9 +63,9 @@ const char* ssid = "your_ssid"; const char* password = "your_pass"; #if (ESP8266) - #include + #include #elif (ESP32) - #include + #include #endif // Seconds for timeout, default is 3s @@ -85,22 +85,22 @@ Ticker ticker1; void heartBeatPrint(void) { - static int num = 1; + static int num = 1; - if (WiFi.status() == WL_CONNECTED) - Serial.print(F("H")); // H means connected to WiFi - else - Serial.print(F("F")); // F means not connected to WiFi + if (WiFi.status() == WL_CONNECTED) + Serial.print(F("H")); // H means connected to WiFi + else + Serial.print(F("F")); // F means not connected to WiFi - if (num == 80) - { - Serial.println(); - num = 1; - } - else if (num++ % 10 == 0) - { - Serial.print(F(" ")); - } + if (num == 80) + { + Serial.println(); + num = 1; + } + else if (num++ % 10 == 0) + { + Serial.print(F(" ")); + } } // To replace with your real APP_API @@ -126,111 +126,111 @@ uint8_t requestIndex = 0; void sendRequest() { - static bool requestOpenResult; + static bool requestOpenResult; - if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) - { - requestOpenResult = request.open("GET", requestAll[requestIndex] ); + if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) + { + requestOpenResult = request.open("GET", requestAll[requestIndex] ); - if (requestOpenResult) - { - // Only send() if open() returns true, or crash - request.send(); - } - else - { - Serial.println(F("Can't send bad request")); - } - } - else - { - Serial.println(F("Can't send request")); - } + if (requestOpenResult) + { + // Only send() if open() returns true, or crash + request.send(); + } + else + { + Serial.println(F("Can't send bad request")); + } + } + else + { + Serial.println(F("Can't send request")); + } } void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState) { - (void) optParm; + (void) optParm; - if (readyState == readyStateDone) - { - AHTTP_LOGDEBUG(F("\n**************************************")); - AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); + if (readyState == readyStateDone) + { + AHTTP_LOGDEBUG(F("\n**************************************")); + AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); - if (request->responseHTTPcode() == 200) - { - Serial.print(F("\n***************")); - Serial.print(requestName[ requestIndex ]); - Serial.println(F("***************")); - Serial.println(request->responseText()); - Serial.println(F("**************************************")); - } + if (request->responseHTTPcode() == 200) + { + Serial.print(F("\n***************")); + Serial.print(requestName[ requestIndex ]); + Serial.println(F("***************")); + Serial.println(request->responseText()); + Serial.println(F("**************************************")); + } #if 1 - // Bypass hourly - if (requestIndex == 1) - requestIndex = 3; - else - requestIndex = (requestIndex + 1) % NUM_REQUESTS; + // Bypass hourly + if (requestIndex == 1) + requestIndex = 3; + else + requestIndex = (requestIndex + 1) % NUM_REQUESTS; #else - // hourly too long, not display anyway. Not enough heap. - requestIndex = (requestIndex + 1) % NUM_REQUESTS; + // hourly too long, not display anyway. Not enough heap. + requestIndex = (requestIndex + 1) % NUM_REQUESTS; #endif - request->setDebug(false); - } + request->setDebug(false); + } } void setup() { - // put your setup code here, to run once: - Serial.begin(115200); + // put your setup code here, to run once: + Serial.begin(115200); - while (!Serial && millis() < 5000); + while (!Serial && millis() < 5000); - delay(200); + delay(200); - Serial.print(F("\nStarting AsyncHTTPMultiRequests using ")); - Serial.println(ARDUINO_BOARD); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); + Serial.print(F("\nStarting AsyncHTTPMultiRequests using ")); + Serial.println(ARDUINO_BOARD); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); #if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - { - Serial.print(F("Warning. Must use this example on Version equal or later than : ")); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); - } + if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) + { + Serial.print(F("Warning. Must use this example on Version equal or later than : ")); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); + } #endif - WiFi.mode(WIFI_STA); + WiFi.mode(WIFI_STA); - WiFi.begin(ssid, password); + WiFi.begin(ssid, password); - Serial.print(F("Connecting to WiFi SSID: ")); - Serial.println(ssid); + Serial.print(F("Connecting to WiFi SSID: ")); + Serial.println(ssid); - while (WiFi.status() != WL_CONNECTED) - { - delay(500); - Serial.print(F(".")); - } + while (WiFi.status() != WL_CONNECTED) + { + delay(500); + Serial.print(F(".")); + } - Serial.print(F("AsyncHTTPRequest @ IP : ")); - Serial.println(WiFi.localIP()); + Serial.print(F("AsyncHTTPRequest @ IP : ")); + Serial.println(WiFi.localIP()); - request.setDebug(false); + request.setDebug(false); - request.onReadyStateChange(requestCB); - ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest); + request.onReadyStateChange(requestCB); + ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest); - ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint); + ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint); - // Send first request now - sendRequest(); + // Send first request now + sendRequest(); } void loop() diff --git a/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino b/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino index 21d67a8..043818e 100644 --- a/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino +++ b/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino @@ -41,7 +41,7 @@ //************************************************************************************************************* #if !( defined(ESP8266) || defined(ESP32) ) - #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting. + #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting. #endif // Level from 0-4 @@ -60,9 +60,9 @@ const char* ssid = "your_ssid"; const char* password = "your_pass"; #if (ESP8266) - #include + #include #elif (ESP32) - #include + #include #endif #define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2" @@ -85,103 +85,103 @@ Ticker ticker1; void heartBeatPrint() { - static int num = 1; + static int num = 1; - if (WiFi.status() == WL_CONNECTED) - Serial.print(F("H")); // H means connected to WiFi - else - Serial.print(F("F")); // F means not connected to WiFi + if (WiFi.status() == WL_CONNECTED) + Serial.print(F("H")); // H means connected to WiFi + else + Serial.print(F("F")); // F means not connected to WiFi - if (num == 80) - { - Serial.println(); - num = 1; - } - else if (num++ % 10 == 0) - { - Serial.print(F(" ")); - } + if (num == 80) + { + Serial.println(); + num = 1; + } + else if (num++ % 10 == 0) + { + Serial.print(F(" ")); + } } void sendRequest() { - static bool requestOpenResult; + static bool requestOpenResult; - if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) - { - //requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt"); - requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt"); + if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) + { + //requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt"); + requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt"); - if (requestOpenResult) - { - // Only send() if open() returns true, or crash - request.send(); - } - else - { - Serial.println(F("Can't send bad request")); - } - } - else - { - Serial.println(F("Can't send request")); - } + if (requestOpenResult) + { + // Only send() if open() returns true, or crash + request.send(); + } + else + { + Serial.println(F("Can't send bad request")); + } + } + else + { + Serial.println(F("Can't send request")); + } } void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState) { - (void) optParm; + (void) optParm; - if (readyState == readyStateDone) - { - AHTTP_LOGDEBUG(F("\n**************************************")); - AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); + if (readyState == readyStateDone) + { + AHTTP_LOGDEBUG(F("\n**************************************")); + AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); - if (request->responseHTTPcode() == 200) - { - Serial.println(F("\n**************************************")); - Serial.println(request->responseText()); - Serial.println(F("**************************************")); - } - } + if (request->responseHTTPcode() == 200) + { + Serial.println(F("\n**************************************")); + Serial.println(request->responseText()); + Serial.println(F("**************************************")); + } + } } void setup() { - // put your setup code here, to run once: - Serial.begin(115200); + // put your setup code here, to run once: + Serial.begin(115200); - while (!Serial && millis() < 5000); + while (!Serial && millis() < 5000); - Serial.print(F("\nStarting AsyncHTTPRequest_ESP using ")); - Serial.println(ARDUINO_BOARD); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); + Serial.print(F("\nStarting AsyncHTTPRequest_ESP using ")); + Serial.println(ARDUINO_BOARD); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); - WiFi.mode(WIFI_STA); + WiFi.mode(WIFI_STA); - WiFi.begin(ssid, password); + WiFi.begin(ssid, password); - Serial.print(F("Connecting to WiFi SSID: ")); - Serial.println(ssid); + Serial.print(F("Connecting to WiFi SSID: ")); + Serial.println(ssid); - while (WiFi.status() != WL_CONNECTED) - { - delay(500); - Serial.print(F(".")); - } + while (WiFi.status() != WL_CONNECTED) + { + delay(500); + Serial.print(F(".")); + } - Serial.print(F("\nAsyncHTTPRequest @ IP : ")); - Serial.println(WiFi.localIP()); + Serial.print(F("\nAsyncHTTPRequest @ IP : ")); + Serial.println(WiFi.localIP()); - request.setDebug(false); + request.setDebug(false); - request.onReadyStateChange(requestCB); - ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest); + request.onReadyStateChange(requestCB); + ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest); - ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint); + ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint); - // Send first request now - sendRequest(); + // Send first request now + sendRequest(); } void loop() diff --git a/examples/AsyncHTTPRequest_ESP8266_Ethernet/AsyncHTTPRequest_ESP8266_Ethernet.ino b/examples/AsyncHTTPRequest_ESP8266_Ethernet/AsyncHTTPRequest_ESP8266_Ethernet.ino index db78f6f..2b5078b 100644 --- a/examples/AsyncHTTPRequest_ESP8266_Ethernet/AsyncHTTPRequest_ESP8266_Ethernet.ino +++ b/examples/AsyncHTTPRequest_ESP8266_Ethernet/AsyncHTTPRequest_ESP8266_Ethernet.ino @@ -41,7 +41,7 @@ //************************************************************************************************************* #if !( defined(ESP8266) ) - #error This code is intended to run on the ESP8266 platform! Please check your Tools->Board setting. + #error This code is intended to run on the ESP8266 platform! Please check your Tools->Board setting. #endif // Level from 0-4 @@ -65,27 +65,27 @@ #define CSPIN 16 // 5 #if USING_W5500 - #include "W5500lwIP.h" - #define SHIELD_TYPE "ESP8266_W5500 Ethernet" + #include "W5500lwIP.h" + #define SHIELD_TYPE "ESP8266_W5500 Ethernet" - Wiznet5500lwIP eth(CSPIN); + Wiznet5500lwIP eth(CSPIN); #elif USING_W5100 - #include - #define SHIELD_TYPE "ESP8266_W5100 Ethernet" + #include + #define SHIELD_TYPE "ESP8266_W5100 Ethernet" - Wiznet5100lwIP eth(CSPIN); + Wiznet5100lwIP eth(CSPIN); #elif USING_ENC28J60 - #include - #define SHIELD_TYPE "ESP8266_ENC28J60 Ethernet" + #include + #define SHIELD_TYPE "ESP8266_ENC28J60 Ethernet" - ENC28J60lwIP eth(CSPIN); + ENC28J60lwIP eth(CSPIN); #else - // default if none selected - #include "W5500lwIP.h" + // default if none selected + #include "W5500lwIP.h" - Wiznet5500lwIP eth(CSPIN); + Wiznet5500lwIP eth(CSPIN); #endif @@ -115,126 +115,126 @@ Ticker ticker1; void heartBeatPrint() { - static int num = 1; + static int num = 1; - if (eth.connected()) - Serial.print(F("H")); // H means connected to Ethernet - else - Serial.print(F("F")); // F means not connected to Ethernet + if (eth.connected()) + Serial.print(F("H")); // H means connected to Ethernet + else + Serial.print(F("F")); // F means not connected to Ethernet - if (num == 80) - { - Serial.println(); - num = 1; - } - else if (num++ % 10 == 0) - { - Serial.print(F(" ")); - } + if (num == 80) + { + Serial.println(); + num = 1; + } + else if (num++ % 10 == 0) + { + Serial.print(F(" ")); + } } void sendRequest() { - static bool requestOpenResult; + static bool requestOpenResult; - if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) - { - //requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt"); - requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt"); + if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) + { + //requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt"); + requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt"); - if (requestOpenResult) - { - // Only send() if open() returns true, or crash - request.send(); - } - else - { - Serial.println(F("Can't send bad request")); - } - } - else - { - Serial.println(F("Can't send request")); - } + if (requestOpenResult) + { + // Only send() if open() returns true, or crash + request.send(); + } + else + { + Serial.println(F("Can't send bad request")); + } + } + else + { + Serial.println(F("Can't send request")); + } } void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState) { - (void) optParm; + (void) optParm; - if (readyState == readyStateDone) - { - AHTTP_LOGDEBUG(F("\n**************************************")); - AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); + if (readyState == readyStateDone) + { + AHTTP_LOGDEBUG(F("\n**************************************")); + AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); - if (request->responseHTTPcode() == 200) - { - Serial.println(F("\n**************************************")); - Serial.println(request->responseText()); - Serial.println(F("**************************************")); - } - } + if (request->responseHTTPcode() == 200) + { + Serial.println(F("\n**************************************")); + Serial.println(request->responseText()); + Serial.println(F("**************************************")); + } + } } void initEthernet() { - SPI.begin(); - SPI.setClockDivider(SPI_CLOCK_DIV4); - SPI.setBitOrder(MSBFIRST); - SPI.setDataMode(SPI_MODE0); - eth.setDefault(); + SPI.begin(); + SPI.setClockDivider(SPI_CLOCK_DIV4); + SPI.setBitOrder(MSBFIRST); + SPI.setDataMode(SPI_MODE0); + eth.setDefault(); - if (!eth.begin()) - { - Serial.println("No Ethernet hardware ... Stop here"); + if (!eth.begin()) + { + Serial.println("No Ethernet hardware ... Stop here"); - while (true) - { - delay(1000); - } - } - else - { - Serial.print("Connecting to network : "); + while (true) + { + delay(1000); + } + } + else + { + Serial.print("Connecting to network : "); - while (!eth.connected()) - { - Serial.print("."); - delay(1000); - } - } + while (!eth.connected()) + { + Serial.print("."); + delay(1000); + } + } - Serial.println(); - Serial.print("Ethernet IP address: "); - Serial.println(eth.localIP()); + Serial.println(); + Serial.print("Ethernet IP address: "); + Serial.println(eth.localIP()); } void setup() { - // put your setup code here, to run once: - Serial.begin(115200); + // put your setup code here, to run once: + Serial.begin(115200); - while (!Serial && millis() < 5000); + while (!Serial && millis() < 5000); - delay(200); + delay(200); - Serial.print("\nStart AsyncHTTPRequest_ESP8266_Ethernet on "); - Serial.print(ARDUINO_BOARD); - Serial.print(" using "); - Serial.println(SHIELD_TYPE); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); + Serial.print("\nStart AsyncHTTPRequest_ESP8266_Ethernet on "); + Serial.print(ARDUINO_BOARD); + Serial.print(" using "); + Serial.println(SHIELD_TYPE); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); - initEthernet(); + initEthernet(); - request.setDebug(false); + request.setDebug(false); - request.onReadyStateChange(requestCB); - ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest); + request.onReadyStateChange(requestCB); + ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest); - ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint); + ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint); - // Send first request now - sendRequest(); + // Send first request now + sendRequest(); } void loop() diff --git a/examples/AsyncHTTPRequest_ESP_Multi/AsyncHTTPRequest_ESP_Multi.ino b/examples/AsyncHTTPRequest_ESP_Multi/AsyncHTTPRequest_ESP_Multi.ino index 174916f..b8ef73f 100644 --- a/examples/AsyncHTTPRequest_ESP_Multi/AsyncHTTPRequest_ESP_Multi.ino +++ b/examples/AsyncHTTPRequest_ESP_Multi/AsyncHTTPRequest_ESP_Multi.ino @@ -19,7 +19,7 @@ *****************************************************************************************************************************/ #if !( defined(ESP8266) || defined(ESP32) ) - #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting. + #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting. #endif // Level from 0-4 @@ -39,9 +39,9 @@ const char* ssid = "your_ssid"; const char* password = "your_pass"; #if (ESP8266) - #include + #include #elif (ESP32) - #include + #include #endif // Seconds for timeout, default is 3s @@ -59,8 +59,8 @@ const char* password = "your_pass"; const char* addreses[][NUM_DIFFERENT_SITES] = { - {"http://worldtimeapi.org/api/timezone/America/Toronto.txt", "http://worldtimeapi.org/api/timezone/Europe/Prague.txt"}, - {"http://www.myexternalip.com/raw"} + {"http://worldtimeapi.org/api/timezone/America/Toronto.txt", "http://worldtimeapi.org/api/timezone/Europe/Prague.txt"}, + {"http://www.myexternalip.com/raw"} }; #define NUM_ENTRIES_SITE_0 2 @@ -88,161 +88,161 @@ Ticker ticker1; void heartBeatPrint() { - static int num = 1; + static int num = 1; - if (WiFi.status() == WL_CONNECTED) - Serial.print(F("H")); // H means connected to WiFi - else - Serial.print(F("F")); // F means not connected to WiFi + if (WiFi.status() == WL_CONNECTED) + Serial.print(F("H")); // H means connected to WiFi + else + Serial.print(F("F")); // F means not connected to WiFi - if (num == 80) - { - Serial.println(); - num = 1; - } - else if (num++ % 10 == 0) - { - Serial.print(F(" ")); - } + if (num == 80) + { + Serial.println(); + num = 1; + } + else if (num++ % 10 == 0) + { + Serial.print(F(" ")); + } } void sendRequest(uint16_t index) { - static bool requestOpenResult; + static bool requestOpenResult; - reqCount[index]--; - readySend[index] = false; + reqCount[index]--; + readySend[index] = false; - requestOpenResult = request[index].open("GET", addreses[index][reqCount[index]]); + requestOpenResult = request[index].open("GET", addreses[index][reqCount[index]]); - if (requestOpenResult) - { - // Only send() if open() returns true, or crash - Serial.print("\nSending request: "); - request[index].send(); - } - else - { - Serial.print("\nCan't send bad request : "); - } + if (requestOpenResult) + { + // Only send() if open() returns true, or crash + Serial.print("\nSending request: "); + request[index].send(); + } + else + { + Serial.print("\nCan't send bad request : "); + } - Serial.println(addreses[index][reqCount[index]]); + Serial.println(addreses[index][reqCount[index]]); } void sendRequest0() { - sendRequest(0); + sendRequest(0); } void sendRequest1() { - sendRequest(1); + sendRequest(1); } void sendRequests() { - reqCount[0] = NUM_ENTRIES_SITE_0; - reqCount[1] = NUM_ENTRIES_SITE_1; + reqCount[0] = NUM_ENTRIES_SITE_0; + reqCount[1] = NUM_ENTRIES_SITE_1; } void requestCB0(void* optParm, AsyncHTTPRequest* thisRequest, int readyState) { - (void) optParm; + (void) optParm; - if (readyState == readyStateDone) - { - AHTTP_LOGWARN(F("\n**************************************")); - AHTTP_LOGWARN1(F("Response Code = "), request->responseHTTPString()); + if (readyState == readyStateDone) + { + AHTTP_LOGWARN(F("\n**************************************")); + AHTTP_LOGWARN1(F("Response Code = "), request->responseHTTPString()); - if (request->responseHTTPcode() == 200) - { - Serial.println(F("\n**************************************")); - Serial.println(request->responseText()); - Serial.println(F("**************************************")); - } - else - { - AHTTP_LOGERROR(F("Response error")); - } + if (request->responseHTTPcode() == 200) + { + Serial.println(F("\n**************************************")); + Serial.println(request->responseText()); + Serial.println(F("**************************************")); + } + else + { + AHTTP_LOGERROR(F("Response error")); + } - thisRequest->setDebug(false); - readySend[0] = true; - } + thisRequest->setDebug(false); + readySend[0] = true; + } } void requestCB1(void* optParm, AsyncHTTPRequest* thisRequest, int readyState) { - (void) optParm; + (void) optParm; - if (readyState == readyStateDone) - { - AHTTP_LOGWARN(F("\n**************************************")); - AHTTP_LOGWARN1(F("Response Code = "), request->responseHTTPString()); + if (readyState == readyStateDone) + { + AHTTP_LOGWARN(F("\n**************************************")); + AHTTP_LOGWARN1(F("Response Code = "), request->responseHTTPString()); - if (request->responseHTTPcode() == 200) - { - Serial.println(F("\n**************************************")); - Serial.println(request->responseText()); - Serial.println(F("**************************************")); - } - else - { - AHTTP_LOGERROR(F("Response error")); - } + if (request->responseHTTPcode() == 200) + { + Serial.println(F("\n**************************************")); + Serial.println(request->responseText()); + Serial.println(F("**************************************")); + } + else + { + AHTTP_LOGERROR(F("Response error")); + } - thisRequest->setDebug(false); - readySend[1] = true; - } + thisRequest->setDebug(false); + readySend[1] = true; + } } void setup() { - // put your setup code here, to run once: - Serial.begin(115200); + // put your setup code here, to run once: + Serial.begin(115200); - while (!Serial && millis() < 5000); + while (!Serial && millis() < 5000); - Serial.print("\nStart AsyncHTTPRequest_ESP_Multi on "); - Serial.println(ARDUINO_BOARD); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); + Serial.print("\nStart AsyncHTTPRequest_ESP_Multi on "); + Serial.println(ARDUINO_BOARD); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); - WiFi.mode(WIFI_STA); + WiFi.mode(WIFI_STA); - WiFi.begin(ssid, password); + WiFi.begin(ssid, password); - Serial.println("Connecting to WiFi SSID: " + String(ssid)); + Serial.println("Connecting to WiFi SSID: " + String(ssid)); - while (WiFi.status() != WL_CONNECTED) - { - delay(1000); - Serial.print("."); - } + while (WiFi.status() != WL_CONNECTED) + { + delay(1000); + Serial.print("."); + } - Serial.print(F("\nAsyncHTTPSRequest @ IP : ")); - Serial.println(WiFi.localIP()); + Serial.print(F("\nAsyncHTTPSRequest @ IP : ")); + Serial.println(WiFi.localIP()); - for (int index = 0; index < NUM_DIFFERENT_SITES; index++) - { - request[index].setDebug(false); + for (int index = 0; index < NUM_DIFFERENT_SITES; index++) + { + request[index].setDebug(false); - request[index].onReadyStateChange(requestCB[index]); - } + request[index].onReadyStateChange(requestCB[index]); + } - ticker.attach(HTTP_REQUEST_INTERVAL, sendRequests); + ticker.attach(HTTP_REQUEST_INTERVAL, sendRequests); - ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint); + ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint); } void loop() { - for (int index = 0; index < NUM_DIFFERENT_SITES; index++) - { - if ((reqCount[index] > 0) && readySend[index]) - { - sendRequestCB[index](); + for (int index = 0; index < NUM_DIFFERENT_SITES; index++) + { + if ((reqCount[index] > 0) && readySend[index]) + { + sendRequestCB[index](); - // Don't send too fast - delay(1000); - } - } + // Don't send too fast + delay(1000); + } + } } diff --git a/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino b/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino index af00cc5..d01352c 100644 --- a/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino +++ b/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino @@ -43,7 +43,7 @@ // Important note: This code is intended to run with the ESPAsync_WiFiManager library version 1.4.1+. #if !( defined(ESP8266) || defined(ESP32) ) - #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting. + #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting. #endif #define ESP_ASYNC_WIFIMANAGER_VERSION_MIN_TARGET "ESPAsync_WiFiManager v1.15.0" @@ -66,90 +66,90 @@ //Ported to ESP32 #ifdef ESP32 - #include - #include - #include + #include + #include + #include - // From v1.1.1 - #include - WiFiMulti wifiMulti; + // From v1.1.1 + #include + WiFiMulti wifiMulti; - // LittleFS has higher priority than SPIFFS - #define USE_LITTLEFS true - #define USE_SPIFFS false + // LittleFS has higher priority than SPIFFS + #define USE_LITTLEFS true + #define USE_SPIFFS false - #if USE_LITTLEFS - // Use LittleFS - #include "FS.h" + #if USE_LITTLEFS + // Use LittleFS + #include "FS.h" - // The library will be depreciated after being merged to future major Arduino esp32 core release 2.x - // At that time, just remove this library inclusion - #if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) ) - #warning Using ESP32 Core 1.0.6 or 2.0.0+ and core LittleFS library - // The library has been merged into esp32 core from release 1.0.6 - #include // https://github.com/espressif/arduino-esp32/tree/master/libraries/LittleFS + // The library will be depreciated after being merged to future major Arduino esp32 core release 2.x + // At that time, just remove this library inclusion + #if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) ) + #warning Using ESP32 Core 1.0.6 or 2.0.0+ and core LittleFS library + // The library has been merged into esp32 core from release 1.0.6 + #include // https://github.com/espressif/arduino-esp32/tree/master/libraries/LittleFS - //#define FileFS LittleFS - //#define FS_Name "LittleFS" - FS* filesystem = &LittleFS; - #define FileFS LittleFS - #else - #warning Using ESP32 Core 1.0.5-. You must install LITTLEFS library - // The library has been merged into esp32 core from release 1.0.6 - #include // https://github.com/lorol/LITTLEFS + //#define FileFS LittleFS + //#define FS_Name "LittleFS" + FS* filesystem = &LittleFS; + #define FileFS LittleFS + #else + #warning Using ESP32 Core 1.0.5-. You must install LITTLEFS library + // The library has been merged into esp32 core from release 1.0.6 + #include // https://github.com/lorol/LITTLEFS - //#define FileFS LITTLEFS - FS* filesystem = &LITTLEFS; - #define FileFS LITTLEFS - #endif + //#define FileFS LITTLEFS + FS* filesystem = &LITTLEFS; + #define FileFS LITTLEFS + #endif - #define FS_Name "LittleFS" - #elif USE_SPIFFS - #include - FS* filesystem = &SPIFFS; - #define FileFS SPIFFS - #define FS_Name "SPIFFS" - #else - // +Use FFat - #include - FS* filesystem = &FFat; - #define FileFS FFat - #define FS_Name "FFat" - #endif - ////// + #define FS_Name "LittleFS" + #elif USE_SPIFFS + #include + FS* filesystem = &SPIFFS; + #define FileFS SPIFFS + #define FS_Name "SPIFFS" + #else + // +Use FFat + #include + FS* filesystem = &FFat; + #define FileFS FFat + #define FS_Name "FFat" + #endif + ////// - #define LED_BUILTIN 2 - #define LED_ON HIGH - #define LED_OFF LOW + #define LED_BUILTIN 2 + #define LED_ON HIGH + #define LED_OFF LOW #else - #include //https://github.com/esp8266/Arduino - //needed for library - #include + #include //https://github.com/esp8266/Arduino + //needed for library + #include - // From v1.1.1 - #include - ESP8266WiFiMulti wifiMulti; + // From v1.1.1 + #include + ESP8266WiFiMulti wifiMulti; - #define USE_LITTLEFS true + #define USE_LITTLEFS true - #if USE_LITTLEFS - #include - FS* filesystem = &LittleFS; - #define FileFS LittleFS - #define FS_Name "LittleFS" - #else - FS* filesystem = &SPIFFS; - #define FileFS SPIFFS - #define FS_Name "SPIFFS" - #endif - ////// + #if USE_LITTLEFS + #include + FS* filesystem = &LittleFS; + #define FileFS LittleFS + #define FS_Name "LittleFS" + #else + FS* filesystem = &SPIFFS; + #define FileFS SPIFFS + #define FS_Name "SPIFFS" + #endif + ////// - #define ESP_getChipId() (ESP.getChipId()) + #define ESP_getChipId() (ESP.getChipId()) - #define LED_ON LOW - #define LED_OFF HIGH + #define LED_ON LOW + #define LED_OFF HIGH #endif // SSID and PW for your Router @@ -169,21 +169,21 @@ String Router_Pass; typedef struct { - char wifi_ssid[SSID_MAX_LEN]; - char wifi_pw [PASS_MAX_LEN]; + char wifi_ssid[SSID_MAX_LEN]; + char wifi_pw [PASS_MAX_LEN]; } WiFi_Credentials; typedef struct { - String wifi_ssid; - String wifi_pw; + String wifi_ssid; + String wifi_pw; } WiFi_Credentials_String; #define NUM_WIFI_CREDENTIALS 2 typedef struct { - WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; + WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; } WM_Config; WM_Config WM_config; @@ -218,35 +218,35 @@ bool initialConfig = false; // Use USE_DHCP_IP == true for dynamic DHCP IP, false to use static IP which you have to change accordingly to your network #if (defined(USE_STATIC_IP_CONFIG_IN_CP) && !USE_STATIC_IP_CONFIG_IN_CP) - // Force DHCP to be true - #if defined(USE_DHCP_IP) - #undef USE_DHCP_IP - #endif - #define USE_DHCP_IP true + // Force DHCP to be true + #if defined(USE_DHCP_IP) + #undef USE_DHCP_IP + #endif + #define USE_DHCP_IP true #else - // You can select DHCP or Static IP here - #define USE_DHCP_IP true - //#define USE_DHCP_IP false + // You can select DHCP or Static IP here + #define USE_DHCP_IP true + //#define USE_DHCP_IP false #endif #if ( USE_DHCP_IP || ( defined(USE_STATIC_IP_CONFIG_IN_CP) && !USE_STATIC_IP_CONFIG_IN_CP ) ) - // Use DHCP - #warning Using DHCP IP - IPAddress stationIP = IPAddress(0, 0, 0, 0); - IPAddress gatewayIP = IPAddress(192, 168, 2, 1); - IPAddress netMask = IPAddress(255, 255, 255, 0); + // Use DHCP + #warning Using DHCP IP + IPAddress stationIP = IPAddress(0, 0, 0, 0); + IPAddress gatewayIP = IPAddress(192, 168, 2, 1); + IPAddress netMask = IPAddress(255, 255, 255, 0); #else - // Use static IP - #warning Using static IP + // Use static IP + #warning Using static IP - #ifdef ESP32 - IPAddress stationIP = IPAddress(192, 168, 2, 232); - #else - IPAddress stationIP = IPAddress(192, 168, 2, 186); - #endif + #ifdef ESP32 + IPAddress stationIP = IPAddress(192, 168, 2, 232); + #else + IPAddress stationIP = IPAddress(192, 168, 2, 186); + #endif - IPAddress gatewayIP = IPAddress(192, 168, 2, 1); - IPAddress netMask = IPAddress(255, 255, 255, 0); + IPAddress gatewayIP = IPAddress(192, 168, 2, 1); + IPAddress netMask = IPAddress(255, 255, 255, 0); #endif #define USE_CONFIGURABLE_DNS true @@ -309,39 +309,40 @@ WiFi_STA_IPConfig WM_STA_IPconfig; void initAPIPConfigStruct(WiFi_AP_IPConfig &in_WM_AP_IPconfig) { - in_WM_AP_IPconfig._ap_static_ip = APStaticIP; - in_WM_AP_IPconfig._ap_static_gw = APStaticGW; - in_WM_AP_IPconfig._ap_static_sn = APStaticSN; + in_WM_AP_IPconfig._ap_static_ip = APStaticIP; + in_WM_AP_IPconfig._ap_static_gw = APStaticGW; + in_WM_AP_IPconfig._ap_static_sn = APStaticSN; } void initSTAIPConfigStruct(WiFi_STA_IPConfig &in_WM_STA_IPconfig) { - in_WM_STA_IPconfig._sta_static_ip = stationIP; - in_WM_STA_IPconfig._sta_static_gw = gatewayIP; - in_WM_STA_IPconfig._sta_static_sn = netMask; + in_WM_STA_IPconfig._sta_static_ip = stationIP; + in_WM_STA_IPconfig._sta_static_gw = gatewayIP; + in_WM_STA_IPconfig._sta_static_sn = netMask; #if USE_CONFIGURABLE_DNS - in_WM_STA_IPconfig._sta_static_dns1 = dns1IP; - in_WM_STA_IPconfig._sta_static_dns2 = dns2IP; + in_WM_STA_IPconfig._sta_static_dns1 = dns1IP; + in_WM_STA_IPconfig._sta_static_dns2 = dns2IP; #endif } void displayIPConfigStruct(WiFi_STA_IPConfig in_WM_STA_IPconfig) { - LOGERROR3(F("stationIP ="), in_WM_STA_IPconfig._sta_static_ip, F(", gatewayIP ="), in_WM_STA_IPconfig._sta_static_gw); - LOGERROR1(F("netMask ="), in_WM_STA_IPconfig._sta_static_sn); + LOGERROR3(F("stationIP ="), in_WM_STA_IPconfig._sta_static_ip, F(", gatewayIP ="), in_WM_STA_IPconfig._sta_static_gw); + LOGERROR1(F("netMask ="), in_WM_STA_IPconfig._sta_static_sn); #if USE_CONFIGURABLE_DNS - LOGERROR3(F("dns1IP ="), in_WM_STA_IPconfig._sta_static_dns1, F(", dns2IP ="), in_WM_STA_IPconfig._sta_static_dns2); + LOGERROR3(F("dns1IP ="), in_WM_STA_IPconfig._sta_static_dns1, F(", dns2IP ="), in_WM_STA_IPconfig._sta_static_dns2); #endif } void configWiFi(WiFi_STA_IPConfig in_WM_STA_IPconfig) { #if USE_CONFIGURABLE_DNS - // Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5 - WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn, in_WM_STA_IPconfig._sta_static_dns1, in_WM_STA_IPconfig._sta_static_dns2); + // Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5 + WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn, + in_WM_STA_IPconfig._sta_static_dns1, in_WM_STA_IPconfig._sta_static_dns2); #else - // Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2. - WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn); + // Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2. + WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn); #endif } @@ -350,481 +351,484 @@ void configWiFi(WiFi_STA_IPConfig in_WM_STA_IPconfig) uint8_t connectMultiWiFi() { #if ESP32 - // For ESP32, this better be 0 to shorten the connect time. - // For ESP32-S2, must be > 500 + // For ESP32, this better be 0 to shorten the connect time. + // For ESP32-S2, must be > 500 #if ( ARDUINO_ESP32S2_DEV || ARDUINO_FEATHERS2 || ARDUINO_PROS2 || ARDUINO_MICROS2 ) #define WIFI_MULTI_1ST_CONNECT_WAITING_MS 500L #else - // For ESP32 core v1.0.6, must be >= 500 + // For ESP32 core v1.0.6, must be >= 500 #define WIFI_MULTI_1ST_CONNECT_WAITING_MS 800L #endif #else - // For ESP8266, this better be 2200 to enable connect the 1st time + // For ESP8266, this better be 2200 to enable connect the 1st time #define WIFI_MULTI_1ST_CONNECT_WAITING_MS 2200L #endif #define WIFI_MULTI_CONNECT_WAITING_MS 100L - uint8_t status; + uint8_t status; - LOGERROR(F("ConnectMultiWiFi with :")); + LOGERROR(F("ConnectMultiWiFi with :")); - if ( (Router_SSID != "") && (Router_Pass != "") ) - { - LOGERROR3(F("* Flash-stored Router_SSID = "), Router_SSID, F(", Router_Pass = "), Router_Pass ); - } + if ( (Router_SSID != "") && (Router_Pass != "") ) + { + LOGERROR3(F("* Flash-stored Router_SSID = "), Router_SSID, F(", Router_Pass = "), Router_Pass ); + } - for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++) - { - // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) - if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) - { - LOGERROR3(F("* Additional SSID = "), WM_config.WiFi_Creds[i].wifi_ssid, F(", PW = "), WM_config.WiFi_Creds[i].wifi_pw ); - } - } + for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++) + { + // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) + if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "") + && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) + { + LOGERROR3(F("* Additional SSID = "), WM_config.WiFi_Creds[i].wifi_ssid, F(", PW = "), WM_config.WiFi_Creds[i].wifi_pw ); + } + } - LOGERROR(F("Connecting MultiWifi...")); + LOGERROR(F("Connecting MultiWifi...")); - WiFi.mode(WIFI_STA); + WiFi.mode(WIFI_STA); #if !USE_DHCP_IP - // New in v1.4.0 - configWiFi(WM_STA_IPconfig); - ////// + // New in v1.4.0 + configWiFi(WM_STA_IPconfig); + ////// #endif - int i = 0; - status = wifiMulti.run(); + int i = 0; + status = wifiMulti.run(); - delay(WIFI_MULTI_1ST_CONNECT_WAITING_MS); + delay(WIFI_MULTI_1ST_CONNECT_WAITING_MS); - while ( ( i++ < 20 ) && ( status != WL_CONNECTED ) ) - { - status = wifiMulti.run(); + while ( ( i++ < 20 ) && ( status != WL_CONNECTED ) ) + { + status = wifiMulti.run(); - if ( status == WL_CONNECTED ) - break; - else - delay(WIFI_MULTI_CONNECT_WAITING_MS); - } + if ( status == WL_CONNECTED ) + break; + else + delay(WIFI_MULTI_CONNECT_WAITING_MS); + } - if ( status == WL_CONNECTED ) - { - LOGERROR1(F("WiFi connected after time: "), i); - LOGERROR3(F("SSID:"), WiFi.SSID(), F(",RSSI="), WiFi.RSSI()); - LOGERROR3(F("Channel:"), WiFi.channel(), F(",IP address:"), WiFi.localIP() ); - } - else - LOGERROR(F("WiFi not connected")); + if ( status == WL_CONNECTED ) + { + LOGERROR1(F("WiFi connected after time: "), i); + LOGERROR3(F("SSID:"), WiFi.SSID(), F(",RSSI="), WiFi.RSSI()); + LOGERROR3(F("Channel:"), WiFi.channel(), F(",IP address:"), WiFi.localIP() ); + } + else + LOGERROR(F("WiFi not connected")); - return status; + return status; } void heartBeatPrint() { - static int num = 1; + static int num = 1; - if (WiFi.status() == WL_CONNECTED) - Serial.print(F("H")); // H means connected to WiFi - else - Serial.print(F("F")); // F means not connected to WiFi + if (WiFi.status() == WL_CONNECTED) + Serial.print(F("H")); // H means connected to WiFi + else + Serial.print(F("F")); // F means not connected to WiFi - if (num == 80) - { - Serial.println(); - num = 1; - } - else if (num++ % 10 == 0) - { - Serial.print(F(" ")); - } + if (num == 80) + { + Serial.println(); + num = 1; + } + else if (num++ % 10 == 0) + { + Serial.print(F(" ")); + } } void check_WiFi() { - if ( (WiFi.status() != WL_CONNECTED) ) - { - Serial.println(F("\nWiFi lost. Call connectMultiWiFi in loop")); - connectMultiWiFi(); - } + if ( (WiFi.status() != WL_CONNECTED) ) + { + Serial.println(F("\nWiFi lost. Call connectMultiWiFi in loop")); + connectMultiWiFi(); + } } void check_status() { - static ulong checkstatus_timeout = 0; - static ulong checkwifi_timeout = 0; + static ulong checkstatus_timeout = 0; + static ulong checkwifi_timeout = 0; - static ulong current_millis; + static ulong current_millis; #define WIFICHECK_INTERVAL 1000L #define HEARTBEAT_INTERVAL 10000L - current_millis = millis(); + current_millis = millis(); - // Check WiFi every WIFICHECK_INTERVAL (1) seconds. - if ((current_millis > checkwifi_timeout) || (checkwifi_timeout == 0)) - { - check_WiFi(); - checkwifi_timeout = current_millis + WIFICHECK_INTERVAL; - } + // Check WiFi every WIFICHECK_INTERVAL (1) seconds. + if ((current_millis > checkwifi_timeout) || (checkwifi_timeout == 0)) + { + check_WiFi(); + checkwifi_timeout = current_millis + WIFICHECK_INTERVAL; + } - // Print hearbeat every HEARTBEAT_INTERVAL (10) seconds. - if ((current_millis > checkstatus_timeout) || (checkstatus_timeout == 0)) - { - heartBeatPrint(); - checkstatus_timeout = current_millis + HEARTBEAT_INTERVAL; - } + // Print hearbeat every HEARTBEAT_INTERVAL (10) seconds. + if ((current_millis > checkstatus_timeout) || (checkstatus_timeout == 0)) + { + heartBeatPrint(); + checkstatus_timeout = current_millis + HEARTBEAT_INTERVAL; + } } void loadConfigData() { - File file = FileFS.open(CONFIG_FILENAME, "r"); - LOGERROR(F("LoadWiFiCfgFile ")); + File file = FileFS.open(CONFIG_FILENAME, "r"); + LOGERROR(F("LoadWiFiCfgFile ")); - memset(&WM_config, 0, sizeof(WM_config)); + memset(&WM_config, 0, sizeof(WM_config)); - // New in v1.4.0 - //memset(&WM_STA_IPconfig, 0, sizeof(WM_STA_IPconfig)); - // New in v1.8.2 - initSTAIPConfigStruct(WM_STA_IPconfig); - ////// + // New in v1.4.0 + //memset(&WM_STA_IPconfig, 0, sizeof(WM_STA_IPconfig)); + // New in v1.8.2 + initSTAIPConfigStruct(WM_STA_IPconfig); + ////// - if (file) - { - file.readBytes((char *) &WM_config, sizeof(WM_config)); + if (file) + { + file.readBytes((char *) &WM_config, sizeof(WM_config)); - // New in v1.4.0 - file.readBytes((char *) &WM_STA_IPconfig, sizeof(WM_STA_IPconfig)); - ////// + // New in v1.4.0 + file.readBytes((char *) &WM_STA_IPconfig, sizeof(WM_STA_IPconfig)); + ////// - file.close(); - LOGERROR(F("OK")); + file.close(); + LOGERROR(F("OK")); - // New in v1.4.0 - displayIPConfigStruct(WM_STA_IPconfig); - ////// - } - else - { - LOGERROR(F("failed")); - } + // New in v1.4.0 + displayIPConfigStruct(WM_STA_IPconfig); + ////// + } + else + { + LOGERROR(F("failed")); + } } void saveConfigData() { - File file = FileFS.open(CONFIG_FILENAME, "w"); - LOGERROR(F("SaveWiFiCfgFile ")); + File file = FileFS.open(CONFIG_FILENAME, "w"); + LOGERROR(F("SaveWiFiCfgFile ")); - if (file) - { - file.write((uint8_t*) &WM_config, sizeof(WM_config)); + if (file) + { + file.write((uint8_t*) &WM_config, sizeof(WM_config)); - // New in v1.4.0 - file.write((uint8_t*) &WM_STA_IPconfig, sizeof(WM_STA_IPconfig)); - ////// + // New in v1.4.0 + file.write((uint8_t*) &WM_STA_IPconfig, sizeof(WM_STA_IPconfig)); + ////// - file.close(); - LOGERROR(F("OK")); - } - else - { - LOGERROR(F("failed")); - } + file.close(); + LOGERROR(F("OK")); + } + else + { + LOGERROR(F("failed")); + } } void sendRequest() { - static bool requestOpenResult; + static bool requestOpenResult; - if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) - { - //requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt"); - requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt"); + if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) + { + //requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt"); + requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt"); - if (requestOpenResult) - { - // Only send() if open() returns true, or crash - request.send(); - } - else - { - Serial.println(F("Can't send bad request")); - } - } - else - { - Serial.println(F("Can't send request")); - } + if (requestOpenResult) + { + // Only send() if open() returns true, or crash + request.send(); + } + else + { + Serial.println(F("Can't send bad request")); + } + } + else + { + Serial.println(F("Can't send request")); + } } void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState) { - (void) optParm; + (void) optParm; - if (readyState == readyStateDone) - { - AHTTP_LOGDEBUG(F("\n**************************************")); - AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); + if (readyState == readyStateDone) + { + AHTTP_LOGDEBUG(F("\n**************************************")); + AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); - if (request->responseHTTPcode() == 200) - { - Serial.println(F("\n**************************************")); - Serial.println(request->responseText()); - Serial.println(F("**************************************")); - } - } + if (request->responseHTTPcode() == 200) + { + Serial.println(F("\n**************************************")); + Serial.println(request->responseText()); + Serial.println(F("**************************************")); + } + } } void setup() { - // put your setup code here, to run once: - Serial.begin(115200); + // put your setup code here, to run once: + Serial.begin(115200); - while (!Serial && millis() < 5000); + while (!Serial && millis() < 5000); - delay(200); + delay(200); - Serial.print(F("\nStarting AsyncHTTPRequest_ESP_WiFiManager using ")); - Serial.print(FS_Name); - Serial.print(F(" on ")); - Serial.println(ARDUINO_BOARD); - Serial.println(ESP_ASYNC_WIFIMANAGER_VERSION); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); + Serial.print(F("\nStarting AsyncHTTPRequest_ESP_WiFiManager using ")); + Serial.print(FS_Name); + Serial.print(F(" on ")); + Serial.println(ARDUINO_BOARD); + Serial.println(ESP_ASYNC_WIFIMANAGER_VERSION); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); #if defined(ESP_ASYNC_WIFIMANAGER_VERSION_INT) - if (ESP_ASYNC_WIFIMANAGER_VERSION_INT < ESP_ASYNC_WIFIMANAGER_VERSION_MIN) - { - Serial.print(F("Warning. Must use this example on Version later than : ")); - Serial.println(ESP_ASYNC_WIFIMANAGER_VERSION_MIN_TARGET); - } + if (ESP_ASYNC_WIFIMANAGER_VERSION_INT < ESP_ASYNC_WIFIMANAGER_VERSION_MIN) + { + Serial.print(F("Warning. Must use this example on Version later than : ")); + Serial.println(ESP_ASYNC_WIFIMANAGER_VERSION_MIN_TARGET); + } #endif #if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - { - Serial.print(F("Warning. Must use this example on Version equal or later than : ")); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); - } + if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) + { + Serial.print(F("Warning. Must use this example on Version equal or later than : ")); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); + } #endif - if (FORMAT_FILESYSTEM) - FileFS.format(); + if (FORMAT_FILESYSTEM) + FileFS.format(); - // Format FileFS if not yet + // Format FileFS if not yet #ifdef ESP32 - if (!FileFS.begin(true)) + if (!FileFS.begin(true)) #else - if (!FileFS.begin()) + if (!FileFS.begin()) #endif - { - Serial.print(FS_Name); - Serial.println(F(" failed! AutoFormatting.")); + { + Serial.print(FS_Name); + Serial.println(F(" failed! AutoFormatting.")); #ifdef ESP8266 - FileFS.format(); + FileFS.format(); #endif - } + } - unsigned long startedAt = millis(); + unsigned long startedAt = millis(); - // New in v1.4.0 - initAPIPConfigStruct(WM_AP_IPconfig); - initSTAIPConfigStruct(WM_STA_IPconfig); - ////// + // New in v1.4.0 + initAPIPConfigStruct(WM_AP_IPconfig); + initSTAIPConfigStruct(WM_STA_IPconfig); + ////// - //Local intialization. Once its business is done, there is no need to keep it around - // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX - //ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer); - // Use this to personalize DHCP hostname (RFC952 conformed) - AsyncWebServer webServer(HTTP_PORT); + //Local intialization. Once its business is done, there is no need to keep it around + // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX + //ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer); + // Use this to personalize DHCP hostname (RFC952 conformed) + AsyncWebServer webServer(HTTP_PORT); - //ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer, "AutoConnectAP"); + //ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer, "AutoConnectAP"); #if ( USING_ESP32_S2 || USING_ESP32_C3 ) - ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, NULL, "AutoConnectAP"); + ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, NULL, "AutoConnectAP"); #else - AsyncDNSServer dnsServer; + AsyncDNSServer dnsServer; - ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer, "AutoConnectAP"); + ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer, "AutoConnectAP"); #endif - //ESPAsync_wifiManager.setDebugOutput(true); + //ESPAsync_wifiManager.setDebugOutput(true); - //reset settings - for testing - //ESPAsync_wifiManager.resetSettings(); + //reset settings - for testing + //ESPAsync_wifiManager.resetSettings(); #if USE_CUSTOM_AP_IP - //set custom ip for portal - // New in v1.4.0 - ESPAsync_wifiManager.setAPStaticIPConfig(WM_AP_IPconfig); - ////// + //set custom ip for portal + // New in v1.4.0 + ESPAsync_wifiManager.setAPStaticIPConfig(WM_AP_IPconfig); + ////// #endif - ESPAsync_wifiManager.setMinimumSignalQuality(-1); + ESPAsync_wifiManager.setMinimumSignalQuality(-1); - // From v1.0.10 only - // Set config portal channel, default = 1. Use 0 => random channel from 1-13 - ESPAsync_wifiManager.setConfigPortalChannel(0); - ////// + // From v1.0.10 only + // Set config portal channel, default = 1. Use 0 => random channel from 1-13 + ESPAsync_wifiManager.setConfigPortalChannel(0); + ////// #if !USE_DHCP_IP - // Set (static IP, Gateway, Subnetmask, DNS1 and DNS2) or (IP, Gateway, Subnetmask). New in v1.0.5 - // New in v1.4.0 - ESPAsync_wifiManager.setSTAStaticIPConfig(WM_STA_IPconfig); - ////// + // Set (static IP, Gateway, Subnetmask, DNS1 and DNS2) or (IP, Gateway, Subnetmask). New in v1.0.5 + // New in v1.4.0 + ESPAsync_wifiManager.setSTAStaticIPConfig(WM_STA_IPconfig); + ////// #endif - // New from v1.1.1 + // New from v1.1.1 #if USING_CORS_FEATURE - ESPAsync_wifiManager.setCORSHeader("Your Access-Control-Allow-Origin"); + ESPAsync_wifiManager.setCORSHeader("Your Access-Control-Allow-Origin"); #endif - // We can't use WiFi.SSID() in ESP32 as it's only valid after connected. - // SSID and Password stored in ESP32 wifi_ap_record_t and wifi_config_t are also cleared in reboot - // Have to create a new function to store in EEPROM/SPIFFS for this purpose - Router_SSID = ESPAsync_wifiManager.WiFi_SSID(); - Router_Pass = ESPAsync_wifiManager.WiFi_Pass(); + // We can't use WiFi.SSID() in ESP32 as it's only valid after connected. + // SSID and Password stored in ESP32 wifi_ap_record_t and wifi_config_t are also cleared in reboot + // Have to create a new function to store in EEPROM/SPIFFS for this purpose + Router_SSID = ESPAsync_wifiManager.WiFi_SSID(); + Router_Pass = ESPAsync_wifiManager.WiFi_Pass(); - //Remove this line if you do not want to see WiFi password printed - Serial.print(F("Stored: SSID = ")); - Serial.print(Router_SSID); - Serial.print(F(", Pass = ")); - Serial.println(Router_Pass); + //Remove this line if you do not want to see WiFi password printed + Serial.print(F("Stored: SSID = ")); + Serial.print(Router_SSID); + Serial.print(F(", Pass = ")); + Serial.println(Router_Pass); - if (Router_SSID != "") - { - ESPAsync_wifiManager.setConfigPortalTimeout(120); //If no access point name has been previously entered disable timeout. - Serial.println(F("Got stored Credentials. Timeout 120s")); - } - else - { - Serial.println(F("No stored Credentials. No timeout")); - } + if (Router_SSID != "") + { + ESPAsync_wifiManager.setConfigPortalTimeout(120); //If no access point name has been previously entered disable timeout. + Serial.println(F("Got stored Credentials. Timeout 120s")); + } + else + { + Serial.println(F("No stored Credentials. No timeout")); + } - String chipID = String(ESP_getChipId(), HEX); - chipID.toUpperCase(); + String chipID = String(ESP_getChipId(), HEX); + chipID.toUpperCase(); - // SSID and PW for Config Portal - String AP_SSID = "ESP_" + chipID + "_AutoConnectAP"; - String AP_PASS = "MyESP_" + chipID; + // SSID and PW for Config Portal + String AP_SSID = "ESP_" + chipID + "_AutoConnectAP"; + String AP_PASS = "MyESP_" + chipID; - // From v1.1.0, Don't permit NULL password - if ( (Router_SSID == "") || (Router_Pass == "") ) - { - Serial.println(F("We haven't got any access point credentials, so get them now")); + // From v1.1.0, Don't permit NULL password + if ( (Router_SSID == "") || (Router_Pass == "") ) + { + Serial.println(F("We haven't got any access point credentials, so get them now")); - initialConfig = true; + initialConfig = true; - Serial.print(F("Starting configuration portal @ ")); + Serial.print(F("Starting configuration portal @ ")); #if USE_CUSTOM_AP_IP - Serial.print(APStaticIP); + Serial.print(APStaticIP); #else - Serial.print(F("192.168.4.1")); + Serial.print(F("192.168.4.1")); #endif - Serial.print(F(", SSID = ")); - Serial.print(AP_SSID); - Serial.print(F(", PASS = ")); - Serial.println(AP_PASS); + Serial.print(F(", SSID = ")); + Serial.print(AP_SSID); + Serial.print(F(", PASS = ")); + Serial.println(AP_PASS); - // Starts an access point - //if (!ESPAsync_wifiManager.startConfigPortal((const char *) ssid.c_str(), password)) - if ( !ESPAsync_wifiManager.startConfigPortal(AP_SSID.c_str(), AP_PASS.c_str()) ) - Serial.println(F("Not connected to WiFi but continuing anyway.")); - else - Serial.println(F("WiFi connected...yeey :)")); + // Starts an access point + //if (!ESPAsync_wifiManager.startConfigPortal((const char *) ssid.c_str(), password)) + if ( !ESPAsync_wifiManager.startConfigPortal(AP_SSID.c_str(), AP_PASS.c_str()) ) + Serial.println(F("Not connected to WiFi but continuing anyway.")); + else + Serial.println(F("WiFi connected...yeey :)")); - // Stored for later usage, from v1.1.0, but clear first - memset(&WM_config, 0, sizeof(WM_config)); + // Stored for later usage, from v1.1.0, but clear first + memset(&WM_config, 0, sizeof(WM_config)); - for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++) - { - String tempSSID = ESPAsync_wifiManager.getSSID(i); - String tempPW = ESPAsync_wifiManager.getPW(i); + for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++) + { + String tempSSID = ESPAsync_wifiManager.getSSID(i); + String tempPW = ESPAsync_wifiManager.getPW(i); - if (strlen(tempSSID.c_str()) < sizeof(WM_config.WiFi_Creds[i].wifi_ssid) - 1) - strcpy(WM_config.WiFi_Creds[i].wifi_ssid, tempSSID.c_str()); - else - strncpy(WM_config.WiFi_Creds[i].wifi_ssid, tempSSID.c_str(), sizeof(WM_config.WiFi_Creds[i].wifi_ssid) - 1); + if (strlen(tempSSID.c_str()) < sizeof(WM_config.WiFi_Creds[i].wifi_ssid) - 1) + strcpy(WM_config.WiFi_Creds[i].wifi_ssid, tempSSID.c_str()); + else + strncpy(WM_config.WiFi_Creds[i].wifi_ssid, tempSSID.c_str(), sizeof(WM_config.WiFi_Creds[i].wifi_ssid) - 1); - if (strlen(tempPW.c_str()) < sizeof(WM_config.WiFi_Creds[i].wifi_pw) - 1) - strcpy(WM_config.WiFi_Creds[i].wifi_pw, tempPW.c_str()); - else - strncpy(WM_config.WiFi_Creds[i].wifi_pw, tempPW.c_str(), sizeof(WM_config.WiFi_Creds[i].wifi_pw) - 1); + if (strlen(tempPW.c_str()) < sizeof(WM_config.WiFi_Creds[i].wifi_pw) - 1) + strcpy(WM_config.WiFi_Creds[i].wifi_pw, tempPW.c_str()); + else + strncpy(WM_config.WiFi_Creds[i].wifi_pw, tempPW.c_str(), sizeof(WM_config.WiFi_Creds[i].wifi_pw) - 1); - // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) - if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) - { - LOGERROR3(F("* Add SSID = "), WM_config.WiFi_Creds[i].wifi_ssid, F(", PW = "), WM_config.WiFi_Creds[i].wifi_pw ); - wifiMulti.addAP(WM_config.WiFi_Creds[i].wifi_ssid, WM_config.WiFi_Creds[i].wifi_pw); - } - } + // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) + if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "") + && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) + { + LOGERROR3(F("* Add SSID = "), WM_config.WiFi_Creds[i].wifi_ssid, F(", PW = "), WM_config.WiFi_Creds[i].wifi_pw ); + wifiMulti.addAP(WM_config.WiFi_Creds[i].wifi_ssid, WM_config.WiFi_Creds[i].wifi_pw); + } + } - // New in v1.4.0 - ESPAsync_wifiManager.getSTAStaticIPConfig(WM_STA_IPconfig); - displayIPConfigStruct(WM_STA_IPconfig); - ////// + // New in v1.4.0 + ESPAsync_wifiManager.getSTAStaticIPConfig(WM_STA_IPconfig); + displayIPConfigStruct(WM_STA_IPconfig); + ////// - saveConfigData(); - } - else - { - wifiMulti.addAP(Router_SSID.c_str(), Router_Pass.c_str()); - } + saveConfigData(); + } + else + { + wifiMulti.addAP(Router_SSID.c_str(), Router_Pass.c_str()); + } - startedAt = millis(); + startedAt = millis(); - if (!initialConfig) - { - // Load stored data, the addAP ready for MultiWiFi reconnection - loadConfigData(); + if (!initialConfig) + { + // Load stored data, the addAP ready for MultiWiFi reconnection + loadConfigData(); - for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++) - { - // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) - if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) - { - LOGERROR3(F("* Add SSID = "), WM_config.WiFi_Creds[i].wifi_ssid, F(", PW = "), WM_config.WiFi_Creds[i].wifi_pw ); - wifiMulti.addAP(WM_config.WiFi_Creds[i].wifi_ssid, WM_config.WiFi_Creds[i].wifi_pw); - } - } + for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++) + { + // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) + if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "") + && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) + { + LOGERROR3(F("* Add SSID = "), WM_config.WiFi_Creds[i].wifi_ssid, F(", PW = "), WM_config.WiFi_Creds[i].wifi_pw ); + wifiMulti.addAP(WM_config.WiFi_Creds[i].wifi_ssid, WM_config.WiFi_Creds[i].wifi_pw); + } + } - if ( WiFi.status() != WL_CONNECTED ) - { - Serial.println(F("ConnectMultiWiFi in setup")); + if ( WiFi.status() != WL_CONNECTED ) + { + Serial.println(F("ConnectMultiWiFi in setup")); - connectMultiWiFi(); - } - } + connectMultiWiFi(); + } + } - Serial.print(F("After waiting ")); - Serial.print((float) (millis() - startedAt) / 1000L); - Serial.print(F(" secs more in setup(), connection result is ")); + Serial.print(F("After waiting ")); + Serial.print((float) (millis() - startedAt) / 1000L); + Serial.print(F(" secs more in setup(), connection result is ")); - if (WiFi.status() == WL_CONNECTED) - { - Serial.print(F("connected. Local IP: ")); - Serial.println(WiFi.localIP()); - } - else - Serial.println(ESPAsync_wifiManager.getStatus(WiFi.status())); + if (WiFi.status() == WL_CONNECTED) + { + Serial.print(F("connected. Local IP: ")); + Serial.println(WiFi.localIP()); + } + else + Serial.println(ESPAsync_wifiManager.getStatus(WiFi.status())); - request.setDebug(false); + request.setDebug(false); - request.onReadyStateChange(requestCB); - ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest); + request.onReadyStateChange(requestCB); + ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest); - // Send first request now - sendRequest(); + // Send first request now + sendRequest(); } void loop() { - // put your main code here, to run repeatedly - check_status(); + // put your main code here, to run repeatedly + check_status(); } diff --git a/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino b/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino index ec4a997..bdb13ce 100644 --- a/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino +++ b/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino @@ -65,91 +65,91 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS); void sendRequest() { - static bool requestOpenResult; + static bool requestOpenResult; - if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) - { - //requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt"); - requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt"); + if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) + { + //requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt"); + requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt"); - if (requestOpenResult) - { - // Only send() if open() returns true, or crash - request.send(); - } - else - { - Serial.println("Can't send bad request"); - } - } - else - { - Serial.println("Can't send request"); - } + if (requestOpenResult) + { + // Only send() if open() returns true, or crash + request.send(); + } + else + { + Serial.println("Can't send bad request"); + } + } + else + { + Serial.println("Can't send request"); + } } void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState) { - (void) optParm; + (void) optParm; - if (readyState == readyStateDone) - { - AHTTP_LOGDEBUG(F("\n**************************************")); - AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); + if (readyState == readyStateDone) + { + AHTTP_LOGDEBUG(F("\n**************************************")); + AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); - if (request->responseHTTPcode() == 200) - { - Serial.println(F("\n**************************************")); - Serial.println(request->responseText()); - Serial.println(F("**************************************")); - } - } + if (request->responseHTTPcode() == 200) + { + Serial.println(F("\n**************************************")); + Serial.println(request->responseText()); + Serial.println(F("**************************************")); + } + } } void setup() { - Serial.begin(115200); + Serial.begin(115200); - while (!Serial && millis() < 5000); + while (!Serial && millis() < 5000); - Serial.print("\nStart AsyncHTTPRequest_STM32 on "); - Serial.println(BOARD_NAME); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); + Serial.print("\nStart AsyncHTTPRequest_STM32 on "); + Serial.println(BOARD_NAME); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); #if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - { - Serial.print("Warning. Must use this example on Version equal or later than : "); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); - } + if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) + { + Serial.print("Warning. Must use this example on Version equal or later than : "); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); + } #endif - // start the ethernet connection and the server - // Use random mac - uint16_t index = millis() % NUMBER_OF_MAC; + // start the ethernet connection and the server + // Use random mac + uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - // Use DHCP dynamic IP and random mac - Ethernet.begin(mac[index]); + // Use Static IP + //Ethernet.begin(mac[index], ip); + // Use DHCP dynamic IP and random mac + Ethernet.begin(mac[index]); - Serial.print(F("AsyncHTTPRequest @ IP : ")); - Serial.println(Ethernet.localIP()); - Serial.println(); + Serial.print(F("AsyncHTTPRequest @ IP : ")); + Serial.println(Ethernet.localIP()); + Serial.println(); - request.setDebug(false); + request.setDebug(false); - request.onReadyStateChange(requestCB); - sendHTTPRequest.start(); //start the ticker. + request.onReadyStateChange(requestCB); + sendHTTPRequest.start(); //start the ticker. - // Send first request now - //delay(60); - sendRequest(); + // Send first request now + //delay(60); + sendRequest(); } void loop() { - sendHTTPRequest.update(); + sendHTTPRequest.update(); } diff --git a/examples/AsyncHTTPRequest_STM32/defines.h b/examples/AsyncHTTPRequest_STM32/defines.h index 44a9364..fd7592b 100644 --- a/examples/AsyncHTTPRequest_STM32/defines.h +++ b/examples/AsyncHTTPRequest_STM32/defines.h @@ -46,54 +46,54 @@ #if defined(STM32F0) - #warning STM32F0 board selected - #define BOARD_TYPE "STM32F0" + #warning STM32F0 board selected + #define BOARD_TYPE "STM32F0" #elif defined(STM32F1) - #warning STM32F1 board selected - #define BOARD_TYPE "STM32F1" + #warning STM32F1 board selected + #define BOARD_TYPE "STM32F1" #elif defined(STM32F2) - #warning STM32F2 board selected - #define BOARD_TYPE "STM32F2" + #warning STM32F2 board selected + #define BOARD_TYPE "STM32F2" #elif defined(STM32F3) - #warning STM32F3 board selected - #define BOARD_TYPE "STM32F3" + #warning STM32F3 board selected + #define BOARD_TYPE "STM32F3" #elif defined(STM32F4) - #warning STM32F4 board selected - #define BOARD_TYPE "STM32F4" + #warning STM32F4 board selected + #define BOARD_TYPE "STM32F4" #elif defined(STM32F7) - #warning STM32F7 board selected - #define BOARD_TYPE "STM32F7" + #warning STM32F7 board selected + #define BOARD_TYPE "STM32F7" #elif defined(STM32L0) - #warning STM32L0 board selected - #define BOARD_TYPE "STM32L0" + #warning STM32L0 board selected + #define BOARD_TYPE "STM32L0" #elif defined(STM32L1) - #warning STM32L1 board selected - #define BOARD_TYPE "STM32L1" + #warning STM32L1 board selected + #define BOARD_TYPE "STM32L1" #elif defined(STM32L4) - #warning STM32L4 board selected - #define BOARD_TYPE "STM32L4" + #warning STM32L4 board selected + #define BOARD_TYPE "STM32L4" #elif defined(STM32H7) - #warning STM32H7 board selected - #define BOARD_TYPE "STM32H7" + #warning STM32H7 board selected + #define BOARD_TYPE "STM32H7" #elif defined(STM32G0) - #warning STM32G0 board selected - #define BOARD_TYPE "STM32G0" + #warning STM32G0 board selected + #define BOARD_TYPE "STM32G0" #elif defined(STM32G4) - #warning STM32G4 board selected - #define BOARD_TYPE "STM32G4" + #warning STM32G4 board selected + #define BOARD_TYPE "STM32G4" #elif defined(STM32WB) - #warning STM32WB board selected - #define BOARD_TYPE "STM32WB" + #warning STM32WB board selected + #define BOARD_TYPE "STM32WB" #elif defined(STM32MP1) - #warning STM32MP1 board selected - #define BOARD_TYPE "STM32MP1" + #warning STM32MP1 board selected + #define BOARD_TYPE "STM32MP1" #else - #warning STM32 unknown board selected - #define BOARD_TYPE "STM32 Unknown" + #warning STM32 unknown board selected + #define BOARD_TYPE "STM32 Unknown" #endif #ifndef BOARD_NAME - #define BOARD_NAME BOARD_TYPE + #define BOARD_NAME BOARD_TYPE #endif #include @@ -106,26 +106,26 @@ byte mac[][NUMBER_OF_MAC] = { - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, }; // Select the static IP address according to your local network diff --git a/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino b/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino index ea22db4..040cc67 100644 --- a/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino +++ b/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino @@ -47,90 +47,90 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS); void sendRequest() { - static bool requestOpenResult; + static bool requestOpenResult; - if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) - { - requestOpenResult = request.open("GET", GET_ServerAddress); + if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) + { + requestOpenResult = request.open("GET", GET_ServerAddress); - if (requestOpenResult) - { - // Only send() if open() returns true, or crash - request.send(); - } - else - { - Serial.println("Can't send bad request"); - } - } - else - { - Serial.println("Can't send request"); - } + if (requestOpenResult) + { + // Only send() if open() returns true, or crash + request.send(); + } + else + { + Serial.println("Can't send bad request"); + } + } + else + { + Serial.println("Can't send request"); + } } void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState) { - (void) optParm; + (void) optParm; - if (readyState == readyStateDone) - { - AHTTP_LOGDEBUG(F("\n**************************************")); - AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); + if (readyState == readyStateDone) + { + AHTTP_LOGDEBUG(F("\n**************************************")); + AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); - if (request->responseHTTPcode() == 200) - { - Serial.println(F("\n**************************************")); - Serial.println(request->responseText()); - Serial.println(F("**************************************")); - } - } + if (request->responseHTTPcode() == 200) + { + Serial.println(F("\n**************************************")); + Serial.println(request->responseText()); + Serial.println(F("**************************************")); + } + } } void setup() { - Serial.begin(115200); + Serial.begin(115200); - while (!Serial && millis() < 5000); + while (!Serial && millis() < 5000); - Serial.print("\nStart AsyncSimpleGET_STM32 on "); - Serial.println(BOARD_NAME); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); + Serial.print("\nStart AsyncSimpleGET_STM32 on "); + Serial.println(BOARD_NAME); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); #if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - { - Serial.print("Warning. Must use this example on Version equal or later than : "); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); - } + if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) + { + Serial.print("Warning. Must use this example on Version equal or later than : "); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); + } #endif - // start the ethernet connection and the server - // Use random mac - uint16_t index = millis() % NUMBER_OF_MAC; + // start the ethernet connection and the server + // Use random mac + uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - // Use DHCP dynamic IP and random mac - Ethernet.begin(mac[index]); + // Use Static IP + //Ethernet.begin(mac[index], ip); + // Use DHCP dynamic IP and random mac + Ethernet.begin(mac[index]); - Serial.print(F("AsyncHTTPRequest @ IP : ")); - Serial.println(Ethernet.localIP()); - Serial.println(); + Serial.print(F("AsyncHTTPRequest @ IP : ")); + Serial.println(Ethernet.localIP()); + Serial.println(); - request.setDebug(false); + request.setDebug(false); - request.onReadyStateChange(requestCB); - sendHTTPRequest.start(); //start the ticker. + request.onReadyStateChange(requestCB); + sendHTTPRequest.start(); //start the ticker. - // Send first request now - delay(10000); - sendRequest(); + // Send first request now + delay(10000); + sendRequest(); } void loop() { - sendHTTPRequest.update(); + sendHTTPRequest.update(); } diff --git a/examples/AsyncSimpleGET_STM32/defines.h b/examples/AsyncSimpleGET_STM32/defines.h index 44a9364..fd7592b 100644 --- a/examples/AsyncSimpleGET_STM32/defines.h +++ b/examples/AsyncSimpleGET_STM32/defines.h @@ -46,54 +46,54 @@ #if defined(STM32F0) - #warning STM32F0 board selected - #define BOARD_TYPE "STM32F0" + #warning STM32F0 board selected + #define BOARD_TYPE "STM32F0" #elif defined(STM32F1) - #warning STM32F1 board selected - #define BOARD_TYPE "STM32F1" + #warning STM32F1 board selected + #define BOARD_TYPE "STM32F1" #elif defined(STM32F2) - #warning STM32F2 board selected - #define BOARD_TYPE "STM32F2" + #warning STM32F2 board selected + #define BOARD_TYPE "STM32F2" #elif defined(STM32F3) - #warning STM32F3 board selected - #define BOARD_TYPE "STM32F3" + #warning STM32F3 board selected + #define BOARD_TYPE "STM32F3" #elif defined(STM32F4) - #warning STM32F4 board selected - #define BOARD_TYPE "STM32F4" + #warning STM32F4 board selected + #define BOARD_TYPE "STM32F4" #elif defined(STM32F7) - #warning STM32F7 board selected - #define BOARD_TYPE "STM32F7" + #warning STM32F7 board selected + #define BOARD_TYPE "STM32F7" #elif defined(STM32L0) - #warning STM32L0 board selected - #define BOARD_TYPE "STM32L0" + #warning STM32L0 board selected + #define BOARD_TYPE "STM32L0" #elif defined(STM32L1) - #warning STM32L1 board selected - #define BOARD_TYPE "STM32L1" + #warning STM32L1 board selected + #define BOARD_TYPE "STM32L1" #elif defined(STM32L4) - #warning STM32L4 board selected - #define BOARD_TYPE "STM32L4" + #warning STM32L4 board selected + #define BOARD_TYPE "STM32L4" #elif defined(STM32H7) - #warning STM32H7 board selected - #define BOARD_TYPE "STM32H7" + #warning STM32H7 board selected + #define BOARD_TYPE "STM32H7" #elif defined(STM32G0) - #warning STM32G0 board selected - #define BOARD_TYPE "STM32G0" + #warning STM32G0 board selected + #define BOARD_TYPE "STM32G0" #elif defined(STM32G4) - #warning STM32G4 board selected - #define BOARD_TYPE "STM32G4" + #warning STM32G4 board selected + #define BOARD_TYPE "STM32G4" #elif defined(STM32WB) - #warning STM32WB board selected - #define BOARD_TYPE "STM32WB" + #warning STM32WB board selected + #define BOARD_TYPE "STM32WB" #elif defined(STM32MP1) - #warning STM32MP1 board selected - #define BOARD_TYPE "STM32MP1" + #warning STM32MP1 board selected + #define BOARD_TYPE "STM32MP1" #else - #warning STM32 unknown board selected - #define BOARD_TYPE "STM32 Unknown" + #warning STM32 unknown board selected + #define BOARD_TYPE "STM32 Unknown" #endif #ifndef BOARD_NAME - #define BOARD_NAME BOARD_TYPE + #define BOARD_NAME BOARD_TYPE #endif #include @@ -106,26 +106,26 @@ byte mac[][NUMBER_OF_MAC] = { - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, }; // Select the static IP address according to your local network diff --git a/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino b/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino index 7aaad3e..3e907c5 100644 --- a/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino +++ b/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino @@ -49,88 +49,88 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS); void sendRequest() { - static bool requestOpenResult; + static bool requestOpenResult; - if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) - { - requestOpenResult = request.open("GET", (GET_ServerAddress + GET_Location).c_str()); + if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) + { + requestOpenResult = request.open("GET", (GET_ServerAddress + GET_Location).c_str()); - if (requestOpenResult) - { - // Only send() if open() returns true, or crash - request.send(); - } - else - { - Serial.println("Can't send bad request"); - } - } - else - { - Serial.println("Can't send request"); - } + if (requestOpenResult) + { + // Only send() if open() returns true, or crash + request.send(); + } + else + { + Serial.println("Can't send bad request"); + } + } + else + { + Serial.println("Can't send request"); + } } void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState) { - (void) optParm; + (void) optParm; - if (readyState == readyStateDone) - { - AHTTP_LOGDEBUG(F("\n**************************************")); - AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); + if (readyState == readyStateDone) + { + AHTTP_LOGDEBUG(F("\n**************************************")); + AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); - if (request->responseHTTPcode() == 200) - { - Serial.println(F("\n**************************************")); - Serial.println(request->responseText()); - Serial.println(F("**************************************")); - } - } + if (request->responseHTTPcode() == 200) + { + Serial.println(F("\n**************************************")); + Serial.println(request->responseText()); + Serial.println(F("**************************************")); + } + } } void setup() { - Serial.begin(115200); + Serial.begin(115200); - while (!Serial && millis() < 5000); + while (!Serial && millis() < 5000); - Serial.print("\nStart AsyncWebClientRepeating_STM32 on "); - Serial.println(BOARD_NAME); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); + Serial.print("\nStart AsyncWebClientRepeating_STM32 on "); + Serial.println(BOARD_NAME); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); #if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - { - Serial.print("Warning. Must use this example on Version equal or later than : "); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); - } + if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) + { + Serial.print("Warning. Must use this example on Version equal or later than : "); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); + } #endif - // start the ethernet connection and the server - // Use random mac - uint16_t index = millis() % NUMBER_OF_MAC; + // start the ethernet connection and the server + // Use random mac + uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - // Use DHCP dynamic IP and random mac - Ethernet.begin(mac[index]); + // Use Static IP + //Ethernet.begin(mac[index], ip); + // Use DHCP dynamic IP and random mac + Ethernet.begin(mac[index]); - Serial.print(F("AsyncHTTPRequest @ IP : ")); - Serial.println(Ethernet.localIP()); - Serial.println(); + Serial.print(F("AsyncHTTPRequest @ IP : ")); + Serial.println(Ethernet.localIP()); + Serial.println(); - request.setDebug(false); + request.setDebug(false); - request.onReadyStateChange(requestCB); - sendHTTPRequest.start(); //start the ticker + request.onReadyStateChange(requestCB); + sendHTTPRequest.start(); //start the ticker - // Send first request now - sendRequest(); + // Send first request now + sendRequest(); } void loop() { - sendHTTPRequest.update(); + sendHTTPRequest.update(); } diff --git a/examples/AsyncWebClientRepeating_STM32/defines.h b/examples/AsyncWebClientRepeating_STM32/defines.h index 44a9364..fd7592b 100644 --- a/examples/AsyncWebClientRepeating_STM32/defines.h +++ b/examples/AsyncWebClientRepeating_STM32/defines.h @@ -46,54 +46,54 @@ #if defined(STM32F0) - #warning STM32F0 board selected - #define BOARD_TYPE "STM32F0" + #warning STM32F0 board selected + #define BOARD_TYPE "STM32F0" #elif defined(STM32F1) - #warning STM32F1 board selected - #define BOARD_TYPE "STM32F1" + #warning STM32F1 board selected + #define BOARD_TYPE "STM32F1" #elif defined(STM32F2) - #warning STM32F2 board selected - #define BOARD_TYPE "STM32F2" + #warning STM32F2 board selected + #define BOARD_TYPE "STM32F2" #elif defined(STM32F3) - #warning STM32F3 board selected - #define BOARD_TYPE "STM32F3" + #warning STM32F3 board selected + #define BOARD_TYPE "STM32F3" #elif defined(STM32F4) - #warning STM32F4 board selected - #define BOARD_TYPE "STM32F4" + #warning STM32F4 board selected + #define BOARD_TYPE "STM32F4" #elif defined(STM32F7) - #warning STM32F7 board selected - #define BOARD_TYPE "STM32F7" + #warning STM32F7 board selected + #define BOARD_TYPE "STM32F7" #elif defined(STM32L0) - #warning STM32L0 board selected - #define BOARD_TYPE "STM32L0" + #warning STM32L0 board selected + #define BOARD_TYPE "STM32L0" #elif defined(STM32L1) - #warning STM32L1 board selected - #define BOARD_TYPE "STM32L1" + #warning STM32L1 board selected + #define BOARD_TYPE "STM32L1" #elif defined(STM32L4) - #warning STM32L4 board selected - #define BOARD_TYPE "STM32L4" + #warning STM32L4 board selected + #define BOARD_TYPE "STM32L4" #elif defined(STM32H7) - #warning STM32H7 board selected - #define BOARD_TYPE "STM32H7" + #warning STM32H7 board selected + #define BOARD_TYPE "STM32H7" #elif defined(STM32G0) - #warning STM32G0 board selected - #define BOARD_TYPE "STM32G0" + #warning STM32G0 board selected + #define BOARD_TYPE "STM32G0" #elif defined(STM32G4) - #warning STM32G4 board selected - #define BOARD_TYPE "STM32G4" + #warning STM32G4 board selected + #define BOARD_TYPE "STM32G4" #elif defined(STM32WB) - #warning STM32WB board selected - #define BOARD_TYPE "STM32WB" + #warning STM32WB board selected + #define BOARD_TYPE "STM32WB" #elif defined(STM32MP1) - #warning STM32MP1 board selected - #define BOARD_TYPE "STM32MP1" + #warning STM32MP1 board selected + #define BOARD_TYPE "STM32MP1" #else - #warning STM32 unknown board selected - #define BOARD_TYPE "STM32 Unknown" + #warning STM32 unknown board selected + #define BOARD_TYPE "STM32 Unknown" #endif #ifndef BOARD_NAME - #define BOARD_NAME BOARD_TYPE + #define BOARD_NAME BOARD_TYPE #endif #include @@ -106,26 +106,26 @@ byte mac[][NUMBER_OF_MAC] = { - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, }; // Select the static IP address according to your local network diff --git a/examples/WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01.ino b/examples/WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01.ino index 0d1b137..f953e61 100644 --- a/examples/WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01.ino +++ b/examples/WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01.ino @@ -41,7 +41,7 @@ //************************************************************************************************************* #if !( defined(ESP32) ) - #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. + #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. #endif // Level from 0-4 @@ -86,22 +86,22 @@ IPAddress myDNS(8, 8, 8, 8); void heartBeatPrint(void) { - static int num = 1; + static int num = 1; - if (WT32_ETH01_isConnected()) - Serial.print(F("H")); // H means connected to WiFi - else - Serial.print(F("F")); // F means not connected to WiFi + if (WT32_ETH01_isConnected()) + Serial.print(F("H")); // H means connected to WiFi + else + Serial.print(F("F")); // F means not connected to WiFi - if (num == 80) - { - Serial.println(); - num = 1; - } - else if (num++ % 10 == 0) - { - Serial.print(F(" ")); - } + if (num == 80) + { + Serial.println(); + num = 1; + } + else if (num++ % 10 == 0) + { + Serial.print(F(" ")); + } } // To replace with your real APP_API @@ -127,118 +127,118 @@ uint8_t requestIndex = 0; void sendRequest() { - static bool requestOpenResult; + static bool requestOpenResult; - if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) - { - requestOpenResult = request.open("GET", requestAll[requestIndex] ); + if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) + { + requestOpenResult = request.open("GET", requestAll[requestIndex] ); - if (requestOpenResult) - { - // Only send() if open() returns true, or crash - request.send(); - } - else - { - Serial.println("Can't send bad request"); - } - } - else - { - Serial.println("Can't send request"); - } + if (requestOpenResult) + { + // Only send() if open() returns true, or crash + request.send(); + } + else + { + Serial.println("Can't send bad request"); + } + } + else + { + Serial.println("Can't send request"); + } } void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState) { - (void) optParm; + (void) optParm; - if (readyState == readyStateDone) - { - AHTTP_LOGDEBUG(F("\n**************************************")); - AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); + if (readyState == readyStateDone) + { + AHTTP_LOGDEBUG(F("\n**************************************")); + AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); - if (request->responseHTTPcode() == 200) - { - Serial.print(F("\n***************")); - Serial.print(requestName[ requestIndex ]); - Serial.println(F("***************")); - Serial.println(request->responseText()); - Serial.println(F("**************************************")); - } + if (request->responseHTTPcode() == 200) + { + Serial.print(F("\n***************")); + Serial.print(requestName[ requestIndex ]); + Serial.println(F("***************")); + Serial.println(request->responseText()); + Serial.println(F("**************************************")); + } #if 1 - // Bypass hourly - if (requestIndex == 1) - requestIndex = 3; - else - requestIndex = (requestIndex + 1) % NUM_REQUESTS; + // Bypass hourly + if (requestIndex == 1) + requestIndex = 3; + else + requestIndex = (requestIndex + 1) % NUM_REQUESTS; #else - // hourly too long, not display anyway. Not enough heap. - requestIndex = (requestIndex + 1) % NUM_REQUESTS; + // hourly too long, not display anyway. Not enough heap. + requestIndex = (requestIndex + 1) % NUM_REQUESTS; #endif - request->setDebug(false); - } + request->setDebug(false); + } } void setup() { - // put your setup code here, to run once: - Serial.begin(115200); + // put your setup code here, to run once: + Serial.begin(115200); - while (!Serial && millis() < 5000); + while (!Serial && millis() < 5000); - delay(200); + delay(200); - Serial.print("\nStart AsyncHTTPMultiRequests_WT32_ETH01 on "); - Serial.print(ARDUINO_BOARD); - Serial.print(" with "); - Serial.println(SHIELD_TYPE); - Serial.println(WEBSERVER_WT32_ETH01_VERSION); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); + Serial.print("\nStart AsyncHTTPMultiRequests_WT32_ETH01 on "); + Serial.print(ARDUINO_BOARD); + Serial.print(" with "); + Serial.println(SHIELD_TYPE); + Serial.println(WEBSERVER_WT32_ETH01_VERSION); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); - Serial.setDebugOutput(true); + Serial.setDebugOutput(true); #if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - { - Serial.print("Warning. Must use this example on Version equal or later than : "); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); - } + if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) + { + Serial.print("Warning. Must use this example on Version equal or later than : "); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); + } #endif - // To be called before ETH.begin() - WT32_ETH01_onEvent(); + // To be called before ETH.begin() + WT32_ETH01_onEvent(); - //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, - // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); - //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); - ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); + //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, + // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); + //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); + ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); - // Static IP, leave without this line to get IP via DHCP - //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); - ETH.config(myIP, myGW, mySN, myDNS); + // Static IP, leave without this line to get IP via DHCP + //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); + ETH.config(myIP, myGW, mySN, myDNS); - WT32_ETH01_waitForConnect(); + WT32_ETH01_waitForConnect(); - Serial.print(F("AsyncHTTPRequest @ IP : ")); - Serial.println(ETH.localIP()); + Serial.print(F("AsyncHTTPRequest @ IP : ")); + Serial.println(ETH.localIP()); - request.setDebug(false); + request.setDebug(false); - request.onReadyStateChange(requestCB); - ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest); + request.onReadyStateChange(requestCB); + ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest); - ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint); + ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint); - // Send first request now - sendRequest(); + // Send first request now + sendRequest(); } void loop() diff --git a/examples/WT32_ETH01/AsyncHTTPRequest_WT32_ETH01/AsyncHTTPRequest_WT32_ETH01.ino b/examples/WT32_ETH01/AsyncHTTPRequest_WT32_ETH01/AsyncHTTPRequest_WT32_ETH01.ino index 5f0d96a..f1ef809 100644 --- a/examples/WT32_ETH01/AsyncHTTPRequest_WT32_ETH01/AsyncHTTPRequest_WT32_ETH01.ino +++ b/examples/WT32_ETH01/AsyncHTTPRequest_WT32_ETH01/AsyncHTTPRequest_WT32_ETH01.ino @@ -41,7 +41,7 @@ //************************************************************************************************************* #if !( defined(ESP32) ) - #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. + #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. #endif // Level from 0-4 @@ -86,121 +86,121 @@ IPAddress myDNS(8, 8, 8, 8); void heartBeatPrint(void) { - static int num = 1; + static int num = 1; - if (WT32_ETH01_isConnected()) - Serial.print(F("H")); // H means connected - else - Serial.print(F("F")); // F means not connected + if (WT32_ETH01_isConnected()) + Serial.print(F("H")); // H means connected + else + Serial.print(F("F")); // F means not connected - if (num == 80) - { - Serial.println(); - num = 1; - } - else if (num++ % 10 == 0) - { - Serial.print(F(" ")); - } + if (num == 80) + { + Serial.println(); + num = 1; + } + else if (num++ % 10 == 0) + { + Serial.print(F(" ")); + } } void sendRequest() { - static bool requestOpenResult; + static bool requestOpenResult; - if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) - { - //requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt"); - requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt"); + if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone) + { + //requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt"); + requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt"); - if (requestOpenResult) - { - // Only send() if open() returns true, or crash - request.send(); - } - else - { - Serial.println("Can't send bad request"); - } - } - else - { - Serial.println("Can't send request"); - } + if (requestOpenResult) + { + // Only send() if open() returns true, or crash + request.send(); + } + else + { + Serial.println("Can't send bad request"); + } + } + else + { + Serial.println("Can't send request"); + } } void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState) { - (void) optParm; + (void) optParm; - if (readyState == readyStateDone) - { - AHTTP_LOGDEBUG(F("\n**************************************")); - AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); + if (readyState == readyStateDone) + { + AHTTP_LOGDEBUG(F("\n**************************************")); + AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); - if (request->responseHTTPcode() == 200) - { - Serial.println(F("\n**************************************")); - Serial.println(request->responseText()); - Serial.println(F("**************************************")); - } - } + if (request->responseHTTPcode() == 200) + { + Serial.println(F("\n**************************************")); + Serial.println(request->responseText()); + Serial.println(F("**************************************")); + } + } } void setup() { - // put your setup code here, to run once: - Serial.begin(115200); + // put your setup code here, to run once: + Serial.begin(115200); - while (!Serial && millis() < 5000); + while (!Serial && millis() < 5000); - delay(200); + delay(200); - Serial.print("\nStart AsyncHTTPRequest_WT32_ETH01 on "); - Serial.print(ARDUINO_BOARD); - Serial.print(" with "); - Serial.println(SHIELD_TYPE); - Serial.println(WEBSERVER_WT32_ETH01_VERSION); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); + Serial.print("\nStart AsyncHTTPRequest_WT32_ETH01 on "); + Serial.print(ARDUINO_BOARD); + Serial.print(" with "); + Serial.println(SHIELD_TYPE); + Serial.println(WEBSERVER_WT32_ETH01_VERSION); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); - Serial.setDebugOutput(true); + Serial.setDebugOutput(true); #if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - { - Serial.print("Warning. Must use this example on Version equal or later than : "); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); - } + if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) + { + Serial.print("Warning. Must use this example on Version equal or later than : "); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); + } #endif - // To be called before ETH.begin() - WT32_ETH01_onEvent(); + // To be called before ETH.begin() + WT32_ETH01_onEvent(); - //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, - // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); - //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); - ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); + //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, + // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); + //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); + ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); - // Static IP, leave without this line to get IP via DHCP - //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); - ETH.config(myIP, myGW, mySN, myDNS); + // Static IP, leave without this line to get IP via DHCP + //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); + ETH.config(myIP, myGW, mySN, myDNS); - WT32_ETH01_waitForConnect(); + WT32_ETH01_waitForConnect(); - Serial.print(F("\nHTTP WebClient is @ IP : ")); - Serial.println(ETH.localIP()); + Serial.print(F("\nHTTP WebClient is @ IP : ")); + Serial.println(ETH.localIP()); - request.setDebug(false); + request.setDebug(false); - request.onReadyStateChange(requestCB); - ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest); + request.onReadyStateChange(requestCB); + ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest); - ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint); + ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint); - // Send first request now - sendRequest(); + // Send first request now + sendRequest(); } void loop() diff --git a/examples/multiFileProject/multiFileProject.ino b/examples/multiFileProject/multiFileProject.ino index 47cc6dc..ef6666f 100644 --- a/examples/multiFileProject/multiFileProject.ino +++ b/examples/multiFileProject/multiFileProject.ino @@ -29,25 +29,25 @@ void setup() { - Serial.begin(115200); + Serial.begin(115200); - while (!Serial); + while (!Serial); - Serial.println("\nStart multiFileProject"); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); + Serial.println("\nStart multiFileProject"); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); #if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) - { - Serial.print("Warning. Must use this example on Version equal or later than : "); - Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); - } + if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) + { + Serial.print("Warning. Must use this example on Version equal or later than : "); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); + } #endif } void loop() { - // put your main code here, to run repeatedly: + // put your main code here, to run repeatedly: } diff --git a/platformio/platformio.ini b/platformio/platformio.ini index f743b4d..6783175 100644 --- a/platformio/platformio.ini +++ b/platformio/platformio.ini @@ -52,7 +52,7 @@ lib_deps = ; PlatformIO 5.x ; me-no-dev/AsyncTCP@>=1.1.1 ; me-no-dev/ESPAsyncTCP@>=1.2.2 -; philbowles/STM32AsyncTCP +; philbowles/STM32AsyncTCP ; https://github.com/khoih-prog/STM32AsyncTCP.git ; stm32duino/STM32duino LwIP@>=2.1.2 ; stm32duino/STM32duino STM32Ethernet@>=1.3.0