Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 47fd60f

Browse files
authored
Add more examples
1 parent 8c53d95 commit 47fd60f

File tree

2 files changed

+243
-0
lines changed

2 files changed

+243
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/****************************************************************************************************************************
2+
AsyncWebClientRepeating_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
3+
4+
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
5+
6+
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
7+
8+
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
9+
10+
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
11+
Licensed under MIT license
12+
13+
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
14+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
15+
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
16+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18+
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
20+
Version: 1.0.0
21+
22+
Version Modified By Date Comments
23+
------- ----------- ---------- -----------
24+
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
25+
*****************************************************************************************************************************/
26+
27+
#include "defines.h"
28+
29+
// Select a test server address
30+
const char GET_ServerAddress[] = "arduino.cc";
31+
32+
// GET location
33+
String GET_Location = "/asciilogo.txt";
34+
35+
// 10s = 10 seconds to not flooding the server
36+
#define HTTP_REQUEST_INTERVAL_MS 10000
37+
38+
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
39+
40+
#include <Ticker.h> // https://github.com/sstaub/Ticker
41+
42+
AsyncHTTPRequest request;
43+
44+
void sendRequest(void);
45+
46+
// Repeat forever, millis() resolution
47+
Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
48+
49+
void sendRequest(void)
50+
{
51+
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
52+
{
53+
request.open("GET", (GET_ServerAddress + GET_Location).c_str());
54+
55+
request.send();
56+
}
57+
}
58+
59+
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
60+
{
61+
if (readyState == readyStateDone)
62+
{
63+
Serial.println("\n**************************************");
64+
Serial.println(request->responseText());
65+
Serial.println("**************************************");
66+
67+
request->setDebug(false);
68+
}
69+
}
70+
71+
void setup(void)
72+
{
73+
Serial.begin(115200);
74+
while (!Serial);
75+
76+
Serial.println("\nStart AsyncWebClientRepeating_STM32 on " + String(BOARD_NAME));
77+
78+
// start the ethernet connection and the server
79+
// Use random mac
80+
uint16_t index = millis() % NUMBER_OF_MAC;
81+
82+
// Use Static IP
83+
//Ethernet.begin(mac[index], ip);
84+
// Use DHCP dynamic IP and random mac
85+
Ethernet.begin(mac[index]);
86+
87+
Serial.print(F("AsyncHTTPRequest @ IP : "));
88+
Serial.println(Ethernet.localIP());
89+
Serial.println();
90+
91+
request.setDebug(false);
92+
93+
request.onReadyStateChange(requestCB);
94+
sendHTTPRequest.start(); //start the ticker
95+
96+
// Send first request now
97+
sendRequest();
98+
}
99+
100+
void loop(void)
101+
{
102+
sendHTTPRequest.update();
103+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/****************************************************************************************************************************
2+
defines.h
3+
4+
Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
5+
6+
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
7+
8+
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
9+
10+
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
11+
12+
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
13+
Licensed under MIT license
14+
15+
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
16+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
17+
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
18+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20+
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
21+
22+
Version: 1.0.0
23+
24+
Version Modified By Date Comments
25+
------- ----------- ---------- -----------
26+
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
27+
*****************************************************************************************************************************/
28+
/*
29+
Currently support
30+
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
31+
- Nucleo-144 (F429ZI, F767ZI)
32+
- Discovery (STM32F746G-DISCOVERY)
33+
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
34+
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
35+
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
36+
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
37+
*/
38+
39+
#ifndef defines_h
40+
#define defines_h
41+
42+
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
43+
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
44+
defined(STM32WB) || defined(STM32MP1) )
45+
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
46+
#endif
47+
48+
#define ASYNC_HTTP_DEBUG_PORT Serial
49+
50+
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
51+
#define _ASYNC_HTTP_LOGLEVEL_ 1
52+
53+
54+
#if defined(STM32F0)
55+
#warning STM32F0 board selected
56+
#define BOARD_TYPE "STM32F0"
57+
#elif defined(STM32F1)
58+
#warning STM32F1 board selected
59+
#define BOARD_TYPE "STM32F1"
60+
#elif defined(STM32F2)
61+
#warning STM32F2 board selected
62+
#define BOARD_TYPE "STM32F2"
63+
#elif defined(STM32F3)
64+
#warning STM32F3 board selected
65+
#define BOARD_TYPE "STM32F3"
66+
#elif defined(STM32F4)
67+
#warning STM32F4 board selected
68+
#define BOARD_TYPE "STM32F4"
69+
#elif defined(STM32F7)
70+
#warning STM32F7 board selected
71+
#define BOARD_TYPE "STM32F7"
72+
#elif defined(STM32L0)
73+
#warning STM32L0 board selected
74+
#define BOARD_TYPE "STM32L0"
75+
#elif defined(STM32L1)
76+
#warning STM32L1 board selected
77+
#define BOARD_TYPE "STM32L1"
78+
#elif defined(STM32L4)
79+
#warning STM32L4 board selected
80+
#define BOARD_TYPE "STM32L4"
81+
#elif defined(STM32H7)
82+
#warning STM32H7 board selected
83+
#define BOARD_TYPE "STM32H7"
84+
#elif defined(STM32G0)
85+
#warning STM32G0 board selected
86+
#define BOARD_TYPE "STM32G0"
87+
#elif defined(STM32G4)
88+
#warning STM32G4 board selected
89+
#define BOARD_TYPE "STM32G4"
90+
#elif defined(STM32WB)
91+
#warning STM32WB board selected
92+
#define BOARD_TYPE "STM32WB"
93+
#elif defined(STM32MP1)
94+
#warning STM32MP1 board selected
95+
#define BOARD_TYPE "STM32MP1"
96+
#else
97+
#warning STM32 unknown board selected
98+
#define BOARD_TYPE "STM32 Unknown"
99+
#endif
100+
101+
#ifndef BOARD_NAME
102+
#define BOARD_NAME BOARD_TYPE
103+
#endif
104+
105+
#include <LwIP.h>
106+
#include <STM32Ethernet.h>
107+
108+
//#include <AsyncUDP_STM32.h>
109+
110+
// Enter a MAC address and IP address for your controller below.
111+
#define NUMBER_OF_MAC 20
112+
113+
byte mac[][NUMBER_OF_MAC] =
114+
{
115+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
116+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
117+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
118+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
119+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
120+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
121+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
122+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
123+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
124+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
125+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
126+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
127+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
128+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
129+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
130+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
131+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
132+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
133+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
134+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
135+
};
136+
137+
// Select the static IP address according to your local network
138+
IPAddress ip(192, 168, 2, 232);
139+
140+
#endif //defines_h

0 commit comments

Comments
 (0)