mirror of
https://github.com/khoih-prog/AsyncHTTPRequest_Generic.git
synced 2025-07-29 18:07:15 +02:00
v1.10.2 default to reconnect to the same host:port
### Releases v1.10.2 1. Default to reconnect to the same `host:port` after connected for new HTTP sites. Check [Host/Headers not always sent with 1.10.1 #44](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues44) 2. Update `Packages' Patches`
This commit is contained in:
@ -29,11 +29,10 @@ Please ensure to specify the following:
|
|||||||
Arduino IDE version: 1.8.19
|
Arduino IDE version: 1.8.19
|
||||||
ESP32 Core Version 2.0.5
|
ESP32 Core Version 2.0.5
|
||||||
OS: Ubuntu 20.04 LTS
|
OS: Ubuntu 20.04 LTS
|
||||||
Linux xy-Inspiron-3593 5.15.0-50-generic #56~20.04.1-Ubuntu SMP Tue Sep 27 15:51:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
|
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
|
||||||
|
|
||||||
Context:
|
Context:
|
||||||
I encountered a crash when using this library
|
I encountered a crash while using this library
|
||||||
|
|
||||||
Steps to reproduce:
|
Steps to reproduce:
|
||||||
1. ...
|
1. ...
|
||||||
2. ...
|
2. ...
|
||||||
@ -41,13 +40,38 @@ Steps to reproduce:
|
|||||||
4. ...
|
4. ...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Additional context
|
||||||
|
|
||||||
|
Add any other context about the problem here.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### Sending Feature Requests
|
### Sending Feature Requests
|
||||||
|
|
||||||
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
|
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
|
||||||
|
|
||||||
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
|
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### Sending Pull Requests
|
### Sending Pull Requests
|
||||||
|
|
||||||
Pull Requests with changes and fixes are also welcome!
|
Pull Requests with changes and fixes are also welcome!
|
||||||
|
|
||||||
|
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
|
||||||
|
|
||||||
|
1. Change directory to the library GitHub
|
||||||
|
|
||||||
|
```
|
||||||
|
xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncHTTPRequest_Generic_GitHub/
|
||||||
|
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncHTTPRequest_Generic_GitHub$
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Issue astyle command
|
||||||
|
|
||||||
|
```
|
||||||
|
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncHTTPRequest_Generic_GitHub$ bash utils/restyle.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
* [Changelog](#changelog)
|
* [Changelog](#changelog)
|
||||||
|
* [Releases v1.10.2](#releases-v1102)
|
||||||
* [Releases v1.10.1](#releases-v1101)
|
* [Releases v1.10.1](#releases-v1101)
|
||||||
* [Releases v1.10.0](#releases-v1100)
|
* [Releases v1.10.0](#releases-v1100)
|
||||||
* [Releases v1.9.2](#releases-v192)
|
* [Releases v1.9.2](#releases-v192)
|
||||||
@ -44,6 +45,11 @@
|
|||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
### Releases v1.10.2
|
||||||
|
|
||||||
|
1. Default to reconnect to the same `host:port` after connected for new HTTP sites. Check [Host/Headers not always sent with 1.10.1 #44](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues44)
|
||||||
|
2. Update `Packages' Patches`
|
||||||
|
|
||||||
### Releases v1.10.1
|
### Releases v1.10.1
|
||||||
|
|
||||||
1. Fix bug of wrong `reqStates`. Check [Release 1.9 breakes previously running code #39](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/39) and [Callback behaviour is buggy (ESP8266) #43](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/43)
|
1. Fix bug of wrong `reqStates`. Check [Release 1.9 breakes previously running code #39](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/39) and [Callback behaviour is buggy (ESP8266) #43](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/43)
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
AsyncCustomHeader_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
AsyncCustomHeader_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
@ -24,12 +24,15 @@
|
|||||||
//char GET_ServerAddress[] = "192.168.2.110/";
|
//char GET_ServerAddress[] = "192.168.2.110/";
|
||||||
char GET_ServerAddress[] = "http://worldtimeapi.org/api/timezone/America/Toronto.txt";
|
char GET_ServerAddress[] = "http://worldtimeapi.org/api/timezone/America/Toronto.txt";
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.1"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2"
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010001
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010002
|
||||||
|
|
||||||
// 600s = 10 minutes to not flooding, 60s in testing
|
// 600s = 10 minutes to not flooding, 60s in testing
|
||||||
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
|
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
|
||||||
|
|
||||||
|
// Uncomment for certain HTTP site to optimize
|
||||||
|
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
|
||||||
|
|
||||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||||
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
|
|
||||||
@ -44,97 +47,102 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
|||||||
|
|
||||||
void sendRequest(void)
|
void sendRequest(void)
|
||||||
{
|
{
|
||||||
static bool requestOpenResult;
|
static bool requestOpenResult;
|
||||||
|
|
||||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||||
{
|
{
|
||||||
Serial.println("\nSending GET Request to " + String(GET_ServerAddress));
|
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)
|
//request.setReqHeader("X-CUSTOM-HEADER", "custom_value");
|
||||||
{
|
if (requestOpenResult)
|
||||||
// Only send() if open() returns true, or crash
|
{
|
||||||
request.send();
|
// Only send() if open() returns true, or crash
|
||||||
}
|
request.send();
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
Serial.println("Can't send bad request");
|
{
|
||||||
}
|
Serial.println("Can't send bad request");
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
Serial.println("Can't send request");
|
{
|
||||||
}
|
Serial.println("Can't send request");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
|
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
|
||||||
{
|
{
|
||||||
(void) optParm;
|
(void) optParm;
|
||||||
|
|
||||||
if (readyState == readyStateDone)
|
if (readyState == readyStateDone)
|
||||||
{
|
{
|
||||||
Serial.println();
|
Serial.println();
|
||||||
AHTTP_LOGDEBUG(F("**************************************"));
|
AHTTP_LOGDEBUG(F("**************************************"));
|
||||||
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
||||||
|
|
||||||
if (request->responseHTTPcode() == 200)
|
if (request->responseHTTPcode() == 200)
|
||||||
{
|
{
|
||||||
Serial.println(F("**************************************"));
|
Serial.println(F("**************************************"));
|
||||||
Serial.println(request->responseText());
|
Serial.println(request->responseText());
|
||||||
Serial.println(F("**************************************"));
|
Serial.println(F("**************************************"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AHTTP_LOGERROR(F("Response error"));
|
AHTTP_LOGERROR(F("Response error"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup(void)
|
void setup(void)
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
while (!Serial && millis() < 5000);
|
|
||||||
|
|
||||||
Serial.print("\nStart AsyncCustomHeader_STM32 on "); Serial.println(BOARD_NAME);
|
while (!Serial && millis() < 5000);
|
||||||
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 defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
|
||||||
if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < 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);
|
Serial.print("Warning. Must use this example on Version equal or later than : ");
|
||||||
}
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// start the ethernet connection and the server
|
// start the ethernet connection and the server
|
||||||
// Use random mac
|
// Use random mac
|
||||||
uint16_t index = millis() % NUMBER_OF_MAC;
|
uint16_t index = millis() % NUMBER_OF_MAC;
|
||||||
|
|
||||||
// Use Static IP
|
// Use Static IP
|
||||||
//Ethernet.begin(mac[index], ip);
|
//Ethernet.begin(mac[index], ip);
|
||||||
// Use DHCP dynamic IP and random mac
|
// Use DHCP dynamic IP and random mac
|
||||||
Ethernet.begin(mac[index]);
|
Ethernet.begin(mac[index]);
|
||||||
|
|
||||||
Serial.print(F("AsyncHTTPRequest @ IP : "));
|
Serial.print(F("AsyncHTTPRequest @ IP : "));
|
||||||
Serial.println(Ethernet.localIP());
|
Serial.println(Ethernet.localIP());
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
request.setDebug(false);
|
request.setDebug(false);
|
||||||
|
|
||||||
// 5s timeout
|
// 5s timeout
|
||||||
request.setTimeout(5);
|
request.setTimeout(5);
|
||||||
|
|
||||||
request.onReadyStateChange(requestCB);
|
request.onReadyStateChange(requestCB);
|
||||||
|
|
||||||
sendHTTPRequest.start(); //start the ticker.
|
sendHTTPRequest.start(); //start the ticker.
|
||||||
|
|
||||||
// Send first request now
|
// Send first request now
|
||||||
delay(10000);
|
delay(10000);
|
||||||
sendRequest();
|
sendRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(void)
|
void loop(void)
|
||||||
{
|
{
|
||||||
sendHTTPRequest.update();
|
sendHTTPRequest.update();
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
defines.h
|
defines.h
|
||||||
|
|
||||||
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
/*
|
/*
|
||||||
Currently support
|
Currently support
|
||||||
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
|
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
|
||||||
- Nucleo-144 (F429ZI, F767ZI)
|
- Nucleo-144 (F429ZI, F767ZI)
|
||||||
- Discovery (STM32F746G-DISCOVERY)
|
- Discovery (STM32F746G-DISCOVERY)
|
||||||
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
|
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
|
||||||
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
|
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
|
||||||
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
|
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
|
||||||
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
|
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
|
||||||
@ -36,7 +36,7 @@
|
|||||||
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
|
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
|
||||||
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
|
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
|
||||||
defined(STM32WB) || defined(STM32MP1) )
|
defined(STM32WB) || defined(STM32MP1) )
|
||||||
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
|
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ASYNC_HTTP_DEBUG_PORT Serial
|
#define ASYNC_HTTP_DEBUG_PORT Serial
|
||||||
@ -46,54 +46,54 @@
|
|||||||
|
|
||||||
|
|
||||||
#if defined(STM32F0)
|
#if defined(STM32F0)
|
||||||
#warning STM32F0 board selected
|
#warning STM32F0 board selected
|
||||||
#define BOARD_TYPE "STM32F0"
|
#define BOARD_TYPE "STM32F0"
|
||||||
#elif defined(STM32F1)
|
#elif defined(STM32F1)
|
||||||
#warning STM32F1 board selected
|
#warning STM32F1 board selected
|
||||||
#define BOARD_TYPE "STM32F1"
|
#define BOARD_TYPE "STM32F1"
|
||||||
#elif defined(STM32F2)
|
#elif defined(STM32F2)
|
||||||
#warning STM32F2 board selected
|
#warning STM32F2 board selected
|
||||||
#define BOARD_TYPE "STM32F2"
|
#define BOARD_TYPE "STM32F2"
|
||||||
#elif defined(STM32F3)
|
#elif defined(STM32F3)
|
||||||
#warning STM32F3 board selected
|
#warning STM32F3 board selected
|
||||||
#define BOARD_TYPE "STM32F3"
|
#define BOARD_TYPE "STM32F3"
|
||||||
#elif defined(STM32F4)
|
#elif defined(STM32F4)
|
||||||
#warning STM32F4 board selected
|
#warning STM32F4 board selected
|
||||||
#define BOARD_TYPE "STM32F4"
|
#define BOARD_TYPE "STM32F4"
|
||||||
#elif defined(STM32F7)
|
#elif defined(STM32F7)
|
||||||
#warning STM32F7 board selected
|
#warning STM32F7 board selected
|
||||||
#define BOARD_TYPE "STM32F7"
|
#define BOARD_TYPE "STM32F7"
|
||||||
#elif defined(STM32L0)
|
#elif defined(STM32L0)
|
||||||
#warning STM32L0 board selected
|
#warning STM32L0 board selected
|
||||||
#define BOARD_TYPE "STM32L0"
|
#define BOARD_TYPE "STM32L0"
|
||||||
#elif defined(STM32L1)
|
#elif defined(STM32L1)
|
||||||
#warning STM32L1 board selected
|
#warning STM32L1 board selected
|
||||||
#define BOARD_TYPE "STM32L1"
|
#define BOARD_TYPE "STM32L1"
|
||||||
#elif defined(STM32L4)
|
#elif defined(STM32L4)
|
||||||
#warning STM32L4 board selected
|
#warning STM32L4 board selected
|
||||||
#define BOARD_TYPE "STM32L4"
|
#define BOARD_TYPE "STM32L4"
|
||||||
#elif defined(STM32H7)
|
#elif defined(STM32H7)
|
||||||
#warning STM32H7 board selected
|
#warning STM32H7 board selected
|
||||||
#define BOARD_TYPE "STM32H7"
|
#define BOARD_TYPE "STM32H7"
|
||||||
#elif defined(STM32G0)
|
#elif defined(STM32G0)
|
||||||
#warning STM32G0 board selected
|
#warning STM32G0 board selected
|
||||||
#define BOARD_TYPE "STM32G0"
|
#define BOARD_TYPE "STM32G0"
|
||||||
#elif defined(STM32G4)
|
#elif defined(STM32G4)
|
||||||
#warning STM32G4 board selected
|
#warning STM32G4 board selected
|
||||||
#define BOARD_TYPE "STM32G4"
|
#define BOARD_TYPE "STM32G4"
|
||||||
#elif defined(STM32WB)
|
#elif defined(STM32WB)
|
||||||
#warning STM32WB board selected
|
#warning STM32WB board selected
|
||||||
#define BOARD_TYPE "STM32WB"
|
#define BOARD_TYPE "STM32WB"
|
||||||
#elif defined(STM32MP1)
|
#elif defined(STM32MP1)
|
||||||
#warning STM32MP1 board selected
|
#warning STM32MP1 board selected
|
||||||
#define BOARD_TYPE "STM32MP1"
|
#define BOARD_TYPE "STM32MP1"
|
||||||
#else
|
#else
|
||||||
#warning STM32 unknown board selected
|
#warning STM32 unknown board selected
|
||||||
#define BOARD_TYPE "STM32 Unknown"
|
#define BOARD_TYPE "STM32 Unknown"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef BOARD_NAME
|
#ifndef BOARD_NAME
|
||||||
#define BOARD_NAME BOARD_TYPE
|
#define BOARD_NAME BOARD_TYPE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <LwIP.h>
|
#include <LwIP.h>
|
||||||
@ -106,26 +106,26 @@
|
|||||||
|
|
||||||
byte mac[][NUMBER_OF_MAC] =
|
byte mac[][NUMBER_OF_MAC] =
|
||||||
{
|
{
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Select the static IP address according to your local network
|
// Select the static IP address according to your local network
|
||||||
|
@ -1,46 +1,50 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
AsyncDweetGET_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
AsyncDweetGET_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Connects to dweet.io once every 1 minutes, sends a GET request and a request body.
|
Connects to dweet.io once every 1 minutes, sends a GET request and a request body.
|
||||||
|
|
||||||
Shows how to use Strings to assemble path and parse content from response.
|
Shows how to use Strings to assemble path and parse content from response.
|
||||||
dweet.io expects: https://dweet.io/dweet/for/thingName
|
dweet.io expects: https://dweet.io/dweet/for/thingName
|
||||||
|
|
||||||
For more on dweet.io, see https://dweet.io/play/
|
For more on dweet.io, see https://dweet.io/play/
|
||||||
* */
|
* */
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
// Select a test server address
|
// Select a test server address
|
||||||
const char GET_ServerAddress[] = "dweet.io";
|
const char GET_ServerAddress[] = "dweet.io";
|
||||||
|
|
||||||
// use your own thing name here
|
// use your own thing name here
|
||||||
String dweetName = "/dweet/for/currentSecond?second=";
|
String dweetName = "/dweet/for/currentSecond?second=";
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.1"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2"
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010001
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010002
|
||||||
|
|
||||||
// 600s = 10 minutes to not flooding, 60s in testing
|
// 600s = 10 minutes to not flooding, 60s in testing
|
||||||
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
|
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
|
||||||
|
|
||||||
|
// Uncomment for certain HTTP site to optimize
|
||||||
|
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
|
||||||
|
|
||||||
|
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||||
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
|
|
||||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||||
@ -53,132 +57,136 @@ AsyncHTTPRequest request;
|
|||||||
void sendRequest(void);
|
void sendRequest(void);
|
||||||
|
|
||||||
// Repeat forever, millis() resolution
|
// Repeat forever, millis() resolution
|
||||||
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
||||||
|
|
||||||
void sendRequest(void)
|
void sendRequest(void)
|
||||||
{
|
{
|
||||||
static bool requestOpenResult;
|
static bool requestOpenResult;
|
||||||
|
|
||||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||||
{
|
{
|
||||||
requestOpenResult = request.open("GET", (GET_ServerAddress + dweetName + String(millis()/1000)).c_str() );
|
requestOpenResult = request.open("GET", (GET_ServerAddress + dweetName + String(millis() / 1000)).c_str() );
|
||||||
|
|
||||||
if (requestOpenResult)
|
if (requestOpenResult)
|
||||||
{
|
{
|
||||||
// Only send() if open() returns true, or crash
|
// Only send() if open() returns true, or crash
|
||||||
request.send();
|
request.send();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Can't send bad request");
|
Serial.println("Can't send bad request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Can't send request");
|
Serial.println("Can't send request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void parseResponse(String responseText)
|
void parseResponse(String responseText)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Typical response is:
|
Typical response is:
|
||||||
{"this":"succeeded",
|
{"this":"succeeded",
|
||||||
"by":"getting",
|
"by":"getting",
|
||||||
"the":"dweets",
|
"the":"dweets",
|
||||||
"with":[{"thing":"my-thing-name",
|
"with":[{"thing":"my-thing-name",
|
||||||
"created":"2016-02-16T05:10:36.589Z",
|
"created":"2016-02-16T05:10:36.589Z",
|
||||||
"content":{"sensorValue":456}}]}
|
"content":{"sensorValue":456}}]}
|
||||||
|
|
||||||
You want "content": numberValue
|
You want "content": numberValue
|
||||||
*/
|
*/
|
||||||
// now parse the response looking for "content":
|
// now parse the response looking for "content":
|
||||||
int labelStart = responseText.indexOf("content\":");
|
int labelStart = responseText.indexOf("content\":");
|
||||||
// find the first { after "content":
|
// find the first { after "content":
|
||||||
int contentStart = responseText.indexOf("{", labelStart);
|
int contentStart = responseText.indexOf("{", labelStart);
|
||||||
// find the following } and get what's between the braces:
|
// find the following } and get what's between the braces:
|
||||||
int contentEnd = responseText.indexOf("}", labelStart);
|
int contentEnd = responseText.indexOf("}", labelStart);
|
||||||
String content = responseText.substring(contentStart + 1, contentEnd);
|
String content = responseText.substring(contentStart + 1, contentEnd);
|
||||||
|
|
||||||
Serial.println(content);
|
|
||||||
|
|
||||||
// now get the value after the colon, and convert to an int:
|
Serial.println(content);
|
||||||
int valueStart = content.indexOf(":");
|
|
||||||
String valueString = content.substring(valueStart + 1);
|
// now get the value after the colon, and convert to an int:
|
||||||
int number = valueString.toInt();
|
int valueStart = content.indexOf(":");
|
||||||
|
String valueString = content.substring(valueStart + 1);
|
||||||
Serial.print("Value string: ");
|
int number = valueString.toInt();
|
||||||
Serial.println(valueString);
|
|
||||||
Serial.print("Actual value: ");
|
Serial.print("Value string: ");
|
||||||
Serial.println(number);
|
Serial.println(valueString);
|
||||||
|
Serial.print("Actual value: ");
|
||||||
|
Serial.println(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
|
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 (request->responseHTTPcode() == 200)
|
if (readyState == readyStateDone)
|
||||||
{
|
{
|
||||||
String responseText = request->responseText();
|
Serial.println();
|
||||||
|
AHTTP_LOGDEBUG(F("**************************************"));
|
||||||
Serial.println("\n**************************************");
|
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
||||||
//Serial.println(request->responseText());
|
|
||||||
Serial.println(responseText);
|
if (request->responseHTTPcode() == 200)
|
||||||
Serial.println("**************************************");
|
{
|
||||||
|
String responseText = request->responseText();
|
||||||
parseResponse(responseText);
|
|
||||||
|
Serial.println("\n**************************************");
|
||||||
request->setDebug(false);
|
//Serial.println(request->responseText());
|
||||||
}
|
Serial.println(responseText);
|
||||||
else
|
Serial.println("**************************************");
|
||||||
{
|
|
||||||
AHTTP_LOGERROR(F("Response error"));
|
parseResponse(responseText);
|
||||||
}
|
|
||||||
}
|
request->setDebug(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AHTTP_LOGERROR(F("Response error"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup(void)
|
void setup(void)
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
while (!Serial && millis() < 5000);
|
|
||||||
|
|
||||||
Serial.print("\nStart AsyncDweetGET_STM32 on "); Serial.println(BOARD_NAME);
|
while (!Serial && millis() < 5000);
|
||||||
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 defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
|
||||||
if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < 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);
|
Serial.print("Warning. Must use this example on Version equal or later than : ");
|
||||||
}
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// start the ethernet connection and the server
|
// start the ethernet connection and the server
|
||||||
// Use random mac
|
// Use random mac
|
||||||
uint16_t index = millis() % NUMBER_OF_MAC;
|
uint16_t index = millis() % NUMBER_OF_MAC;
|
||||||
|
|
||||||
// Use Static IP
|
// Use Static IP
|
||||||
//Ethernet.begin(mac[index], ip);
|
//Ethernet.begin(mac[index], ip);
|
||||||
// Use DHCP dynamic IP and random mac
|
// Use DHCP dynamic IP and random mac
|
||||||
Ethernet.begin(mac[index]);
|
Ethernet.begin(mac[index]);
|
||||||
|
|
||||||
Serial.print(F("AsyncHTTPRequest @ IP : "));
|
Serial.print(F("AsyncHTTPRequest @ IP : "));
|
||||||
Serial.println(Ethernet.localIP());
|
Serial.println(Ethernet.localIP());
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
request.setDebug(false);
|
request.setDebug(false);
|
||||||
|
|
||||||
request.onReadyStateChange(requestCB);
|
request.onReadyStateChange(requestCB);
|
||||||
sendHTTPRequest.start(); //start the ticker.
|
sendHTTPRequest.start(); //start the ticker.
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(void)
|
void loop(void)
|
||||||
{
|
{
|
||||||
sendHTTPRequest.update();
|
sendHTTPRequest.update();
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
defines.h
|
defines.h
|
||||||
|
|
||||||
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
/*
|
/*
|
||||||
Currently support
|
Currently support
|
||||||
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
|
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
|
||||||
- Nucleo-144 (F429ZI, F767ZI)
|
- Nucleo-144 (F429ZI, F767ZI)
|
||||||
- Discovery (STM32F746G-DISCOVERY)
|
- Discovery (STM32F746G-DISCOVERY)
|
||||||
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
|
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
|
||||||
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
|
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
|
||||||
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
|
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
|
||||||
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
|
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
|
||||||
@ -36,7 +36,7 @@
|
|||||||
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
|
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
|
||||||
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
|
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
|
||||||
defined(STM32WB) || defined(STM32MP1) )
|
defined(STM32WB) || defined(STM32MP1) )
|
||||||
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
|
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ASYNC_HTTP_DEBUG_PORT Serial
|
#define ASYNC_HTTP_DEBUG_PORT Serial
|
||||||
@ -46,54 +46,54 @@
|
|||||||
|
|
||||||
|
|
||||||
#if defined(STM32F0)
|
#if defined(STM32F0)
|
||||||
#warning STM32F0 board selected
|
#warning STM32F0 board selected
|
||||||
#define BOARD_TYPE "STM32F0"
|
#define BOARD_TYPE "STM32F0"
|
||||||
#elif defined(STM32F1)
|
#elif defined(STM32F1)
|
||||||
#warning STM32F1 board selected
|
#warning STM32F1 board selected
|
||||||
#define BOARD_TYPE "STM32F1"
|
#define BOARD_TYPE "STM32F1"
|
||||||
#elif defined(STM32F2)
|
#elif defined(STM32F2)
|
||||||
#warning STM32F2 board selected
|
#warning STM32F2 board selected
|
||||||
#define BOARD_TYPE "STM32F2"
|
#define BOARD_TYPE "STM32F2"
|
||||||
#elif defined(STM32F3)
|
#elif defined(STM32F3)
|
||||||
#warning STM32F3 board selected
|
#warning STM32F3 board selected
|
||||||
#define BOARD_TYPE "STM32F3"
|
#define BOARD_TYPE "STM32F3"
|
||||||
#elif defined(STM32F4)
|
#elif defined(STM32F4)
|
||||||
#warning STM32F4 board selected
|
#warning STM32F4 board selected
|
||||||
#define BOARD_TYPE "STM32F4"
|
#define BOARD_TYPE "STM32F4"
|
||||||
#elif defined(STM32F7)
|
#elif defined(STM32F7)
|
||||||
#warning STM32F7 board selected
|
#warning STM32F7 board selected
|
||||||
#define BOARD_TYPE "STM32F7"
|
#define BOARD_TYPE "STM32F7"
|
||||||
#elif defined(STM32L0)
|
#elif defined(STM32L0)
|
||||||
#warning STM32L0 board selected
|
#warning STM32L0 board selected
|
||||||
#define BOARD_TYPE "STM32L0"
|
#define BOARD_TYPE "STM32L0"
|
||||||
#elif defined(STM32L1)
|
#elif defined(STM32L1)
|
||||||
#warning STM32L1 board selected
|
#warning STM32L1 board selected
|
||||||
#define BOARD_TYPE "STM32L1"
|
#define BOARD_TYPE "STM32L1"
|
||||||
#elif defined(STM32L4)
|
#elif defined(STM32L4)
|
||||||
#warning STM32L4 board selected
|
#warning STM32L4 board selected
|
||||||
#define BOARD_TYPE "STM32L4"
|
#define BOARD_TYPE "STM32L4"
|
||||||
#elif defined(STM32H7)
|
#elif defined(STM32H7)
|
||||||
#warning STM32H7 board selected
|
#warning STM32H7 board selected
|
||||||
#define BOARD_TYPE "STM32H7"
|
#define BOARD_TYPE "STM32H7"
|
||||||
#elif defined(STM32G0)
|
#elif defined(STM32G0)
|
||||||
#warning STM32G0 board selected
|
#warning STM32G0 board selected
|
||||||
#define BOARD_TYPE "STM32G0"
|
#define BOARD_TYPE "STM32G0"
|
||||||
#elif defined(STM32G4)
|
#elif defined(STM32G4)
|
||||||
#warning STM32G4 board selected
|
#warning STM32G4 board selected
|
||||||
#define BOARD_TYPE "STM32G4"
|
#define BOARD_TYPE "STM32G4"
|
||||||
#elif defined(STM32WB)
|
#elif defined(STM32WB)
|
||||||
#warning STM32WB board selected
|
#warning STM32WB board selected
|
||||||
#define BOARD_TYPE "STM32WB"
|
#define BOARD_TYPE "STM32WB"
|
||||||
#elif defined(STM32MP1)
|
#elif defined(STM32MP1)
|
||||||
#warning STM32MP1 board selected
|
#warning STM32MP1 board selected
|
||||||
#define BOARD_TYPE "STM32MP1"
|
#define BOARD_TYPE "STM32MP1"
|
||||||
#else
|
#else
|
||||||
#warning STM32 unknown board selected
|
#warning STM32 unknown board selected
|
||||||
#define BOARD_TYPE "STM32 Unknown"
|
#define BOARD_TYPE "STM32 Unknown"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef BOARD_NAME
|
#ifndef BOARD_NAME
|
||||||
#define BOARD_NAME BOARD_TYPE
|
#define BOARD_NAME BOARD_TYPE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <LwIP.h>
|
#include <LwIP.h>
|
||||||
@ -106,26 +106,26 @@
|
|||||||
|
|
||||||
byte mac[][NUMBER_OF_MAC] =
|
byte mac[][NUMBER_OF_MAC] =
|
||||||
{
|
{
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Select the static IP address according to your local network
|
// Select the static IP address according to your local network
|
||||||
|
@ -1,40 +1,43 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
AsyncDweetPOST_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
AsyncDweetPOST_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
// Dweet.io POST client. Connects to dweet.io once every ten seconds, sends a POST request and a request body.
|
// Dweet.io POST client. Connects to dweet.io once every ten seconds, sends a POST request and a request body.
|
||||||
// Shows how to use Strings to assemble path and body
|
// Shows how to use Strings to assemble path and body
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
// Select a test server address
|
// Select a test server address
|
||||||
const char POST_ServerAddress[] = "dweet.io";
|
const char POST_ServerAddress[] = "dweet.io";
|
||||||
|
|
||||||
// use your own thing name here
|
// use your own thing name here
|
||||||
String dweetName = "/dweet/for/pinA0-Read?";
|
String dweetName = "/dweet/for/pinA0-Read?";
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.1"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2"
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010001
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010002
|
||||||
|
|
||||||
// 600s = 10 minutes to not flooding, 60s in testing
|
// 600s = 10 minutes to not flooding, 60s in testing
|
||||||
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
|
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
|
||||||
|
|
||||||
|
// Uncomment for certain HTTP site to optimize
|
||||||
|
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
|
||||||
|
|
||||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||||
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
|
|
||||||
@ -45,137 +48,141 @@ AsyncHTTPRequest request;
|
|||||||
void sendRequest(void);
|
void sendRequest(void);
|
||||||
|
|
||||||
// Repeat forever, millis() resolution
|
// Repeat forever, millis() resolution
|
||||||
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
||||||
|
|
||||||
void sendRequest(void)
|
void sendRequest(void)
|
||||||
{
|
{
|
||||||
static bool requestOpenResult;
|
static bool requestOpenResult;
|
||||||
|
|
||||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
|
||||||
{
|
|
||||||
String postData = "sensorValue=";
|
|
||||||
postData += analogRead(A0);
|
|
||||||
|
|
||||||
Serial.println("\nMaking new POST request");
|
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||||
|
{
|
||||||
|
String postData = "sensorValue=";
|
||||||
|
postData += analogRead(A0);
|
||||||
|
|
||||||
requestOpenResult = request.open("POST", (POST_ServerAddress + dweetName + postData).c_str() );
|
Serial.println("\nMaking new POST request");
|
||||||
|
|
||||||
if (requestOpenResult)
|
requestOpenResult = request.open("POST", (POST_ServerAddress + dweetName + postData).c_str() );
|
||||||
{
|
|
||||||
// Only send() if open() returns true, or crash
|
if (requestOpenResult)
|
||||||
request.send();
|
{
|
||||||
}
|
// Only send() if open() returns true, or crash
|
||||||
else
|
request.send();
|
||||||
{
|
}
|
||||||
Serial.println("Can't send bad request");
|
else
|
||||||
}
|
{
|
||||||
}
|
Serial.println("Can't send bad request");
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
Serial.println("Can't send request");
|
else
|
||||||
}
|
{
|
||||||
|
Serial.println("Can't send request");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void parseResponse(String responseText)
|
void parseResponse(String responseText)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Typical response is:
|
Typical response is:
|
||||||
{"this":"succeeded",
|
{"this":"succeeded",
|
||||||
"by":"getting",
|
"by":"getting",
|
||||||
"the":"dweets",
|
"the":"dweets",
|
||||||
"with":[{"thing":"my-thing-name",
|
"with":[{"thing":"my-thing-name",
|
||||||
"created":"2016-02-16T05:10:36.589Z",
|
"created":"2016-02-16T05:10:36.589Z",
|
||||||
"content":{"sensorValue":456}}]}
|
"content":{"sensorValue":456}}]}
|
||||||
|
|
||||||
You want "content": numberValue
|
You want "content": numberValue
|
||||||
*/
|
*/
|
||||||
// now parse the response looking for "content":
|
// now parse the response looking for "content":
|
||||||
int labelStart = responseText.indexOf("content\":");
|
int labelStart = responseText.indexOf("content\":");
|
||||||
// find the first { after "content":
|
// find the first { after "content":
|
||||||
int contentStart = responseText.indexOf("{", labelStart);
|
int contentStart = responseText.indexOf("{", labelStart);
|
||||||
// find the following } and get what's between the braces:
|
// find the following } and get what's between the braces:
|
||||||
int contentEnd = responseText.indexOf("}", labelStart);
|
int contentEnd = responseText.indexOf("}", labelStart);
|
||||||
String content = responseText.substring(contentStart + 1, contentEnd);
|
String content = responseText.substring(contentStart + 1, contentEnd);
|
||||||
|
|
||||||
Serial.println(content);
|
|
||||||
|
|
||||||
// now get the value after the colon, and convert to an int:
|
Serial.println(content);
|
||||||
int valueStart = content.indexOf(":");
|
|
||||||
String valueString = content.substring(valueStart + 1);
|
// now get the value after the colon, and convert to an int:
|
||||||
int number = valueString.toInt();
|
int valueStart = content.indexOf(":");
|
||||||
|
String valueString = content.substring(valueStart + 1);
|
||||||
Serial.print("Value string: ");
|
int number = valueString.toInt();
|
||||||
Serial.println(valueString);
|
|
||||||
Serial.print("Actual value: ");
|
Serial.print("Value string: ");
|
||||||
Serial.println(number);
|
Serial.println(valueString);
|
||||||
|
Serial.print("Actual value: ");
|
||||||
|
Serial.println(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
|
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 (request->responseHTTPcode() == 200)
|
if (readyState == readyStateDone)
|
||||||
{
|
{
|
||||||
String responseText = request->responseText();
|
Serial.println();
|
||||||
|
AHTTP_LOGDEBUG(F("**************************************"));
|
||||||
Serial.println("\n**************************************");
|
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
||||||
//Serial.println(request->responseText());
|
|
||||||
Serial.println(responseText);
|
if (request->responseHTTPcode() == 200)
|
||||||
Serial.println("**************************************");
|
{
|
||||||
|
String responseText = request->responseText();
|
||||||
parseResponse(responseText);
|
|
||||||
|
Serial.println("\n**************************************");
|
||||||
request->setDebug(false);
|
//Serial.println(request->responseText());
|
||||||
}
|
Serial.println(responseText);
|
||||||
else
|
Serial.println("**************************************");
|
||||||
{
|
|
||||||
AHTTP_LOGERROR(F("Response error"));
|
parseResponse(responseText);
|
||||||
}
|
|
||||||
}
|
request->setDebug(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AHTTP_LOGERROR(F("Response error"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup(void)
|
void setup(void)
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
while (!Serial && millis() < 5000);
|
|
||||||
|
|
||||||
Serial.print("\nStart AsyncDweetPOST_STM32 on "); Serial.println(BOARD_NAME);
|
while (!Serial && millis() < 5000);
|
||||||
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 defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
|
||||||
if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < 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);
|
Serial.print("Warning. Must use this example on Version equal or later than : ");
|
||||||
}
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// start the ethernet connection and the server
|
// start the ethernet connection and the server
|
||||||
// Use random mac
|
// Use random mac
|
||||||
uint16_t index = millis() % NUMBER_OF_MAC;
|
uint16_t index = millis() % NUMBER_OF_MAC;
|
||||||
|
|
||||||
// Use Static IP
|
// Use Static IP
|
||||||
//Ethernet.begin(mac[index], ip);
|
//Ethernet.begin(mac[index], ip);
|
||||||
// Use DHCP dynamic IP and random mac
|
// Use DHCP dynamic IP and random mac
|
||||||
Ethernet.begin(mac[index]);
|
Ethernet.begin(mac[index]);
|
||||||
|
|
||||||
Serial.print(F("AsyncHTTPRequest @ IP : "));
|
Serial.print(F("AsyncHTTPRequest @ IP : "));
|
||||||
Serial.println(Ethernet.localIP());
|
Serial.println(Ethernet.localIP());
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
request.setDebug(false);
|
request.setDebug(false);
|
||||||
|
|
||||||
request.onReadyStateChange(requestCB);
|
request.onReadyStateChange(requestCB);
|
||||||
sendHTTPRequest.start(); //start the ticker.
|
sendHTTPRequest.start(); //start the ticker.
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(void)
|
void loop(void)
|
||||||
{
|
{
|
||||||
sendHTTPRequest.update();
|
sendHTTPRequest.update();
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
defines.h
|
defines.h
|
||||||
|
|
||||||
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
/*
|
/*
|
||||||
Currently support
|
Currently support
|
||||||
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
|
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
|
||||||
- Nucleo-144 (F429ZI, F767ZI)
|
- Nucleo-144 (F429ZI, F767ZI)
|
||||||
- Discovery (STM32F746G-DISCOVERY)
|
- Discovery (STM32F746G-DISCOVERY)
|
||||||
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
|
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
|
||||||
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
|
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
|
||||||
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
|
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
|
||||||
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
|
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
|
||||||
@ -36,7 +36,7 @@
|
|||||||
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
|
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
|
||||||
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
|
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
|
||||||
defined(STM32WB) || defined(STM32MP1) )
|
defined(STM32WB) || defined(STM32MP1) )
|
||||||
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
|
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ASYNC_HTTP_DEBUG_PORT Serial
|
#define ASYNC_HTTP_DEBUG_PORT Serial
|
||||||
@ -46,54 +46,54 @@
|
|||||||
|
|
||||||
|
|
||||||
#if defined(STM32F0)
|
#if defined(STM32F0)
|
||||||
#warning STM32F0 board selected
|
#warning STM32F0 board selected
|
||||||
#define BOARD_TYPE "STM32F0"
|
#define BOARD_TYPE "STM32F0"
|
||||||
#elif defined(STM32F1)
|
#elif defined(STM32F1)
|
||||||
#warning STM32F1 board selected
|
#warning STM32F1 board selected
|
||||||
#define BOARD_TYPE "STM32F1"
|
#define BOARD_TYPE "STM32F1"
|
||||||
#elif defined(STM32F2)
|
#elif defined(STM32F2)
|
||||||
#warning STM32F2 board selected
|
#warning STM32F2 board selected
|
||||||
#define BOARD_TYPE "STM32F2"
|
#define BOARD_TYPE "STM32F2"
|
||||||
#elif defined(STM32F3)
|
#elif defined(STM32F3)
|
||||||
#warning STM32F3 board selected
|
#warning STM32F3 board selected
|
||||||
#define BOARD_TYPE "STM32F3"
|
#define BOARD_TYPE "STM32F3"
|
||||||
#elif defined(STM32F4)
|
#elif defined(STM32F4)
|
||||||
#warning STM32F4 board selected
|
#warning STM32F4 board selected
|
||||||
#define BOARD_TYPE "STM32F4"
|
#define BOARD_TYPE "STM32F4"
|
||||||
#elif defined(STM32F7)
|
#elif defined(STM32F7)
|
||||||
#warning STM32F7 board selected
|
#warning STM32F7 board selected
|
||||||
#define BOARD_TYPE "STM32F7"
|
#define BOARD_TYPE "STM32F7"
|
||||||
#elif defined(STM32L0)
|
#elif defined(STM32L0)
|
||||||
#warning STM32L0 board selected
|
#warning STM32L0 board selected
|
||||||
#define BOARD_TYPE "STM32L0"
|
#define BOARD_TYPE "STM32L0"
|
||||||
#elif defined(STM32L1)
|
#elif defined(STM32L1)
|
||||||
#warning STM32L1 board selected
|
#warning STM32L1 board selected
|
||||||
#define BOARD_TYPE "STM32L1"
|
#define BOARD_TYPE "STM32L1"
|
||||||
#elif defined(STM32L4)
|
#elif defined(STM32L4)
|
||||||
#warning STM32L4 board selected
|
#warning STM32L4 board selected
|
||||||
#define BOARD_TYPE "STM32L4"
|
#define BOARD_TYPE "STM32L4"
|
||||||
#elif defined(STM32H7)
|
#elif defined(STM32H7)
|
||||||
#warning STM32H7 board selected
|
#warning STM32H7 board selected
|
||||||
#define BOARD_TYPE "STM32H7"
|
#define BOARD_TYPE "STM32H7"
|
||||||
#elif defined(STM32G0)
|
#elif defined(STM32G0)
|
||||||
#warning STM32G0 board selected
|
#warning STM32G0 board selected
|
||||||
#define BOARD_TYPE "STM32G0"
|
#define BOARD_TYPE "STM32G0"
|
||||||
#elif defined(STM32G4)
|
#elif defined(STM32G4)
|
||||||
#warning STM32G4 board selected
|
#warning STM32G4 board selected
|
||||||
#define BOARD_TYPE "STM32G4"
|
#define BOARD_TYPE "STM32G4"
|
||||||
#elif defined(STM32WB)
|
#elif defined(STM32WB)
|
||||||
#warning STM32WB board selected
|
#warning STM32WB board selected
|
||||||
#define BOARD_TYPE "STM32WB"
|
#define BOARD_TYPE "STM32WB"
|
||||||
#elif defined(STM32MP1)
|
#elif defined(STM32MP1)
|
||||||
#warning STM32MP1 board selected
|
#warning STM32MP1 board selected
|
||||||
#define BOARD_TYPE "STM32MP1"
|
#define BOARD_TYPE "STM32MP1"
|
||||||
#else
|
#else
|
||||||
#warning STM32 unknown board selected
|
#warning STM32 unknown board selected
|
||||||
#define BOARD_TYPE "STM32 Unknown"
|
#define BOARD_TYPE "STM32 Unknown"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef BOARD_NAME
|
#ifndef BOARD_NAME
|
||||||
#define BOARD_NAME BOARD_TYPE
|
#define BOARD_NAME BOARD_TYPE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <LwIP.h>
|
#include <LwIP.h>
|
||||||
@ -106,26 +106,26 @@
|
|||||||
|
|
||||||
byte mac[][NUMBER_OF_MAC] =
|
byte mac[][NUMBER_OF_MAC] =
|
||||||
{
|
{
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Select the static IP address according to your local network
|
// Select the static IP address according to your local network
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
AsyncHTTPMultiRequests.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
AsyncHTTPMultiRequests.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
//************************************************************************************************************
|
//************************************************************************************************************
|
||||||
//
|
//
|
||||||
@ -41,11 +41,11 @@
|
|||||||
//*************************************************************************************************************
|
//*************************************************************************************************************
|
||||||
|
|
||||||
#if !( defined(ESP8266) || defined(ESP32) )
|
#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
|
#endif
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.1"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2"
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010001
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010002
|
||||||
|
|
||||||
// Level from 0-4
|
// Level from 0-4
|
||||||
#define ASYNC_HTTP_DEBUG_PORT Serial
|
#define ASYNC_HTTP_DEBUG_PORT Serial
|
||||||
@ -63,13 +63,16 @@ const char* ssid = "your_ssid";
|
|||||||
const char* password = "your_pass";
|
const char* password = "your_pass";
|
||||||
|
|
||||||
#if (ESP8266)
|
#if (ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#elif (ESP32)
|
#elif (ESP32)
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Seconds for timeout, default is 3s
|
// Seconds for timeout, default is 3s
|
||||||
#define DEFAULT_RX_TIMEOUT 10
|
#define DEFAULT_RX_TIMEOUT 10
|
||||||
|
|
||||||
|
// Uncomment for certain HTTP site to optimize
|
||||||
|
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
|
||||||
|
|
||||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||||
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
@ -82,22 +85,22 @@ Ticker ticker1;
|
|||||||
|
|
||||||
void heartBeatPrint(void)
|
void heartBeatPrint(void)
|
||||||
{
|
{
|
||||||
static int num = 1;
|
static int num = 1;
|
||||||
|
|
||||||
if (WiFi.status() == WL_CONNECTED)
|
if (WiFi.status() == WL_CONNECTED)
|
||||||
Serial.print(F("H")); // H means connected to WiFi
|
Serial.print(F("H")); // H means connected to WiFi
|
||||||
else
|
else
|
||||||
Serial.print(F("F")); // F means not connected to WiFi
|
Serial.print(F("F")); // F means not connected to WiFi
|
||||||
|
|
||||||
if (num == 80)
|
if (num == 80)
|
||||||
{
|
{
|
||||||
Serial.println();
|
Serial.println();
|
||||||
num = 1;
|
num = 1;
|
||||||
}
|
}
|
||||||
else if (num++ % 10 == 0)
|
else if (num++ % 10 == 0)
|
||||||
{
|
{
|
||||||
Serial.print(F(" "));
|
Serial.print(F(" "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// To replace with your real APP_API
|
// To replace with your real APP_API
|
||||||
@ -121,106 +124,115 @@ const char* requestAll[ NUM_REQUESTS ] = { requestCurrent.c_str(), requestMinute
|
|||||||
|
|
||||||
uint8_t requestIndex = 0;
|
uint8_t requestIndex = 0;
|
||||||
|
|
||||||
void sendRequest()
|
void sendRequest()
|
||||||
{
|
{
|
||||||
static bool requestOpenResult;
|
static bool requestOpenResult;
|
||||||
|
|
||||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
|
||||||
{
|
|
||||||
requestOpenResult = request.open("GET", requestAll[requestIndex] );
|
|
||||||
|
|
||||||
if (requestOpenResult)
|
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||||
{
|
{
|
||||||
// Only send() if open() returns true, or crash
|
requestOpenResult = request.open("GET", requestAll[requestIndex] );
|
||||||
request.send();
|
|
||||||
}
|
if (requestOpenResult)
|
||||||
else
|
{
|
||||||
{
|
// Only send() if open() returns true, or crash
|
||||||
Serial.println(F("Can't send bad request"));
|
request.send();
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
Serial.println(F("Can't send bad request"));
|
||||||
Serial.println(F("Can't send request"));
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.println(F("Can't send request"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
|
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 (request->responseHTTPcode() == 200)
|
if (readyState == readyStateDone)
|
||||||
{
|
{
|
||||||
Serial.print(F("\n***************")); Serial.print(requestName[ requestIndex ]); Serial.println(F("***************"));
|
AHTTP_LOGDEBUG(F("\n**************************************"));
|
||||||
Serial.println(request->responseText());
|
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
||||||
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
|
#if 1
|
||||||
// Bypass hourly
|
|
||||||
if (requestIndex == 1)
|
// Bypass hourly
|
||||||
requestIndex = 3;
|
if (requestIndex == 1)
|
||||||
else
|
requestIndex = 3;
|
||||||
requestIndex = (requestIndex + 1) % NUM_REQUESTS;
|
else
|
||||||
|
requestIndex = (requestIndex + 1) % NUM_REQUESTS;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// hourly too long, not display anyway. Not enough heap.
|
// hourly too long, not display anyway. Not enough heap.
|
||||||
requestIndex = (requestIndex + 1) % NUM_REQUESTS;
|
requestIndex = (requestIndex + 1) % NUM_REQUESTS;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
request->setDebug(false);
|
request->setDebug(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
Serial.begin(115200);
|
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 defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
|
||||||
if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < 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);
|
Serial.print(F("Warning. Must use this example on Version equal or later than : "));
|
||||||
}
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#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);
|
|
||||||
|
|
||||||
while (WiFi.status() != WL_CONNECTED)
|
Serial.print(F("Connecting to WiFi SSID: "));
|
||||||
{
|
Serial.println(ssid);
|
||||||
delay(500);
|
|
||||||
Serial.print(F("."));
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.print(F("AsyncHTTPRequest @ IP : "));
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
Serial.println(WiFi.localIP());
|
{
|
||||||
|
delay(500);
|
||||||
request.setDebug(false);
|
Serial.print(F("."));
|
||||||
|
}
|
||||||
request.onReadyStateChange(requestCB);
|
|
||||||
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);
|
|
||||||
|
|
||||||
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
|
Serial.print(F("AsyncHTTPRequest @ IP : "));
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
// Send first request now
|
|
||||||
sendRequest();
|
request.setDebug(false);
|
||||||
|
|
||||||
|
request.onReadyStateChange(requestCB);
|
||||||
|
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);
|
||||||
|
|
||||||
|
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
|
||||||
|
|
||||||
|
// Send first request now
|
||||||
|
sendRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
AsyncHTTPRequest_ESP.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
AsyncHTTPRequest_ESP.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
//************************************************************************************************************
|
//************************************************************************************************************
|
||||||
//
|
//
|
||||||
@ -41,7 +41,7 @@
|
|||||||
//*************************************************************************************************************
|
//*************************************************************************************************************
|
||||||
|
|
||||||
#if !( defined(ESP8266) || defined(ESP32) )
|
#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
|
#endif
|
||||||
|
|
||||||
// Level from 0-4
|
// Level from 0-4
|
||||||
@ -60,16 +60,19 @@ const char* ssid = "your_ssid";
|
|||||||
const char* password = "your_pass";
|
const char* password = "your_pass";
|
||||||
|
|
||||||
#if (ESP8266)
|
#if (ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#elif (ESP32)
|
#elif (ESP32)
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.1"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2"
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010001
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010002
|
||||||
|
|
||||||
// Seconds for timeout, default is 3s
|
// Seconds for timeout, default is 3s
|
||||||
#define DEFAULT_RX_TIMEOUT 10
|
#define DEFAULT_RX_TIMEOUT 10
|
||||||
|
|
||||||
|
// Uncomment for certain HTTP site to optimize
|
||||||
|
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
|
||||||
|
|
||||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||||
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
@ -82,102 +85,105 @@ Ticker ticker1;
|
|||||||
|
|
||||||
void heartBeatPrint()
|
void heartBeatPrint()
|
||||||
{
|
{
|
||||||
static int num = 1;
|
static int num = 1;
|
||||||
|
|
||||||
if (WiFi.status() == WL_CONNECTED)
|
if (WiFi.status() == WL_CONNECTED)
|
||||||
Serial.print(F("H")); // H means connected to WiFi
|
Serial.print(F("H")); // H means connected to WiFi
|
||||||
else
|
else
|
||||||
Serial.print(F("F")); // F means not connected to WiFi
|
Serial.print(F("F")); // F means not connected to WiFi
|
||||||
|
|
||||||
if (num == 80)
|
if (num == 80)
|
||||||
{
|
{
|
||||||
Serial.println();
|
Serial.println();
|
||||||
num = 1;
|
num = 1;
|
||||||
}
|
}
|
||||||
else if (num++ % 10 == 0)
|
else if (num++ % 10 == 0)
|
||||||
{
|
{
|
||||||
Serial.print(F(" "));
|
Serial.print(F(" "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendRequest()
|
void sendRequest()
|
||||||
{
|
{
|
||||||
static bool requestOpenResult;
|
static bool requestOpenResult;
|
||||||
|
|
||||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
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/Europe/London.txt");
|
||||||
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
||||||
|
|
||||||
if (requestOpenResult)
|
if (requestOpenResult)
|
||||||
{
|
{
|
||||||
// Only send() if open() returns true, or crash
|
// Only send() if open() returns true, or crash
|
||||||
request.send();
|
request.send();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println(F("Can't send bad request"));
|
Serial.println(F("Can't send bad request"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println(F("Can't send request"));
|
Serial.println(F("Can't send request"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
|
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
|
||||||
{
|
{
|
||||||
(void) optParm;
|
(void) optParm;
|
||||||
|
|
||||||
if (readyState == readyStateDone)
|
if (readyState == readyStateDone)
|
||||||
{
|
{
|
||||||
AHTTP_LOGDEBUG(F("\n**************************************"));
|
AHTTP_LOGDEBUG(F("\n**************************************"));
|
||||||
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
||||||
|
|
||||||
if (request->responseHTTPcode() == 200)
|
if (request->responseHTTPcode() == 200)
|
||||||
{
|
{
|
||||||
Serial.println(F("\n**************************************"));
|
Serial.println(F("\n**************************************"));
|
||||||
Serial.println(request->responseText());
|
Serial.println(request->responseText());
|
||||||
Serial.println(F("**************************************"));
|
Serial.println(F("**************************************"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
while (!Serial && millis() < 5000);
|
|
||||||
|
|
||||||
Serial.print(F("\nStarting AsyncHTTPRequest_ESP using ")); Serial.println(ARDUINO_BOARD);
|
|
||||||
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
while (!Serial && millis() < 5000);
|
||||||
|
|
||||||
WiFi.begin(ssid, password);
|
Serial.print(F("\nStarting AsyncHTTPRequest_ESP using "));
|
||||||
|
Serial.println(ARDUINO_BOARD);
|
||||||
Serial.print(F("Connecting to WiFi SSID: ")); Serial.println(ssid);
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||||
|
|
||||||
while (WiFi.status() != WL_CONNECTED)
|
WiFi.mode(WIFI_STA);
|
||||||
{
|
|
||||||
delay(500);
|
|
||||||
Serial.print(F("."));
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.print(F("\nAsyncHTTPRequest @ IP : "));
|
WiFi.begin(ssid, password);
|
||||||
Serial.println(WiFi.localIP());
|
|
||||||
|
|
||||||
request.setDebug(false);
|
|
||||||
|
|
||||||
request.onReadyStateChange(requestCB);
|
|
||||||
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);
|
|
||||||
|
|
||||||
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
|
Serial.print(F("Connecting to WiFi SSID: "));
|
||||||
|
Serial.println(ssid);
|
||||||
// Send first request now
|
|
||||||
sendRequest();
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
|
delay(500);
|
||||||
|
Serial.print(F("."));
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print(F("\nAsyncHTTPRequest @ IP : "));
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
request.setDebug(false);
|
||||||
|
|
||||||
|
request.onReadyStateChange(requestCB);
|
||||||
|
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);
|
||||||
|
|
||||||
|
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
|
||||||
|
|
||||||
|
// Send first request now
|
||||||
|
sendRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
AsyncHTTPRequest_ESP.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
AsyncHTTPRequest_ESP.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
//************************************************************************************************************
|
//************************************************************************************************************
|
||||||
//
|
//
|
||||||
@ -41,12 +41,12 @@
|
|||||||
//*************************************************************************************************************
|
//*************************************************************************************************************
|
||||||
|
|
||||||
#if !( defined(ESP8266) )
|
#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
|
#endif
|
||||||
|
|
||||||
// Level from 0-4
|
// Level from 0-4
|
||||||
#define ASYNC_HTTP_DEBUG_PORT Serial
|
#define ASYNC_HTTP_DEBUG_PORT Serial
|
||||||
#define _ASYNC_HTTP_LOGLEVEL_ 1
|
#define _ASYNC_HTTP_LOGLEVEL_ 1
|
||||||
|
|
||||||
// 300s = 5 minutes to not flooding
|
// 300s = 5 minutes to not flooding
|
||||||
#define HTTP_REQUEST_INTERVAL 60 //300
|
#define HTTP_REQUEST_INTERVAL 60 //300
|
||||||
@ -65,27 +65,27 @@
|
|||||||
#define CSPIN 16 // 5
|
#define CSPIN 16 // 5
|
||||||
|
|
||||||
#if USING_W5500
|
#if USING_W5500
|
||||||
#include "W5500lwIP.h"
|
#include "W5500lwIP.h"
|
||||||
#define SHIELD_TYPE "ESP8266_W5500 Ethernet"
|
#define SHIELD_TYPE "ESP8266_W5500 Ethernet"
|
||||||
|
|
||||||
Wiznet5500lwIP eth(CSPIN);
|
Wiznet5500lwIP eth(CSPIN);
|
||||||
|
|
||||||
#elif USING_W5100
|
#elif USING_W5100
|
||||||
#include <W5100lwIP.h>
|
#include <W5100lwIP.h>
|
||||||
#define SHIELD_TYPE "ESP8266_W5100 Ethernet"
|
#define SHIELD_TYPE "ESP8266_W5100 Ethernet"
|
||||||
|
|
||||||
Wiznet5100lwIP eth(CSPIN);
|
Wiznet5100lwIP eth(CSPIN);
|
||||||
|
|
||||||
#elif USING_ENC28J60
|
#elif USING_ENC28J60
|
||||||
#include <ENC28J60lwIP.h>
|
#include <ENC28J60lwIP.h>
|
||||||
#define SHIELD_TYPE "ESP8266_ENC28J60 Ethernet"
|
#define SHIELD_TYPE "ESP8266_ENC28J60 Ethernet"
|
||||||
|
|
||||||
ENC28J60lwIP eth(CSPIN);
|
|
||||||
#else
|
|
||||||
// default if none selected
|
|
||||||
#include "W5500lwIP.h"
|
|
||||||
|
|
||||||
Wiznet5500lwIP eth(CSPIN);
|
ENC28J60lwIP eth(CSPIN);
|
||||||
|
#else
|
||||||
|
// default if none selected
|
||||||
|
#include "W5500lwIP.h"
|
||||||
|
|
||||||
|
Wiznet5500lwIP eth(CSPIN);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -95,11 +95,14 @@ using TCPClient = WiFiClient;
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.1"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2"
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010001
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010002
|
||||||
|
|
||||||
// Seconds for timeout, default is 3s
|
// Seconds for timeout, default is 3s
|
||||||
#define DEFAULT_RX_TIMEOUT 10
|
#define DEFAULT_RX_TIMEOUT 10
|
||||||
|
|
||||||
|
// Uncomment for certain HTTP site to optimize
|
||||||
|
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
|
||||||
|
|
||||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||||
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
@ -112,125 +115,128 @@ Ticker ticker1;
|
|||||||
|
|
||||||
void heartBeatPrint()
|
void heartBeatPrint()
|
||||||
{
|
{
|
||||||
static int num = 1;
|
static int num = 1;
|
||||||
|
|
||||||
if (eth.connected())
|
if (eth.connected())
|
||||||
Serial.print(F("H")); // H means connected to Ethernet
|
Serial.print(F("H")); // H means connected to Ethernet
|
||||||
else
|
else
|
||||||
Serial.print(F("F")); // F means not connected to Ethernet
|
Serial.print(F("F")); // F means not connected to Ethernet
|
||||||
|
|
||||||
if (num == 80)
|
if (num == 80)
|
||||||
{
|
{
|
||||||
Serial.println();
|
Serial.println();
|
||||||
num = 1;
|
num = 1;
|
||||||
}
|
}
|
||||||
else if (num++ % 10 == 0)
|
else if (num++ % 10 == 0)
|
||||||
{
|
{
|
||||||
Serial.print(F(" "));
|
Serial.print(F(" "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendRequest()
|
void sendRequest()
|
||||||
{
|
{
|
||||||
static bool requestOpenResult;
|
static bool requestOpenResult;
|
||||||
|
|
||||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
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/Europe/London.txt");
|
||||||
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
||||||
|
|
||||||
if (requestOpenResult)
|
if (requestOpenResult)
|
||||||
{
|
{
|
||||||
// Only send() if open() returns true, or crash
|
// Only send() if open() returns true, or crash
|
||||||
request.send();
|
request.send();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println(F("Can't send bad request"));
|
Serial.println(F("Can't send bad request"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println(F("Can't send request"));
|
Serial.println(F("Can't send request"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
|
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
|
||||||
{
|
{
|
||||||
(void) optParm;
|
(void) optParm;
|
||||||
|
|
||||||
if (readyState == readyStateDone)
|
if (readyState == readyStateDone)
|
||||||
{
|
{
|
||||||
AHTTP_LOGDEBUG(F("\n**************************************"));
|
AHTTP_LOGDEBUG(F("\n**************************************"));
|
||||||
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
||||||
|
|
||||||
if (request->responseHTTPcode() == 200)
|
if (request->responseHTTPcode() == 200)
|
||||||
{
|
{
|
||||||
Serial.println(F("\n**************************************"));
|
Serial.println(F("\n**************************************"));
|
||||||
Serial.println(request->responseText());
|
Serial.println(request->responseText());
|
||||||
Serial.println(F("**************************************"));
|
Serial.println(F("**************************************"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void initEthernet()
|
void initEthernet()
|
||||||
{
|
{
|
||||||
SPI.begin();
|
SPI.begin();
|
||||||
SPI.setClockDivider(SPI_CLOCK_DIV4);
|
SPI.setClockDivider(SPI_CLOCK_DIV4);
|
||||||
SPI.setBitOrder(MSBFIRST);
|
SPI.setBitOrder(MSBFIRST);
|
||||||
SPI.setDataMode(SPI_MODE0);
|
SPI.setDataMode(SPI_MODE0);
|
||||||
eth.setDefault();
|
eth.setDefault();
|
||||||
|
|
||||||
if (!eth.begin())
|
if (!eth.begin())
|
||||||
{
|
{
|
||||||
Serial.println("No Ethernet hardware ... Stop here");
|
Serial.println("No Ethernet hardware ... Stop here");
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.print("Connecting to network : ");
|
Serial.print("Connecting to network : ");
|
||||||
|
|
||||||
while (!eth.connected())
|
while (!eth.connected())
|
||||||
{
|
{
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.print("Ethernet IP address: ");
|
Serial.print("Ethernet IP address: ");
|
||||||
Serial.println(eth.localIP());
|
Serial.println(eth.localIP());
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
while (!Serial && millis() < 5000);
|
|
||||||
|
|
||||||
delay(200);
|
while (!Serial && millis() < 5000);
|
||||||
|
|
||||||
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();
|
delay(200);
|
||||||
|
|
||||||
request.setDebug(false);
|
Serial.print("\nStart AsyncHTTPRequest_ESP8266_Ethernet on ");
|
||||||
|
Serial.print(ARDUINO_BOARD);
|
||||||
request.onReadyStateChange(requestCB);
|
Serial.print(" using ");
|
||||||
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);
|
Serial.println(SHIELD_TYPE);
|
||||||
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||||
|
|
||||||
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
|
initEthernet();
|
||||||
|
|
||||||
// Send first request now
|
request.setDebug(false);
|
||||||
sendRequest();
|
|
||||||
|
request.onReadyStateChange(requestCB);
|
||||||
|
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);
|
||||||
|
|
||||||
|
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
|
||||||
|
|
||||||
|
// Send first request now
|
||||||
|
sendRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
AsyncHTTPRequest_ESP_Multi.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
AsyncHTTPRequest_ESP_Multi.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#if !( defined(ESP8266) || defined(ESP32) )
|
#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
|
#endif
|
||||||
|
|
||||||
// Level from 0-4
|
// Level from 0-4
|
||||||
@ -39,25 +39,28 @@ const char* ssid = "your_ssid";
|
|||||||
const char* password = "your_pass";
|
const char* password = "your_pass";
|
||||||
|
|
||||||
#if (ESP8266)
|
#if (ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#elif (ESP32)
|
#elif (ESP32)
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Seconds for timeout, default is 3s
|
// Seconds for timeout, default is 3s
|
||||||
#define DEFAULT_RX_TIMEOUT 10
|
#define DEFAULT_RX_TIMEOUT 10
|
||||||
|
|
||||||
|
// Uncomment for certain HTTP site to optimize
|
||||||
|
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
|
||||||
|
|
||||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||||
#include <AsyncHTTPRequest_Generic.h> // http://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
|
|
||||||
#include <Ticker.h>
|
#include <Ticker.h>
|
||||||
|
|
||||||
#define NUM_DIFFERENT_SITES 2
|
#define NUM_DIFFERENT_SITES 2
|
||||||
|
|
||||||
const char* addreses[][NUM_DIFFERENT_SITES] =
|
const char* addreses[][NUM_DIFFERENT_SITES] =
|
||||||
{
|
{
|
||||||
{"http://worldtimeapi.org/api/timezone/America/Toronto.txt", "http://worldtimeapi.org/api/timezone/Europe/Prague.txt"},
|
{"http://worldtimeapi.org/api/timezone/America/Toronto.txt", "http://worldtimeapi.org/api/timezone/Europe/Prague.txt"},
|
||||||
{"http://www.myexternalip.com/raw"}
|
{"http://www.myexternalip.com/raw"}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NUM_ENTRIES_SITE_0 2
|
#define NUM_ENTRIES_SITE_0 2
|
||||||
@ -85,159 +88,161 @@ Ticker ticker1;
|
|||||||
|
|
||||||
void heartBeatPrint()
|
void heartBeatPrint()
|
||||||
{
|
{
|
||||||
static int num = 1;
|
static int num = 1;
|
||||||
|
|
||||||
if (WiFi.status() == WL_CONNECTED)
|
if (WiFi.status() == WL_CONNECTED)
|
||||||
Serial.print(F("H")); // H means connected to WiFi
|
Serial.print(F("H")); // H means connected to WiFi
|
||||||
else
|
else
|
||||||
Serial.print(F("F")); // F means not connected to WiFi
|
Serial.print(F("F")); // F means not connected to WiFi
|
||||||
|
|
||||||
if (num == 80)
|
if (num == 80)
|
||||||
{
|
{
|
||||||
Serial.println();
|
Serial.println();
|
||||||
num = 1;
|
num = 1;
|
||||||
}
|
}
|
||||||
else if (num++ % 10 == 0)
|
else if (num++ % 10 == 0)
|
||||||
{
|
{
|
||||||
Serial.print(F(" "));
|
Serial.print(F(" "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendRequest(uint16_t index)
|
void sendRequest(uint16_t index)
|
||||||
{
|
{
|
||||||
static bool requestOpenResult;
|
static bool requestOpenResult;
|
||||||
|
|
||||||
reqCount[index]--;
|
reqCount[index]--;
|
||||||
readySend[index] = false;
|
readySend[index] = false;
|
||||||
|
|
||||||
requestOpenResult = request[index].open("GET", addreses[index][reqCount[index]]);
|
|
||||||
|
|
||||||
if (requestOpenResult)
|
requestOpenResult = request[index].open("GET", addreses[index][reqCount[index]]);
|
||||||
{
|
|
||||||
// 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]]);
|
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]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendRequest0()
|
void sendRequest0()
|
||||||
{
|
{
|
||||||
sendRequest(0);
|
sendRequest(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendRequest1()
|
void sendRequest1()
|
||||||
{
|
{
|
||||||
sendRequest(1);
|
sendRequest(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendRequests()
|
void sendRequests()
|
||||||
{
|
{
|
||||||
reqCount[0] = NUM_ENTRIES_SITE_0;
|
reqCount[0] = NUM_ENTRIES_SITE_0;
|
||||||
reqCount[1] = NUM_ENTRIES_SITE_1;
|
reqCount[1] = NUM_ENTRIES_SITE_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestCB0(void* optParm, AsyncHTTPRequest* thisRequest, int readyState)
|
void requestCB0(void* optParm, AsyncHTTPRequest* thisRequest, int readyState)
|
||||||
{
|
{
|
||||||
(void) optParm;
|
(void) optParm;
|
||||||
|
|
||||||
if (readyState == readyStateDone)
|
if (readyState == readyStateDone)
|
||||||
{
|
{
|
||||||
AHTTP_LOGWARN(F("\n**************************************"));
|
AHTTP_LOGWARN(F("\n**************************************"));
|
||||||
AHTTP_LOGWARN1(F("Response Code = "), request->responseHTTPString());
|
AHTTP_LOGWARN1(F("Response Code = "), request->responseHTTPString());
|
||||||
|
|
||||||
if (request->responseHTTPcode() == 200)
|
if (request->responseHTTPcode() == 200)
|
||||||
{
|
{
|
||||||
Serial.println(F("\n**************************************"));
|
Serial.println(F("\n**************************************"));
|
||||||
Serial.println(request->responseText());
|
Serial.println(request->responseText());
|
||||||
Serial.println(F("**************************************"));
|
Serial.println(F("**************************************"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AHTTP_LOGERROR(F("Response error"));
|
AHTTP_LOGERROR(F("Response error"));
|
||||||
}
|
}
|
||||||
|
|
||||||
thisRequest->setDebug(false);
|
thisRequest->setDebug(false);
|
||||||
readySend[0] = true;
|
readySend[0] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestCB1(void* optParm, AsyncHTTPRequest* thisRequest, int readyState)
|
void requestCB1(void* optParm, AsyncHTTPRequest* thisRequest, int readyState)
|
||||||
{
|
{
|
||||||
(void) optParm;
|
(void) optParm;
|
||||||
|
|
||||||
if (readyState == readyStateDone)
|
if (readyState == readyStateDone)
|
||||||
{
|
{
|
||||||
AHTTP_LOGWARN(F("\n**************************************"));
|
AHTTP_LOGWARN(F("\n**************************************"));
|
||||||
AHTTP_LOGWARN1(F("Response Code = "), request->responseHTTPString());
|
AHTTP_LOGWARN1(F("Response Code = "), request->responseHTTPString());
|
||||||
|
|
||||||
if (request->responseHTTPcode() == 200)
|
if (request->responseHTTPcode() == 200)
|
||||||
{
|
{
|
||||||
Serial.println(F("\n**************************************"));
|
Serial.println(F("\n**************************************"));
|
||||||
Serial.println(request->responseText());
|
Serial.println(request->responseText());
|
||||||
Serial.println(F("**************************************"));
|
Serial.println(F("**************************************"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AHTTP_LOGERROR(F("Response error"));
|
AHTTP_LOGERROR(F("Response error"));
|
||||||
}
|
}
|
||||||
|
|
||||||
thisRequest->setDebug(false);
|
thisRequest->setDebug(false);
|
||||||
readySend[1] = true;
|
readySend[1] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
while (!Serial && millis() < 5000);
|
|
||||||
|
|
||||||
Serial.print("\nStart AsyncHTTPRequest_ESP_Multi on "); Serial.println(ARDUINO_BOARD);
|
while (!Serial && millis() < 5000);
|
||||||
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
Serial.print("\nStart AsyncHTTPRequest_ESP_Multi on ");
|
||||||
|
Serial.println(ARDUINO_BOARD);
|
||||||
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||||
|
|
||||||
WiFi.begin(ssid, password);
|
WiFi.mode(WIFI_STA);
|
||||||
|
|
||||||
Serial.println("Connecting to WiFi SSID: " + String(ssid));
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
while (WiFi.status() != WL_CONNECTED)
|
Serial.println("Connecting to WiFi SSID: " + String(ssid));
|
||||||
{
|
|
||||||
delay(1000);
|
|
||||||
Serial.print(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.print(F("\nAsyncHTTPSRequest @ IP : "));
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
Serial.println(WiFi.localIP());
|
{
|
||||||
|
delay(1000);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
|
||||||
for (int index = 0; index < NUM_DIFFERENT_SITES; index++)
|
Serial.print(F("\nAsyncHTTPSRequest @ IP : "));
|
||||||
{
|
Serial.println(WiFi.localIP());
|
||||||
request[index].setDebug(false);
|
|
||||||
|
|
||||||
request[index].onReadyStateChange(requestCB[index]);
|
for (int index = 0; index < NUM_DIFFERENT_SITES; index++)
|
||||||
}
|
{
|
||||||
|
request[index].setDebug(false);
|
||||||
|
|
||||||
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequests);
|
request[index].onReadyStateChange(requestCB[index]);
|
||||||
|
}
|
||||||
|
|
||||||
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
|
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequests);
|
||||||
|
|
||||||
|
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
for (int index = 0; index < NUM_DIFFERENT_SITES; index++)
|
for (int index = 0; index < NUM_DIFFERENT_SITES; index++)
|
||||||
{
|
{
|
||||||
if ((reqCount[index] > 0) && readySend[index])
|
if ((reqCount[index] > 0) && readySend[index])
|
||||||
{
|
{
|
||||||
sendRequestCB[index]();
|
sendRequestCB[index]();
|
||||||
|
|
||||||
// Don't send too fast
|
// Don't send too fast
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,21 +1,21 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
AsyncHTTPRequest_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
AsyncHTTPRequest_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
//************************************************************************************************************
|
//************************************************************************************************************
|
||||||
//
|
//
|
||||||
@ -42,12 +42,15 @@
|
|||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.1"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2"
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010001
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010002
|
||||||
|
|
||||||
// 600s = 10 minutes to not flooding, 60s in testing
|
// 600s = 10 minutes to not flooding, 60s in testing
|
||||||
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
|
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
|
||||||
|
|
||||||
|
// Uncomment for certain HTTP site to optimize
|
||||||
|
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
|
||||||
|
|
||||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||||
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
|
|
||||||
@ -58,91 +61,95 @@ AsyncHTTPRequest request;
|
|||||||
void sendRequest();
|
void sendRequest();
|
||||||
|
|
||||||
// Repeat forever, millis() resolution
|
// Repeat forever, millis() resolution
|
||||||
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
||||||
|
|
||||||
void sendRequest()
|
void sendRequest()
|
||||||
{
|
{
|
||||||
static bool requestOpenResult;
|
static bool requestOpenResult;
|
||||||
|
|
||||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
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/Europe/London.txt");
|
||||||
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
||||||
|
|
||||||
if (requestOpenResult)
|
if (requestOpenResult)
|
||||||
{
|
{
|
||||||
// Only send() if open() returns true, or crash
|
// Only send() if open() returns true, or crash
|
||||||
request.send();
|
request.send();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Can't send bad request");
|
Serial.println("Can't send bad request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Can't send request");
|
Serial.println("Can't send request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
|
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
|
||||||
{
|
{
|
||||||
(void) optParm;
|
(void) optParm;
|
||||||
|
|
||||||
if (readyState == readyStateDone)
|
if (readyState == readyStateDone)
|
||||||
{
|
{
|
||||||
AHTTP_LOGDEBUG(F("\n**************************************"));
|
AHTTP_LOGDEBUG(F("\n**************************************"));
|
||||||
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
||||||
|
|
||||||
if (request->responseHTTPcode() == 200)
|
if (request->responseHTTPcode() == 200)
|
||||||
{
|
{
|
||||||
Serial.println(F("\n**************************************"));
|
Serial.println(F("\n**************************************"));
|
||||||
Serial.println(request->responseText());
|
Serial.println(request->responseText());
|
||||||
Serial.println(F("**************************************"));
|
Serial.println(F("**************************************"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
while (!Serial && millis() < 5000);
|
|
||||||
|
|
||||||
Serial.print("\nStart AsyncHTTPRequest_STM32 on "); Serial.println(BOARD_NAME);
|
while (!Serial && millis() < 5000);
|
||||||
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 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);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// start the ethernet connection and the server
|
if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
|
||||||
// Use random mac
|
{
|
||||||
uint16_t index = millis() % NUMBER_OF_MAC;
|
Serial.print("Warning. Must use this example on Version equal or later than : ");
|
||||||
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET);
|
||||||
|
}
|
||||||
|
|
||||||
// Use Static IP
|
#endif
|
||||||
//Ethernet.begin(mac[index], ip);
|
|
||||||
// Use DHCP dynamic IP and random mac
|
|
||||||
Ethernet.begin(mac[index]);
|
|
||||||
|
|
||||||
Serial.print(F("AsyncHTTPRequest @ IP : "));
|
// start the ethernet connection and the server
|
||||||
Serial.println(Ethernet.localIP());
|
// Use random mac
|
||||||
Serial.println();
|
uint16_t index = millis() % NUMBER_OF_MAC;
|
||||||
|
|
||||||
request.setDebug(false);
|
// Use Static IP
|
||||||
|
//Ethernet.begin(mac[index], ip);
|
||||||
request.onReadyStateChange(requestCB);
|
// Use DHCP dynamic IP and random mac
|
||||||
sendHTTPRequest.start(); //start the ticker.
|
Ethernet.begin(mac[index]);
|
||||||
|
|
||||||
// Send first request now
|
Serial.print(F("AsyncHTTPRequest @ IP : "));
|
||||||
//delay(60);
|
Serial.println(Ethernet.localIP());
|
||||||
sendRequest();
|
Serial.println();
|
||||||
|
|
||||||
|
request.setDebug(false);
|
||||||
|
|
||||||
|
request.onReadyStateChange(requestCB);
|
||||||
|
sendHTTPRequest.start(); //start the ticker.
|
||||||
|
|
||||||
|
// Send first request now
|
||||||
|
//delay(60);
|
||||||
|
sendRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
sendHTTPRequest.update();
|
sendHTTPRequest.update();
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
defines.h
|
defines.h
|
||||||
|
|
||||||
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
/*
|
/*
|
||||||
Currently support
|
Currently support
|
||||||
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
|
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
|
||||||
- Nucleo-144 (F429ZI, F767ZI)
|
- Nucleo-144 (F429ZI, F767ZI)
|
||||||
- Discovery (STM32F746G-DISCOVERY)
|
- Discovery (STM32F746G-DISCOVERY)
|
||||||
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
|
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
|
||||||
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
|
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
|
||||||
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
|
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
|
||||||
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
|
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
|
||||||
@ -36,7 +36,7 @@
|
|||||||
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
|
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
|
||||||
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
|
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
|
||||||
defined(STM32WB) || defined(STM32MP1) )
|
defined(STM32WB) || defined(STM32MP1) )
|
||||||
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
|
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ASYNC_HTTP_DEBUG_PORT Serial
|
#define ASYNC_HTTP_DEBUG_PORT Serial
|
||||||
@ -46,54 +46,54 @@
|
|||||||
|
|
||||||
|
|
||||||
#if defined(STM32F0)
|
#if defined(STM32F0)
|
||||||
#warning STM32F0 board selected
|
#warning STM32F0 board selected
|
||||||
#define BOARD_TYPE "STM32F0"
|
#define BOARD_TYPE "STM32F0"
|
||||||
#elif defined(STM32F1)
|
#elif defined(STM32F1)
|
||||||
#warning STM32F1 board selected
|
#warning STM32F1 board selected
|
||||||
#define BOARD_TYPE "STM32F1"
|
#define BOARD_TYPE "STM32F1"
|
||||||
#elif defined(STM32F2)
|
#elif defined(STM32F2)
|
||||||
#warning STM32F2 board selected
|
#warning STM32F2 board selected
|
||||||
#define BOARD_TYPE "STM32F2"
|
#define BOARD_TYPE "STM32F2"
|
||||||
#elif defined(STM32F3)
|
#elif defined(STM32F3)
|
||||||
#warning STM32F3 board selected
|
#warning STM32F3 board selected
|
||||||
#define BOARD_TYPE "STM32F3"
|
#define BOARD_TYPE "STM32F3"
|
||||||
#elif defined(STM32F4)
|
#elif defined(STM32F4)
|
||||||
#warning STM32F4 board selected
|
#warning STM32F4 board selected
|
||||||
#define BOARD_TYPE "STM32F4"
|
#define BOARD_TYPE "STM32F4"
|
||||||
#elif defined(STM32F7)
|
#elif defined(STM32F7)
|
||||||
#warning STM32F7 board selected
|
#warning STM32F7 board selected
|
||||||
#define BOARD_TYPE "STM32F7"
|
#define BOARD_TYPE "STM32F7"
|
||||||
#elif defined(STM32L0)
|
#elif defined(STM32L0)
|
||||||
#warning STM32L0 board selected
|
#warning STM32L0 board selected
|
||||||
#define BOARD_TYPE "STM32L0"
|
#define BOARD_TYPE "STM32L0"
|
||||||
#elif defined(STM32L1)
|
#elif defined(STM32L1)
|
||||||
#warning STM32L1 board selected
|
#warning STM32L1 board selected
|
||||||
#define BOARD_TYPE "STM32L1"
|
#define BOARD_TYPE "STM32L1"
|
||||||
#elif defined(STM32L4)
|
#elif defined(STM32L4)
|
||||||
#warning STM32L4 board selected
|
#warning STM32L4 board selected
|
||||||
#define BOARD_TYPE "STM32L4"
|
#define BOARD_TYPE "STM32L4"
|
||||||
#elif defined(STM32H7)
|
#elif defined(STM32H7)
|
||||||
#warning STM32H7 board selected
|
#warning STM32H7 board selected
|
||||||
#define BOARD_TYPE "STM32H7"
|
#define BOARD_TYPE "STM32H7"
|
||||||
#elif defined(STM32G0)
|
#elif defined(STM32G0)
|
||||||
#warning STM32G0 board selected
|
#warning STM32G0 board selected
|
||||||
#define BOARD_TYPE "STM32G0"
|
#define BOARD_TYPE "STM32G0"
|
||||||
#elif defined(STM32G4)
|
#elif defined(STM32G4)
|
||||||
#warning STM32G4 board selected
|
#warning STM32G4 board selected
|
||||||
#define BOARD_TYPE "STM32G4"
|
#define BOARD_TYPE "STM32G4"
|
||||||
#elif defined(STM32WB)
|
#elif defined(STM32WB)
|
||||||
#warning STM32WB board selected
|
#warning STM32WB board selected
|
||||||
#define BOARD_TYPE "STM32WB"
|
#define BOARD_TYPE "STM32WB"
|
||||||
#elif defined(STM32MP1)
|
#elif defined(STM32MP1)
|
||||||
#warning STM32MP1 board selected
|
#warning STM32MP1 board selected
|
||||||
#define BOARD_TYPE "STM32MP1"
|
#define BOARD_TYPE "STM32MP1"
|
||||||
#else
|
#else
|
||||||
#warning STM32 unknown board selected
|
#warning STM32 unknown board selected
|
||||||
#define BOARD_TYPE "STM32 Unknown"
|
#define BOARD_TYPE "STM32 Unknown"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef BOARD_NAME
|
#ifndef BOARD_NAME
|
||||||
#define BOARD_NAME BOARD_TYPE
|
#define BOARD_NAME BOARD_TYPE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <LwIP.h>
|
#include <LwIP.h>
|
||||||
@ -106,26 +106,26 @@
|
|||||||
|
|
||||||
byte mac[][NUMBER_OF_MAC] =
|
byte mac[][NUMBER_OF_MAC] =
|
||||||
{
|
{
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Select the static IP address according to your local network
|
// Select the static IP address according to your local network
|
||||||
|
@ -1,35 +1,38 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
AsyncSimpleGET_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
AsyncSimpleGET_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
// Select a test server address
|
// Select a test server address
|
||||||
//char GET_ServerAddress[] = "ipv4bot.whatismyipaddress.com/";
|
//char GET_ServerAddress[] = "ipv4bot.whatismyipaddress.com/";
|
||||||
char GET_ServerAddress[] = "http://worldtimeapi.org/api/timezone/America/Toronto.txt";
|
char GET_ServerAddress[] = "http://worldtimeapi.org/api/timezone/America/Toronto.txt";
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.1"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2"
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010001
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010002
|
||||||
|
|
||||||
// 600s = 10 minutes to not flooding, 60s in testing
|
// 600s = 10 minutes to not flooding, 60s in testing
|
||||||
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
|
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
|
||||||
|
|
||||||
|
// Uncomment for certain HTTP site to optimize
|
||||||
|
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
|
||||||
|
|
||||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||||
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
|
|
||||||
@ -40,89 +43,94 @@ AsyncHTTPRequest request;
|
|||||||
void sendRequest();
|
void sendRequest();
|
||||||
|
|
||||||
// Repeat forever, millis() resolution
|
// Repeat forever, millis() resolution
|
||||||
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
||||||
|
|
||||||
void sendRequest()
|
void sendRequest()
|
||||||
{
|
{
|
||||||
static bool requestOpenResult;
|
static bool requestOpenResult;
|
||||||
|
|
||||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||||
{
|
{
|
||||||
requestOpenResult = request.open("GET", GET_ServerAddress);
|
requestOpenResult = request.open("GET", GET_ServerAddress);
|
||||||
|
|
||||||
if (requestOpenResult)
|
if (requestOpenResult)
|
||||||
{
|
{
|
||||||
// Only send() if open() returns true, or crash
|
// Only send() if open() returns true, or crash
|
||||||
request.send();
|
request.send();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Can't send bad request");
|
Serial.println("Can't send bad request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Can't send request");
|
Serial.println("Can't send request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
|
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
|
||||||
{
|
{
|
||||||
(void) optParm;
|
(void) optParm;
|
||||||
|
|
||||||
if (readyState == readyStateDone)
|
if (readyState == readyStateDone)
|
||||||
{
|
{
|
||||||
AHTTP_LOGDEBUG(F("\n**************************************"));
|
AHTTP_LOGDEBUG(F("\n**************************************"));
|
||||||
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
||||||
|
|
||||||
if (request->responseHTTPcode() == 200)
|
if (request->responseHTTPcode() == 200)
|
||||||
{
|
{
|
||||||
Serial.println(F("\n**************************************"));
|
Serial.println(F("\n**************************************"));
|
||||||
Serial.println(request->responseText());
|
Serial.println(request->responseText());
|
||||||
Serial.println(F("**************************************"));
|
Serial.println(F("**************************************"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
while (!Serial && millis() < 5000);
|
|
||||||
|
|
||||||
Serial.print("\nStart AsyncSimpleGET_STM32 on "); Serial.println(BOARD_NAME);
|
while (!Serial && millis() < 5000);
|
||||||
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 defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
|
||||||
if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < 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);
|
Serial.print("Warning. Must use this example on Version equal or later than : ");
|
||||||
}
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// start the ethernet connection and the server
|
// start the ethernet connection and the server
|
||||||
// Use random mac
|
// Use random mac
|
||||||
uint16_t index = millis() % NUMBER_OF_MAC;
|
uint16_t index = millis() % NUMBER_OF_MAC;
|
||||||
|
|
||||||
// Use Static IP
|
// Use Static IP
|
||||||
//Ethernet.begin(mac[index], ip);
|
//Ethernet.begin(mac[index], ip);
|
||||||
// Use DHCP dynamic IP and random mac
|
// Use DHCP dynamic IP and random mac
|
||||||
Ethernet.begin(mac[index]);
|
Ethernet.begin(mac[index]);
|
||||||
|
|
||||||
Serial.print(F("AsyncHTTPRequest @ IP : ")); Serial.println(Ethernet.localIP());
|
Serial.print(F("AsyncHTTPRequest @ IP : "));
|
||||||
Serial.println();
|
Serial.println(Ethernet.localIP());
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
request.setDebug(false);
|
request.setDebug(false);
|
||||||
|
|
||||||
request.onReadyStateChange(requestCB);
|
|
||||||
sendHTTPRequest.start(); //start the ticker.
|
|
||||||
|
|
||||||
// Send first request now
|
request.onReadyStateChange(requestCB);
|
||||||
delay(10000);
|
sendHTTPRequest.start(); //start the ticker.
|
||||||
sendRequest();
|
|
||||||
|
// Send first request now
|
||||||
|
delay(10000);
|
||||||
|
sendRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
sendHTTPRequest.update();
|
sendHTTPRequest.update();
|
||||||
}
|
}
|
||||||
|
@ -46,54 +46,54 @@
|
|||||||
|
|
||||||
|
|
||||||
#if defined(STM32F0)
|
#if defined(STM32F0)
|
||||||
#warning STM32F0 board selected
|
#warning STM32F0 board selected
|
||||||
#define BOARD_TYPE "STM32F0"
|
#define BOARD_TYPE "STM32F0"
|
||||||
#elif defined(STM32F1)
|
#elif defined(STM32F1)
|
||||||
#warning STM32F1 board selected
|
#warning STM32F1 board selected
|
||||||
#define BOARD_TYPE "STM32F1"
|
#define BOARD_TYPE "STM32F1"
|
||||||
#elif defined(STM32F2)
|
#elif defined(STM32F2)
|
||||||
#warning STM32F2 board selected
|
#warning STM32F2 board selected
|
||||||
#define BOARD_TYPE "STM32F2"
|
#define BOARD_TYPE "STM32F2"
|
||||||
#elif defined(STM32F3)
|
#elif defined(STM32F3)
|
||||||
#warning STM32F3 board selected
|
#warning STM32F3 board selected
|
||||||
#define BOARD_TYPE "STM32F3"
|
#define BOARD_TYPE "STM32F3"
|
||||||
#elif defined(STM32F4)
|
#elif defined(STM32F4)
|
||||||
#warning STM32F4 board selected
|
#warning STM32F4 board selected
|
||||||
#define BOARD_TYPE "STM32F4"
|
#define BOARD_TYPE "STM32F4"
|
||||||
#elif defined(STM32F7)
|
#elif defined(STM32F7)
|
||||||
#warning STM32F7 board selected
|
#warning STM32F7 board selected
|
||||||
#define BOARD_TYPE "STM32F7"
|
#define BOARD_TYPE "STM32F7"
|
||||||
#elif defined(STM32L0)
|
#elif defined(STM32L0)
|
||||||
#warning STM32L0 board selected
|
#warning STM32L0 board selected
|
||||||
#define BOARD_TYPE "STM32L0"
|
#define BOARD_TYPE "STM32L0"
|
||||||
#elif defined(STM32L1)
|
#elif defined(STM32L1)
|
||||||
#warning STM32L1 board selected
|
#warning STM32L1 board selected
|
||||||
#define BOARD_TYPE "STM32L1"
|
#define BOARD_TYPE "STM32L1"
|
||||||
#elif defined(STM32L4)
|
#elif defined(STM32L4)
|
||||||
#warning STM32L4 board selected
|
#warning STM32L4 board selected
|
||||||
#define BOARD_TYPE "STM32L4"
|
#define BOARD_TYPE "STM32L4"
|
||||||
#elif defined(STM32H7)
|
#elif defined(STM32H7)
|
||||||
#warning STM32H7 board selected
|
#warning STM32H7 board selected
|
||||||
#define BOARD_TYPE "STM32H7"
|
#define BOARD_TYPE "STM32H7"
|
||||||
#elif defined(STM32G0)
|
#elif defined(STM32G0)
|
||||||
#warning STM32G0 board selected
|
#warning STM32G0 board selected
|
||||||
#define BOARD_TYPE "STM32G0"
|
#define BOARD_TYPE "STM32G0"
|
||||||
#elif defined(STM32G4)
|
#elif defined(STM32G4)
|
||||||
#warning STM32G4 board selected
|
#warning STM32G4 board selected
|
||||||
#define BOARD_TYPE "STM32G4"
|
#define BOARD_TYPE "STM32G4"
|
||||||
#elif defined(STM32WB)
|
#elif defined(STM32WB)
|
||||||
#warning STM32WB board selected
|
#warning STM32WB board selected
|
||||||
#define BOARD_TYPE "STM32WB"
|
#define BOARD_TYPE "STM32WB"
|
||||||
#elif defined(STM32MP1)
|
#elif defined(STM32MP1)
|
||||||
#warning STM32MP1 board selected
|
#warning STM32MP1 board selected
|
||||||
#define BOARD_TYPE "STM32MP1"
|
#define BOARD_TYPE "STM32MP1"
|
||||||
#else
|
#else
|
||||||
#warning STM32 unknown board selected
|
#warning STM32 unknown board selected
|
||||||
#define BOARD_TYPE "STM32 Unknown"
|
#define BOARD_TYPE "STM32 Unknown"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef BOARD_NAME
|
#ifndef BOARD_NAME
|
||||||
#define BOARD_NAME BOARD_TYPE
|
#define BOARD_NAME BOARD_TYPE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <LwIP.h>
|
#include <LwIP.h>
|
||||||
@ -106,26 +106,26 @@
|
|||||||
|
|
||||||
byte mac[][NUMBER_OF_MAC] =
|
byte mac[][NUMBER_OF_MAC] =
|
||||||
{
|
{
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Select the static IP address according to your local network
|
// Select the static IP address according to your local network
|
||||||
|
@ -1,37 +1,40 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
AsyncWebClientRepeating_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
AsyncWebClientRepeating_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
// Select a test server address
|
// Select a test server address
|
||||||
const char GET_ServerAddress[] = "arduino.tips";
|
const char GET_ServerAddress[] = "arduino.tips";
|
||||||
|
|
||||||
// GET location
|
// GET location
|
||||||
String GET_Location = "/asciilogo.txt";
|
String GET_Location = "/asciilogo.txt";
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.1"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2"
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010001
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010002
|
||||||
|
|
||||||
// 600s = 10 minutes to not flooding, 60s in testing
|
// 600s = 10 minutes to not flooding, 60s in testing
|
||||||
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
|
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
|
||||||
|
|
||||||
|
// Uncomment for certain HTTP site to optimize
|
||||||
|
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
|
||||||
|
|
||||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||||
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
|
|
||||||
@ -42,88 +45,92 @@ AsyncHTTPRequest request;
|
|||||||
void sendRequest();
|
void sendRequest();
|
||||||
|
|
||||||
// Repeat forever, millis() resolution
|
// Repeat forever, millis() resolution
|
||||||
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
|
||||||
|
|
||||||
void sendRequest()
|
void sendRequest()
|
||||||
{
|
{
|
||||||
static bool requestOpenResult;
|
static bool requestOpenResult;
|
||||||
|
|
||||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||||
{
|
{
|
||||||
requestOpenResult = request.open("GET", (GET_ServerAddress + GET_Location).c_str());
|
requestOpenResult = request.open("GET", (GET_ServerAddress + GET_Location).c_str());
|
||||||
|
|
||||||
if (requestOpenResult)
|
if (requestOpenResult)
|
||||||
{
|
{
|
||||||
// Only send() if open() returns true, or crash
|
// Only send() if open() returns true, or crash
|
||||||
request.send();
|
request.send();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Can't send bad request");
|
Serial.println("Can't send bad request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Can't send request");
|
Serial.println("Can't send request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
|
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
|
||||||
{
|
{
|
||||||
(void) optParm;
|
(void) optParm;
|
||||||
|
|
||||||
if (readyState == readyStateDone)
|
if (readyState == readyStateDone)
|
||||||
{
|
{
|
||||||
AHTTP_LOGDEBUG(F("\n**************************************"));
|
AHTTP_LOGDEBUG(F("\n**************************************"));
|
||||||
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
||||||
|
|
||||||
if (request->responseHTTPcode() == 200)
|
if (request->responseHTTPcode() == 200)
|
||||||
{
|
{
|
||||||
Serial.println(F("\n**************************************"));
|
Serial.println(F("\n**************************************"));
|
||||||
Serial.println(request->responseText());
|
Serial.println(request->responseText());
|
||||||
Serial.println(F("**************************************"));
|
Serial.println(F("**************************************"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
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 defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
|
||||||
if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < 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);
|
Serial.print("Warning. Must use this example on Version equal or later than : ");
|
||||||
}
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// start the ethernet connection and the server
|
// start the ethernet connection and the server
|
||||||
// Use random mac
|
// Use random mac
|
||||||
uint16_t index = millis() % NUMBER_OF_MAC;
|
uint16_t index = millis() % NUMBER_OF_MAC;
|
||||||
|
|
||||||
// Use Static IP
|
// Use Static IP
|
||||||
//Ethernet.begin(mac[index], ip);
|
//Ethernet.begin(mac[index], ip);
|
||||||
// Use DHCP dynamic IP and random mac
|
// Use DHCP dynamic IP and random mac
|
||||||
Ethernet.begin(mac[index]);
|
Ethernet.begin(mac[index]);
|
||||||
|
|
||||||
Serial.print(F("AsyncHTTPRequest @ IP : "));
|
Serial.print(F("AsyncHTTPRequest @ IP : "));
|
||||||
Serial.println(Ethernet.localIP());
|
Serial.println(Ethernet.localIP());
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
request.setDebug(false);
|
request.setDebug(false);
|
||||||
|
|
||||||
request.onReadyStateChange(requestCB);
|
|
||||||
sendHTTPRequest.start(); //start the ticker
|
|
||||||
|
|
||||||
// Send first request now
|
request.onReadyStateChange(requestCB);
|
||||||
sendRequest();
|
sendHTTPRequest.start(); //start the ticker
|
||||||
|
|
||||||
|
// Send first request now
|
||||||
|
sendRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
sendHTTPRequest.update();
|
sendHTTPRequest.update();
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
defines.h
|
defines.h
|
||||||
|
|
||||||
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
/*
|
/*
|
||||||
Currently support
|
Currently support
|
||||||
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
|
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
|
||||||
- Nucleo-144 (F429ZI, F767ZI)
|
- Nucleo-144 (F429ZI, F767ZI)
|
||||||
- Discovery (STM32F746G-DISCOVERY)
|
- Discovery (STM32F746G-DISCOVERY)
|
||||||
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
|
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
|
||||||
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
|
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
|
||||||
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
|
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
|
||||||
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
|
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
|
||||||
@ -36,7 +36,7 @@
|
|||||||
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
|
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
|
||||||
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
|
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
|
||||||
defined(STM32WB) || defined(STM32MP1) )
|
defined(STM32WB) || defined(STM32MP1) )
|
||||||
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
|
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ASYNC_HTTP_DEBUG_PORT Serial
|
#define ASYNC_HTTP_DEBUG_PORT Serial
|
||||||
@ -46,54 +46,54 @@
|
|||||||
|
|
||||||
|
|
||||||
#if defined(STM32F0)
|
#if defined(STM32F0)
|
||||||
#warning STM32F0 board selected
|
#warning STM32F0 board selected
|
||||||
#define BOARD_TYPE "STM32F0"
|
#define BOARD_TYPE "STM32F0"
|
||||||
#elif defined(STM32F1)
|
#elif defined(STM32F1)
|
||||||
#warning STM32F1 board selected
|
#warning STM32F1 board selected
|
||||||
#define BOARD_TYPE "STM32F1"
|
#define BOARD_TYPE "STM32F1"
|
||||||
#elif defined(STM32F2)
|
#elif defined(STM32F2)
|
||||||
#warning STM32F2 board selected
|
#warning STM32F2 board selected
|
||||||
#define BOARD_TYPE "STM32F2"
|
#define BOARD_TYPE "STM32F2"
|
||||||
#elif defined(STM32F3)
|
#elif defined(STM32F3)
|
||||||
#warning STM32F3 board selected
|
#warning STM32F3 board selected
|
||||||
#define BOARD_TYPE "STM32F3"
|
#define BOARD_TYPE "STM32F3"
|
||||||
#elif defined(STM32F4)
|
#elif defined(STM32F4)
|
||||||
#warning STM32F4 board selected
|
#warning STM32F4 board selected
|
||||||
#define BOARD_TYPE "STM32F4"
|
#define BOARD_TYPE "STM32F4"
|
||||||
#elif defined(STM32F7)
|
#elif defined(STM32F7)
|
||||||
#warning STM32F7 board selected
|
#warning STM32F7 board selected
|
||||||
#define BOARD_TYPE "STM32F7"
|
#define BOARD_TYPE "STM32F7"
|
||||||
#elif defined(STM32L0)
|
#elif defined(STM32L0)
|
||||||
#warning STM32L0 board selected
|
#warning STM32L0 board selected
|
||||||
#define BOARD_TYPE "STM32L0"
|
#define BOARD_TYPE "STM32L0"
|
||||||
#elif defined(STM32L1)
|
#elif defined(STM32L1)
|
||||||
#warning STM32L1 board selected
|
#warning STM32L1 board selected
|
||||||
#define BOARD_TYPE "STM32L1"
|
#define BOARD_TYPE "STM32L1"
|
||||||
#elif defined(STM32L4)
|
#elif defined(STM32L4)
|
||||||
#warning STM32L4 board selected
|
#warning STM32L4 board selected
|
||||||
#define BOARD_TYPE "STM32L4"
|
#define BOARD_TYPE "STM32L4"
|
||||||
#elif defined(STM32H7)
|
#elif defined(STM32H7)
|
||||||
#warning STM32H7 board selected
|
#warning STM32H7 board selected
|
||||||
#define BOARD_TYPE "STM32H7"
|
#define BOARD_TYPE "STM32H7"
|
||||||
#elif defined(STM32G0)
|
#elif defined(STM32G0)
|
||||||
#warning STM32G0 board selected
|
#warning STM32G0 board selected
|
||||||
#define BOARD_TYPE "STM32G0"
|
#define BOARD_TYPE "STM32G0"
|
||||||
#elif defined(STM32G4)
|
#elif defined(STM32G4)
|
||||||
#warning STM32G4 board selected
|
#warning STM32G4 board selected
|
||||||
#define BOARD_TYPE "STM32G4"
|
#define BOARD_TYPE "STM32G4"
|
||||||
#elif defined(STM32WB)
|
#elif defined(STM32WB)
|
||||||
#warning STM32WB board selected
|
#warning STM32WB board selected
|
||||||
#define BOARD_TYPE "STM32WB"
|
#define BOARD_TYPE "STM32WB"
|
||||||
#elif defined(STM32MP1)
|
#elif defined(STM32MP1)
|
||||||
#warning STM32MP1 board selected
|
#warning STM32MP1 board selected
|
||||||
#define BOARD_TYPE "STM32MP1"
|
#define BOARD_TYPE "STM32MP1"
|
||||||
#else
|
#else
|
||||||
#warning STM32 unknown board selected
|
#warning STM32 unknown board selected
|
||||||
#define BOARD_TYPE "STM32 Unknown"
|
#define BOARD_TYPE "STM32 Unknown"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef BOARD_NAME
|
#ifndef BOARD_NAME
|
||||||
#define BOARD_NAME BOARD_TYPE
|
#define BOARD_NAME BOARD_TYPE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <LwIP.h>
|
#include <LwIP.h>
|
||||||
@ -106,26 +106,26 @@
|
|||||||
|
|
||||||
byte mac[][NUMBER_OF_MAC] =
|
byte mac[][NUMBER_OF_MAC] =
|
||||||
{
|
{
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
|
||||||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
|
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Select the static IP address according to your local network
|
// Select the static IP address according to your local network
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
AsyncHTTPMultiRequests_WT32_ETH01.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
AsyncHTTPMultiRequests_WT32_ETH01.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
//************************************************************************************************************
|
//************************************************************************************************************
|
||||||
//
|
//
|
||||||
@ -41,7 +41,7 @@
|
|||||||
//*************************************************************************************************************
|
//*************************************************************************************************************
|
||||||
|
|
||||||
#if !( defined(ESP32) )
|
#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
|
#endif
|
||||||
|
|
||||||
// Level from 0-4
|
// Level from 0-4
|
||||||
@ -57,8 +57,11 @@
|
|||||||
|
|
||||||
#include <WebServer_WT32_ETH01.h> // https://github.com/khoih-prog/WebServer_WT32_ETH01
|
#include <WebServer_WT32_ETH01.h> // https://github.com/khoih-prog/WebServer_WT32_ETH01
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.1"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2"
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010001
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010002
|
||||||
|
|
||||||
|
// Uncomment for certain HTTP site to optimize
|
||||||
|
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
|
||||||
|
|
||||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||||
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
@ -83,22 +86,22 @@ IPAddress myDNS(8, 8, 8, 8);
|
|||||||
|
|
||||||
void heartBeatPrint(void)
|
void heartBeatPrint(void)
|
||||||
{
|
{
|
||||||
static int num = 1;
|
static int num = 1;
|
||||||
|
|
||||||
if (WT32_ETH01_isConnected())
|
if (WT32_ETH01_isConnected())
|
||||||
Serial.print(F("H")); // H means connected to WiFi
|
Serial.print(F("H")); // H means connected to WiFi
|
||||||
else
|
else
|
||||||
Serial.print(F("F")); // F means not connected to WiFi
|
Serial.print(F("F")); // F means not connected to WiFi
|
||||||
|
|
||||||
if (num == 80)
|
if (num == 80)
|
||||||
{
|
{
|
||||||
Serial.println();
|
Serial.println();
|
||||||
num = 1;
|
num = 1;
|
||||||
}
|
}
|
||||||
else if (num++ % 10 == 0)
|
else if (num++ % 10 == 0)
|
||||||
{
|
{
|
||||||
Serial.print(F(" "));
|
Serial.print(F(" "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// To replace with your real APP_API
|
// To replace with your real APP_API
|
||||||
@ -122,113 +125,122 @@ const char* requestAll[ NUM_REQUESTS ] = { requestCurrent.c_str(), requestMinute
|
|||||||
|
|
||||||
uint8_t requestIndex = 0;
|
uint8_t requestIndex = 0;
|
||||||
|
|
||||||
void sendRequest()
|
void sendRequest()
|
||||||
{
|
{
|
||||||
static bool requestOpenResult;
|
static bool requestOpenResult;
|
||||||
|
|
||||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
|
||||||
{
|
|
||||||
requestOpenResult = request.open("GET", requestAll[requestIndex] );
|
|
||||||
|
|
||||||
if (requestOpenResult)
|
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||||
{
|
{
|
||||||
// Only send() if open() returns true, or crash
|
requestOpenResult = request.open("GET", requestAll[requestIndex] );
|
||||||
request.send();
|
|
||||||
}
|
if (requestOpenResult)
|
||||||
else
|
{
|
||||||
{
|
// Only send() if open() returns true, or crash
|
||||||
Serial.println("Can't send bad request");
|
request.send();
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
Serial.println("Can't send bad request");
|
||||||
Serial.println("Can't send request");
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.println("Can't send request");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
|
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 (request->responseHTTPcode() == 200)
|
if (readyState == readyStateDone)
|
||||||
{
|
{
|
||||||
Serial.print(F("\n***************")); Serial.print(requestName[ requestIndex ]); Serial.println(F("***************"));
|
AHTTP_LOGDEBUG(F("\n**************************************"));
|
||||||
Serial.println(request->responseText());
|
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
||||||
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
|
#if 1
|
||||||
// Bypass hourly
|
|
||||||
if (requestIndex == 1)
|
// Bypass hourly
|
||||||
requestIndex = 3;
|
if (requestIndex == 1)
|
||||||
else
|
requestIndex = 3;
|
||||||
requestIndex = (requestIndex + 1) % NUM_REQUESTS;
|
else
|
||||||
|
requestIndex = (requestIndex + 1) % NUM_REQUESTS;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// hourly too long, not display anyway. Not enough heap.
|
// hourly too long, not display anyway. Not enough heap.
|
||||||
requestIndex = (requestIndex + 1) % NUM_REQUESTS;
|
requestIndex = (requestIndex + 1) % NUM_REQUESTS;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
request->setDebug(false);
|
request->setDebug(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
while (!Serial && millis() < 5000);
|
|
||||||
|
|
||||||
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.setDebugOutput(true);
|
while (!Serial && millis() < 5000);
|
||||||
|
|
||||||
|
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.setDebugOutput(true);
|
||||||
|
|
||||||
#if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
|
#if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
|
||||||
if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < 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);
|
Serial.print("Warning. Must use this example on Version equal or later than : ");
|
||||||
}
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// To be called before ETH.begin()
|
// To be called before ETH.begin()
|
||||||
WT32_ETH01_onEvent();
|
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,
|
//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_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, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE);
|
||||||
ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER);
|
ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER);
|
||||||
|
|
||||||
// Static IP, leave without this line to get IP via DHCP
|
// 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);
|
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
|
||||||
ETH.config(myIP, myGW, mySN, myDNS);
|
ETH.config(myIP, myGW, mySN, myDNS);
|
||||||
|
|
||||||
WT32_ETH01_waitForConnect();
|
WT32_ETH01_waitForConnect();
|
||||||
|
|
||||||
Serial.print(F("AsyncHTTPRequest @ IP : "));
|
Serial.print(F("AsyncHTTPRequest @ IP : "));
|
||||||
Serial.println(ETH.localIP());
|
Serial.println(ETH.localIP());
|
||||||
|
|
||||||
request.setDebug(false);
|
|
||||||
|
|
||||||
request.onReadyStateChange(requestCB);
|
|
||||||
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);
|
|
||||||
|
|
||||||
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
|
request.setDebug(false);
|
||||||
|
|
||||||
// Send first request now
|
request.onReadyStateChange(requestCB);
|
||||||
sendRequest();
|
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);
|
||||||
|
|
||||||
|
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
|
||||||
|
|
||||||
|
// Send first request now
|
||||||
|
sendRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
AsyncHTTPRequest_WT32_ETH01.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
AsyncHTTPRequest_WT32_ETH01.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
//************************************************************************************************************
|
//************************************************************************************************************
|
||||||
//
|
//
|
||||||
@ -41,7 +41,7 @@
|
|||||||
//*************************************************************************************************************
|
//*************************************************************************************************************
|
||||||
|
|
||||||
#if !( defined(ESP32) )
|
#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
|
#endif
|
||||||
|
|
||||||
// Level from 0-4
|
// Level from 0-4
|
||||||
@ -57,8 +57,11 @@
|
|||||||
|
|
||||||
#include <WebServer_WT32_ETH01.h> // https://github.com/khoih-prog/WebServer_WT32_ETH01
|
#include <WebServer_WT32_ETH01.h> // https://github.com/khoih-prog/WebServer_WT32_ETH01
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.1"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2"
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010001
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010002
|
||||||
|
|
||||||
|
// Uncomment for certain HTTP site to optimize
|
||||||
|
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
|
||||||
|
|
||||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||||
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
@ -83,118 +86,123 @@ IPAddress myDNS(8, 8, 8, 8);
|
|||||||
|
|
||||||
void heartBeatPrint(void)
|
void heartBeatPrint(void)
|
||||||
{
|
{
|
||||||
static int num = 1;
|
static int num = 1;
|
||||||
|
|
||||||
if (WT32_ETH01_isConnected())
|
if (WT32_ETH01_isConnected())
|
||||||
Serial.print(F("H")); // H means connected
|
Serial.print(F("H")); // H means connected
|
||||||
else
|
else
|
||||||
Serial.print(F("F")); // F means not connected
|
Serial.print(F("F")); // F means not connected
|
||||||
|
|
||||||
if (num == 80)
|
if (num == 80)
|
||||||
{
|
{
|
||||||
Serial.println();
|
Serial.println();
|
||||||
num = 1;
|
num = 1;
|
||||||
}
|
}
|
||||||
else if (num++ % 10 == 0)
|
else if (num++ % 10 == 0)
|
||||||
{
|
{
|
||||||
Serial.print(F(" "));
|
Serial.print(F(" "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendRequest()
|
void sendRequest()
|
||||||
{
|
{
|
||||||
static bool requestOpenResult;
|
static bool requestOpenResult;
|
||||||
|
|
||||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
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/Europe/London.txt");
|
||||||
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
||||||
|
|
||||||
if (requestOpenResult)
|
if (requestOpenResult)
|
||||||
{
|
{
|
||||||
// Only send() if open() returns true, or crash
|
// Only send() if open() returns true, or crash
|
||||||
request.send();
|
request.send();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Can't send bad request");
|
Serial.println("Can't send bad request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Can't send request");
|
Serial.println("Can't send request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
|
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
|
||||||
{
|
{
|
||||||
(void) optParm;
|
(void) optParm;
|
||||||
|
|
||||||
if (readyState == readyStateDone)
|
if (readyState == readyStateDone)
|
||||||
{
|
{
|
||||||
AHTTP_LOGDEBUG(F("\n**************************************"));
|
AHTTP_LOGDEBUG(F("\n**************************************"));
|
||||||
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
||||||
|
|
||||||
if (request->responseHTTPcode() == 200)
|
if (request->responseHTTPcode() == 200)
|
||||||
{
|
{
|
||||||
Serial.println(F("\n**************************************"));
|
Serial.println(F("\n**************************************"));
|
||||||
Serial.println(request->responseText());
|
Serial.println(request->responseText());
|
||||||
Serial.println(F("**************************************"));
|
Serial.println(F("**************************************"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
while (!Serial && millis() < 5000);
|
|
||||||
|
|
||||||
delay(200);
|
while (!Serial && millis() < 5000);
|
||||||
|
|
||||||
Serial.print("\nStart AsyncHTTPRequest_WT32_ETH01 on "); Serial.print(ARDUINO_BOARD);
|
delay(200);
|
||||||
Serial.print(" with "); Serial.println(SHIELD_TYPE);
|
|
||||||
Serial.println(WEBSERVER_WT32_ETH01_VERSION);
|
|
||||||
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
|
||||||
|
|
||||||
Serial.setDebugOutput(true);
|
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);
|
||||||
|
|
||||||
#if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
|
#if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
|
||||||
if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < 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);
|
Serial.print("Warning. Must use this example on Version equal or later than : ");
|
||||||
}
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// To be called before ETH.begin()
|
// To be called before ETH.begin()
|
||||||
WT32_ETH01_onEvent();
|
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,
|
//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_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, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE);
|
||||||
ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER);
|
ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER);
|
||||||
|
|
||||||
// Static IP, leave without this line to get IP via DHCP
|
// 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);
|
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
|
||||||
ETH.config(myIP, myGW, mySN, myDNS);
|
ETH.config(myIP, myGW, mySN, myDNS);
|
||||||
|
|
||||||
WT32_ETH01_waitForConnect();
|
WT32_ETH01_waitForConnect();
|
||||||
|
|
||||||
Serial.print(F("\nHTTP WebClient is @ IP : "));
|
Serial.print(F("\nHTTP WebClient is @ IP : "));
|
||||||
Serial.println(ETH.localIP());
|
Serial.println(ETH.localIP());
|
||||||
|
|
||||||
request.setDebug(false);
|
|
||||||
|
|
||||||
request.onReadyStateChange(requestCB);
|
|
||||||
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);
|
|
||||||
|
|
||||||
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
|
request.setDebug(false);
|
||||||
|
|
||||||
// Send first request now
|
request.onReadyStateChange(requestCB);
|
||||||
sendRequest();
|
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);
|
||||||
|
|
||||||
|
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
|
||||||
|
|
||||||
|
// Send first request now
|
||||||
|
sendRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
multiFileProject.cpp
|
multiFileProject.cpp
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
multiFileProject.h
|
multiFileProject.h
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
multiFileProject.ino
|
multiFileProject.ino
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
@ -16,35 +16,38 @@
|
|||||||
( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
|
( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
|
||||||
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
|
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
|
||||||
defined(STM32WB) || defined(STM32MP1) ) )
|
defined(STM32WB) || defined(STM32MP1) ) )
|
||||||
#error This code is intended to run on the ESP8266, ESP32 or STM32 platform! Please check your Tools->Board setting.
|
#error This code is intended to run on the ESP8266, ESP32 or STM32 platform! Please check your Tools->Board setting.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.1"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2"
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010001
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010002
|
||||||
|
|
||||||
#include "multiFileProject.h"
|
#include "multiFileProject.h"
|
||||||
|
|
||||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||||
#include "AsyncHTTPRequest_Generic.h"
|
#include "AsyncHTTPRequest_Generic.h"
|
||||||
|
|
||||||
void setup()
|
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 defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
|
||||||
if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < 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);
|
Serial.print("Warning. Must use this example on Version equal or later than : ");
|
||||||
}
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// put your main code here, to run repeatedly:
|
// put your main code here, to run repeatedly:
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name":"AsyncHTTPRequest_Generic",
|
"name":"AsyncHTTPRequest_Generic",
|
||||||
"version": "1.10.1",
|
"version": "1.10.2",
|
||||||
"description":"Simple Async HTTP Request library, supporting GET, POST, PUT, PATCH, DELETE and HEAD, on top of AsyncTCP libraries, such as AsyncTCP, ESPAsyncTCP, AsyncTCP_STM32, etc.. for ESP32 (including ESP32_S2, ESP32_S3 and ESP32_C3), WT32_ETH01 (ESP32 + LAN8720), ESP8266 (WiFi, W5x00 or ENC28J60) and currently STM32 with built-in LAN8742A Ethernet.",
|
"description":"Simple Async HTTP Request library, supporting GET, POST, PUT, PATCH, DELETE and HEAD, on top of AsyncTCP libraries, such as AsyncTCP, ESPAsyncTCP, AsyncTCP_STM32, etc.. for ESP32 (including ESP32_S2, ESP32_S3 and ESP32_C3), WT32_ETH01 (ESP32 + LAN8720), ESP8266 (WiFi, W5x00 or ENC28J60) and currently STM32 with built-in LAN8742A Ethernet.",
|
||||||
"keywords":"communication, async, tcp, http, ESP8266, ESP32, ESP32-S2, ESP32-S3, ESP32-C3, wt32-eth01, stm32, ethernet, wifi, lan8742a, nucleo-144, stm32f7, W5x00, ENC28J60",
|
"keywords":"communication, async, tcp, http, ESP8266, ESP32, ESP32-S2, ESP32-S3, ESP32-C3, wt32-eth01, stm32, ethernet, wifi, lan8742a, nucleo-144, stm32f7, W5x00, ENC28J60",
|
||||||
"authors": [
|
"authors": [
|
||||||
@ -45,7 +45,7 @@
|
|||||||
{
|
{
|
||||||
"owner": "khoih-prog",
|
"owner": "khoih-prog",
|
||||||
"name": "ESPAsync_WiFiManager",
|
"name": "ESPAsync_WiFiManager",
|
||||||
"version": ">=1.15.0",
|
"version": ">=1.15.1",
|
||||||
"platforms": ["espressif8266", "espressif32"]
|
"platforms": ["espressif8266", "espressif32"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=AsyncHTTPRequest_Generic
|
name=AsyncHTTPRequest_Generic
|
||||||
version=1.10.1
|
version=1.10.2
|
||||||
author=Bob Lemaire,Khoi Hoang <khoih.prog@gmail.com>
|
author=Bob Lemaire,Khoi Hoang <khoih.prog@gmail.com>
|
||||||
maintainer=Khoi Hoang <khoih.prog@gmail.com>
|
maintainer=Khoi Hoang <khoih.prog@gmail.com>
|
||||||
license=GPLv3
|
license=GPLv3
|
||||||
|
@ -45,7 +45,7 @@ lib_deps =
|
|||||||
; https://github.com/khoih-prog/STM32AsyncTCP.git
|
; https://github.com/khoih-prog/STM32AsyncTCP.git
|
||||||
; STM32duino LwIP@>=2.1.2
|
; STM32duino LwIP@>=2.1.2
|
||||||
; STM32duino STM32Ethernet@>=1.3.0
|
; STM32duino STM32Ethernet@>=1.3.0
|
||||||
; ESPAsync_WiFiManager@>=1.15.0
|
; ESPAsync_WiFiManager@>=1.15.1
|
||||||
; LittleFS_esp32@>=1.0.6
|
; LittleFS_esp32@>=1.0.6
|
||||||
; WebServer_WT32_ETH01@>=1.5.1
|
; WebServer_WT32_ETH01@>=1.5.1
|
||||||
;
|
;
|
||||||
@ -56,7 +56,7 @@ lib_deps =
|
|||||||
; https://github.com/khoih-prog/STM32AsyncTCP.git
|
; https://github.com/khoih-prog/STM32AsyncTCP.git
|
||||||
; stm32duino/STM32duino LwIP@>=2.1.2
|
; stm32duino/STM32duino LwIP@>=2.1.2
|
||||||
; stm32duino/STM32duino STM32Ethernet@>=1.3.0
|
; stm32duino/STM32duino STM32Ethernet@>=1.3.0
|
||||||
; khoih-prog/ESPAsync_WiFiManager@>=1.15.0
|
; khoih-prog/ESPAsync_WiFiManager@>=1.15.1
|
||||||
; lorol/LittleFS_esp32@>=1.0.6
|
; lorol/LittleFS_esp32@>=1.0.6
|
||||||
; khoih-prog/WebServer_WT32_ETH01@>=1.5.1
|
; khoih-prog/WebServer_WT32_ETH01@>=1.5.1
|
||||||
|
|
||||||
@ -73,11 +73,11 @@ framework = arduino
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
; PlatformIO 4.x
|
; PlatformIO 4.x
|
||||||
; ESPAsyncTCP@>=1.2.2
|
; ESPAsyncTCP@>=1.2.2
|
||||||
; ESPAsync_WiFiManager@>=1.15.0
|
; ESPAsync_WiFiManager@>=1.15.1
|
||||||
;
|
;
|
||||||
; PlatformIO 5.x
|
; PlatformIO 5.x
|
||||||
me-no-dev/ESPAsyncTCP@>=1.2.2
|
me-no-dev/ESPAsyncTCP@>=1.2.2
|
||||||
khoih-prog/ESPAsync_WiFiManager@>=1.15.0
|
khoih-prog/ESPAsync_WiFiManager@>=1.15.1
|
||||||
|
|
||||||
; ============================================================
|
; ============================================================
|
||||||
; Board configuration
|
; Board configuration
|
||||||
@ -128,13 +128,13 @@ framework = arduino
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
; PlatformIO 4.x
|
; PlatformIO 4.x
|
||||||
; AsyncTCP@>=1.1.1
|
; AsyncTCP@>=1.1.1
|
||||||
; ESPAsync_WiFiManager@>=1.15.0
|
; ESPAsync_WiFiManager@>=1.15.1
|
||||||
; LittleFS_esp32@>=1.0.6
|
; LittleFS_esp32@>=1.0.6
|
||||||
; WebServer_WT32_ETH01@>=1.5.1
|
; WebServer_WT32_ETH01@>=1.5.1
|
||||||
;
|
;
|
||||||
; PlatformIO 5.x
|
; PlatformIO 5.x
|
||||||
me-no-dev/AsyncTCP@>=1.1.1
|
me-no-dev/AsyncTCP@>=1.1.1
|
||||||
khoih-prog/ESPAsync_WiFiManager@>=1.15.0
|
khoih-prog/ESPAsync_WiFiManager@>=1.15.1
|
||||||
; lorol/LittleFS_esp32@>=1.0.6
|
; lorol/LittleFS_esp32@>=1.0.6
|
||||||
khoih-prog/WebServer_WT32_ETH01@>=1.5.1
|
khoih-prog/WebServer_WT32_ETH01@>=1.5.1
|
||||||
|
|
||||||
@ -281,7 +281,7 @@ lib_deps =
|
|||||||
; STM32duino STM32Ethernet@>=1.3.0
|
; STM32duino STM32Ethernet@>=1.3.0
|
||||||
;
|
;
|
||||||
; PlatformIO 5.x
|
; PlatformIO 5.x
|
||||||
philbowles/STM32AsyncTCP
|
philbowles/STM32AsyncTCP
|
||||||
https://github.com/khoih-prog/STM32AsyncTCP.git
|
https://github.com/khoih-prog/STM32AsyncTCP.git
|
||||||
stm32duino/STM32duino LwIP@>=2.1.2
|
stm32duino/STM32duino LwIP@>=2.1.2
|
||||||
stm32duino/STM32duino STM32Ethernet@>=1.3.0
|
stm32duino/STM32duino STM32Ethernet@>=1.3.0
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
AsyncHTTPRequest_Debug_Generic.h - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
AsyncHTTPRequest_Debug_Generic.h - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_STM32 is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_STM32 is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program.
|
You should have received a copy of the GNU General Public License along with this program.
|
||||||
If not, see <https://www.gnu.org/licenses/>.
|
If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.10.1
|
Version: 1.10.2
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
@ -34,6 +34,7 @@
|
|||||||
1.9.2 K Hoang 18/10/2022 Not try to reconnect to the same host:port after connected
|
1.9.2 K Hoang 18/10/2022 Not try to reconnect to the same host:port after connected
|
||||||
1.10.0 K Hoang 20/10/2022 Fix bug. Clean up
|
1.10.0 K Hoang 20/10/2022 Fix bug. Clean up
|
||||||
1.10.1 K Hoang 21/10/2022 Fix bug of wrong reqStates
|
1.10.1 K Hoang 21/10/2022 Fix bug of wrong reqStates
|
||||||
|
1.10.2 K Hoang 09/11/2022 Default to reconnect to the same host:port after connected for new HTTP sites
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
AsyncHTTPRequest_Generic.h - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
AsyncHTTPRequest_Generic.h - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
AsyncHTTPRequest_STM32 is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
AsyncHTTPRequest_STM32 is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with this program.
|
You should have received a copy of the GNU General Public License along with this program.
|
||||||
If not, see <https://www.gnu.org/licenses/>.
|
If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.10.1
|
Version: 1.10.2
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
@ -34,6 +34,7 @@
|
|||||||
1.9.2 K Hoang 18/10/2022 Not try to reconnect to the same host:port after connected
|
1.9.2 K Hoang 18/10/2022 Not try to reconnect to the same host:port after connected
|
||||||
1.10.0 K Hoang 20/10/2022 Fix bug. Clean up
|
1.10.0 K Hoang 20/10/2022 Fix bug. Clean up
|
||||||
1.10.1 K Hoang 21/10/2022 Fix bug of wrong reqStates
|
1.10.1 K Hoang 21/10/2022 Fix bug of wrong reqStates
|
||||||
|
1.10.2 K Hoang 09/11/2022 Default to reconnect to the same host:port after connected for new HTTP sites
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
You should have received a copy of the GNU General Public License along with this program.
|
You should have received a copy of the GNU General Public License along with this program.
|
||||||
If not, see <https://www.gnu.org/licenses/>.
|
If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.10.1
|
Version: 1.10.2
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
@ -34,6 +34,7 @@
|
|||||||
1.9.2 K Hoang 18/10/2022 Not try to reconnect to the same host:port after connected
|
1.9.2 K Hoang 18/10/2022 Not try to reconnect to the same host:port after connected
|
||||||
1.10.0 K Hoang 20/10/2022 Fix bug. Clean up
|
1.10.0 K Hoang 20/10/2022 Fix bug. Clean up
|
||||||
1.10.1 K Hoang 21/10/2022 Fix bug of wrong reqStates
|
1.10.1 K Hoang 21/10/2022 Fix bug of wrong reqStates
|
||||||
|
1.10.2 K Hoang 09/11/2022 Default to reconnect to the same host:port after connected for new HTTP sites
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@ -43,13 +44,13 @@
|
|||||||
|
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.10.1"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.10.2"
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MAJOR 1
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MAJOR 1
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MINOR 10
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MINOR 10
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_PATCH 1
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_PATCH 2
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT 1010001
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT 1010002
|
||||||
|
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
|
||||||
@ -57,6 +58,14 @@
|
|||||||
|
|
||||||
#include "AsyncHTTPRequest_Debug_Generic.h"
|
#include "AsyncHTTPRequest_Debug_Generic.h"
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
|
||||||
|
#if !defined(NOT_SEND_HEADER_AFTER_CONNECTED)
|
||||||
|
// Default is false
|
||||||
|
#define NOT_SEND_HEADER_AFTER_CONNECTED false
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef DEBUG_IOTA_PORT
|
#ifndef DEBUG_IOTA_PORT
|
||||||
|
File diff suppressed because it is too large
Load Diff
70
utils/astyle_library.conf
Normal file
70
utils/astyle_library.conf
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
# Code formatting rules for Arduino libraries, modified from for KH libraries:
|
||||||
|
#
|
||||||
|
# https://github.com/arduino/Arduino/blob/master/build/shared/examples_formatter.conf
|
||||||
|
#
|
||||||
|
|
||||||
|
# astyle --style=allman -s2 -t2 -C -S -xW -Y -M120 -f -p -xg -H -xb -c --xC120 -xL *.h *.cpp *.ino
|
||||||
|
|
||||||
|
--mode=c
|
||||||
|
--lineend=linux
|
||||||
|
--style=allman
|
||||||
|
|
||||||
|
# -r or -R
|
||||||
|
#--recursive
|
||||||
|
|
||||||
|
# -c => Converts tabs into spaces
|
||||||
|
convert-tabs
|
||||||
|
|
||||||
|
# -s2 => 2 spaces indentation
|
||||||
|
--indent=spaces=2
|
||||||
|
|
||||||
|
# -t2 => tab =2 spaces
|
||||||
|
#--indent=tab=2
|
||||||
|
|
||||||
|
# -C
|
||||||
|
--indent-classes
|
||||||
|
|
||||||
|
# -S
|
||||||
|
--indent-switches
|
||||||
|
|
||||||
|
# -xW
|
||||||
|
--indent-preproc-block
|
||||||
|
|
||||||
|
# -Y => indent classes, switches (and cases), comments starting at column 1
|
||||||
|
--indent-col1-comments
|
||||||
|
|
||||||
|
# -M120 => maximum of 120 spaces to indent a continuation line
|
||||||
|
--max-continuation-indent=120
|
||||||
|
|
||||||
|
# -xC120 => max‑code‑length will break a line if the code exceeds # characters
|
||||||
|
--max-code-length=120
|
||||||
|
|
||||||
|
# -f =>
|
||||||
|
--break-blocks
|
||||||
|
|
||||||
|
# -p => put a space around operators
|
||||||
|
--pad-oper
|
||||||
|
|
||||||
|
# -xg => Insert space padding after commas
|
||||||
|
--pad-comma
|
||||||
|
|
||||||
|
# -H => put a space after if/for/while
|
||||||
|
pad-header
|
||||||
|
|
||||||
|
# -xb => Break one line headers (e.g. if/for/while)
|
||||||
|
--break-one-line-headers
|
||||||
|
|
||||||
|
# -c => Converts tabs into spaces
|
||||||
|
#--convert-tabs
|
||||||
|
|
||||||
|
# if you like one-liners, keep them
|
||||||
|
#keep-one-line-statements
|
||||||
|
|
||||||
|
# -xV
|
||||||
|
--attach-closing-while
|
||||||
|
|
||||||
|
#unpad-paren
|
||||||
|
|
||||||
|
# -xp
|
||||||
|
remove-comment-prefix
|
||||||
|
|
6
utils/restyle.sh
Normal file
6
utils/restyle.sh
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
for dir in . ; do
|
||||||
|
find $dir -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.ino" \) -exec astyle --suffix=none --options=./utils/astyle_library.conf \{\} \;
|
||||||
|
done
|
||||||
|
|
Reference in New Issue
Block a user