forked from khoih-prog/AsyncHTTPRequest_Generic
Update README.md and use allman astyle
This commit is contained in:
@@ -41,7 +41,7 @@
|
||||
//*************************************************************************************************************
|
||||
|
||||
#if !( defined(ESP8266) || defined(ESP32) )
|
||||
#error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting.
|
||||
#error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
// Level from 0-4
|
||||
@@ -60,9 +60,9 @@ const char* ssid = "your_ssid";
|
||||
const char* password = "your_pass";
|
||||
|
||||
#if (ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#elif (ESP32)
|
||||
#include <WiFi.h>
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
|
||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2"
|
||||
@@ -85,103 +85,103 @@ Ticker ticker1;
|
||||
|
||||
void heartBeatPrint()
|
||||
{
|
||||
static int num = 1;
|
||||
static int num = 1;
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED)
|
||||
Serial.print(F("H")); // H means connected to WiFi
|
||||
else
|
||||
Serial.print(F("F")); // F means not connected to WiFi
|
||||
if (WiFi.status() == WL_CONNECTED)
|
||||
Serial.print(F("H")); // H means connected to WiFi
|
||||
else
|
||||
Serial.print(F("F")); // F means not connected to WiFi
|
||||
|
||||
if (num == 80)
|
||||
{
|
||||
Serial.println();
|
||||
num = 1;
|
||||
}
|
||||
else if (num++ % 10 == 0)
|
||||
{
|
||||
Serial.print(F(" "));
|
||||
}
|
||||
if (num == 80)
|
||||
{
|
||||
Serial.println();
|
||||
num = 1;
|
||||
}
|
||||
else if (num++ % 10 == 0)
|
||||
{
|
||||
Serial.print(F(" "));
|
||||
}
|
||||
}
|
||||
|
||||
void sendRequest()
|
||||
{
|
||||
static bool requestOpenResult;
|
||||
static bool requestOpenResult;
|
||||
|
||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||
{
|
||||
//requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
|
||||
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||
{
|
||||
//requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
|
||||
requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt");
|
||||
|
||||
if (requestOpenResult)
|
||||
{
|
||||
// Only send() if open() returns true, or crash
|
||||
request.send();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println(F("Can't send bad request"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println(F("Can't send request"));
|
||||
}
|
||||
if (requestOpenResult)
|
||||
{
|
||||
// Only send() if open() returns true, or crash
|
||||
request.send();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println(F("Can't send bad request"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println(F("Can't send request"));
|
||||
}
|
||||
}
|
||||
|
||||
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
|
||||
{
|
||||
(void) optParm;
|
||||
(void) optParm;
|
||||
|
||||
if (readyState == readyStateDone)
|
||||
{
|
||||
AHTTP_LOGDEBUG(F("\n**************************************"));
|
||||
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
||||
if (readyState == readyStateDone)
|
||||
{
|
||||
AHTTP_LOGDEBUG(F("\n**************************************"));
|
||||
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
|
||||
|
||||
if (request->responseHTTPcode() == 200)
|
||||
{
|
||||
Serial.println(F("\n**************************************"));
|
||||
Serial.println(request->responseText());
|
||||
Serial.println(F("**************************************"));
|
||||
}
|
||||
}
|
||||
if (request->responseHTTPcode() == 200)
|
||||
{
|
||||
Serial.println(F("\n**************************************"));
|
||||
Serial.println(request->responseText());
|
||||
Serial.println(F("**************************************"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
|
||||
while (!Serial && millis() < 5000);
|
||||
while (!Serial && millis() < 5000);
|
||||
|
||||
Serial.print(F("\nStarting AsyncHTTPRequest_ESP using "));
|
||||
Serial.println(ARDUINO_BOARD);
|
||||
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||
Serial.print(F("\nStarting AsyncHTTPRequest_ESP using "));
|
||||
Serial.println(ARDUINO_BOARD);
|
||||
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
Serial.print(F("Connecting to WiFi SSID: "));
|
||||
Serial.println(ssid);
|
||||
Serial.print(F("Connecting to WiFi SSID: "));
|
||||
Serial.println(ssid);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
Serial.print(F("."));
|
||||
}
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
Serial.print(F("."));
|
||||
}
|
||||
|
||||
Serial.print(F("\nAsyncHTTPRequest @ IP : "));
|
||||
Serial.println(WiFi.localIP());
|
||||
Serial.print(F("\nAsyncHTTPRequest @ IP : "));
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
request.setDebug(false);
|
||||
request.setDebug(false);
|
||||
|
||||
request.onReadyStateChange(requestCB);
|
||||
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);
|
||||
request.onReadyStateChange(requestCB);
|
||||
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);
|
||||
|
||||
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
|
||||
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
|
||||
|
||||
// Send first request now
|
||||
sendRequest();
|
||||
// Send first request now
|
||||
sendRequest();
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
||||
Reference in New Issue
Block a user