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

Commit 0507a1c

Browse files
authored
Major Release v1.1.0
### Major Release v1.1.0 1. Add high-level **HTTP and WebSockets Client** by merging [ArduinoHttpClient Library](https://github.com/arduino-libraries/ArduinoHttpClient) 2. Add many more examples for HTTP and WebSockets Client.
1 parent aeb2bdf commit 0507a1c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+12129
-140
lines changed

README.md

Lines changed: 229 additions & 55 deletions
Large diffs are not rendered by default.

examples/AdvancedWebServer/AdvancedWebServer.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ void handleRoot()
7070
int hr = min / 60;
7171
int day = hr / 24;
7272

73+
hr = hr % 24;
74+
7375
snprintf(temp, BUFFER_SIZE - 1,
7476
"<html>\
7577
<head>\

examples/AdvancedWebServer/AdvancedWebServer.ino.NINA_B302_ublox.hex

Lines changed: 4182 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/****************************************************************************************************************************
2+
BasicAuthGet.ino - Simple Arduino web server sample for WiFi shield
3+
4+
For any WiFi shields, such as WiFiNINA W101, W102, W13x, or custom, such as ESP8266/ESP32-AT, Ethernet, etc
5+
6+
WiFiWebServer is a library for the ESP32-based WiFi shields to run WebServer
7+
Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases
8+
Based on and modified from Arduino WiFiNINA library https://www.arduino.cc/en/Reference/WiFiNINA
9+
Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer
10+
Licensed under MIT license
11+
12+
GET client with HTTP basic authentication for ArduinoHttpClient library
13+
Connects to server once every five seconds, sends a GET request
14+
15+
created 14 Feb 2016
16+
by Tom Igoe
17+
modified 3 Jan 2017 to add HTTP basic authentication
18+
by Sandeep Mistry
19+
modified 22 Jan 2019
20+
by Tom Igoe
21+
*****************************************************************************************************************************/
22+
23+
#include "defines.h"
24+
25+
char serverAddress[] = "192.168.2.112"; // server address
26+
int port = 8080;
27+
28+
WiFiClient client;
29+
WiFiHttpClient httpClient(client, serverAddress);
30+
31+
int status = WL_IDLE_STATUS; // the Wifi radio's status
32+
33+
void printWifiStatus()
34+
{
35+
// print the SSID of the network you're attached to:
36+
// you're connected now, so print out the data
37+
Serial.print(F("You're connected to the network, IP = "));
38+
Serial.println(WiFi.localIP());
39+
40+
Serial.print(F("SSID: "));
41+
Serial.print(WiFi.SSID());
42+
43+
// print the received signal strength:
44+
int32_t rssi = WiFi.RSSI();
45+
Serial.print(F(", Signal strength (RSSI):"));
46+
Serial.print(rssi);
47+
Serial.println(F(" dBm"));
48+
}
49+
50+
void setup()
51+
{
52+
Serial.begin(115200);
53+
while (!Serial);
54+
55+
Serial.print("\nStarting BasicAuthGet on " + String(BOARD_NAME));
56+
Serial.println(" with " + String(SHIELD_TYPE));
57+
58+
// check for the presence of the shield
59+
#if USE_WIFI_NINA
60+
if (WiFi.status() == WL_NO_MODULE)
61+
#else
62+
if (WiFi.status() == WL_NO_SHIELD)
63+
#endif
64+
{
65+
Serial.println(F("WiFi shield not present"));
66+
// don't continue
67+
while (true);
68+
}
69+
70+
#if USE_WIFI_NINA
71+
String fv = WiFi.firmwareVersion();
72+
if (fv < WIFI_FIRMWARE_LATEST_VERSION)
73+
{
74+
Serial.println(F("Please upgrade the firmware"));
75+
}
76+
#endif
77+
78+
// attempt to connect to WiFi network
79+
while ( status != WL_CONNECTED)
80+
{
81+
Serial.print(F("Connecting to SSID: "));
82+
Serial.println(ssid);
83+
// Connect to WPA/WPA2 network
84+
status = WiFi.begin(ssid, pass);
85+
}
86+
87+
// you're connected now, so print out the data
88+
printWifiStatus();
89+
}
90+
91+
void loop()
92+
{
93+
Serial.println("making GET request with HTTP basic authentication");
94+
httpClient.beginRequest();
95+
httpClient.get("/secure");
96+
httpClient.sendBasicAuth("username", "password"); // send the username and password for authentication
97+
httpClient.endRequest();
98+
99+
// read the status code and body of the response
100+
int statusCode = httpClient.responseStatusCode();
101+
String response = httpClient.responseBody();
102+
103+
Serial.print("Status code: ");
104+
Serial.println(statusCode);
105+
Serial.print("Response: ");
106+
Serial.println(response);
107+
108+
Serial.println("Wait five seconds");
109+
delay(5000);
110+
}

0 commit comments

Comments
 (0)