Skip to content

Commit f882f3f

Browse files
author
Martin Chlebovec
committed
update
1 parent 6f7cc6a commit f882f3f

Some content is hidden

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

49 files changed

+9333
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Authorization.ino
3+
*
4+
* Created on: 09.12.2015
5+
*
6+
*/
7+
8+
#include <Arduino.h>
9+
10+
#include <ESP8266WiFi.h>
11+
#include <ESP8266WiFiMulti.h>
12+
13+
#include <ESP8266HTTPClient.h>
14+
15+
#define USE_SERIAL Serial
16+
17+
ESP8266WiFiMulti WiFiMulti;
18+
19+
void setup() {
20+
21+
USE_SERIAL.begin(115200);
22+
// USE_SERIAL.setDebugOutput(true);
23+
24+
USE_SERIAL.println();
25+
USE_SERIAL.println();
26+
USE_SERIAL.println();
27+
28+
for(uint8_t t = 4; t > 0; t--) {
29+
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
30+
USE_SERIAL.flush();
31+
delay(1000);
32+
}
33+
34+
WiFiMulti.addAP("SSID", "PASSWORD");
35+
36+
}
37+
38+
void loop() {
39+
// wait for WiFi connection
40+
if((WiFiMulti.run() == WL_CONNECTED)) {
41+
42+
HTTPClient http;
43+
44+
USE_SERIAL.print("[HTTP] begin...\n");
45+
// configure traged server and url
46+
47+
48+
http.begin("http://user:password@192.168.1.12/test.html");
49+
50+
/*
51+
// or
52+
http.begin("http://192.168.1.12/test.html");
53+
http.setAuthorization("user", "password");
54+
55+
// or
56+
http.begin("http://192.168.1.12/test.html");
57+
http.setAuthorization("dXNlcjpwYXN3b3Jk");
58+
*/
59+
60+
61+
USE_SERIAL.print("[HTTP] GET...\n");
62+
// start connection and send HTTP header
63+
int httpCode = http.GET();
64+
65+
// httpCode will be negative on error
66+
if(httpCode > 0) {
67+
// HTTP header has been send and Server response header has been handled
68+
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
69+
70+
// file found at server
71+
if(httpCode == HTTP_CODE_OK) {
72+
String payload = http.getString();
73+
USE_SERIAL.println(payload);
74+
}
75+
} else {
76+
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
77+
}
78+
79+
http.end();
80+
}
81+
82+
delay(10000);
83+
}
84+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* BasicHTTPClient.ino
3+
*
4+
* Created on: 24.05.2015
5+
*
6+
*/
7+
8+
#include <Arduino.h>
9+
10+
#include <ESP8266WiFi.h>
11+
#include <ESP8266WiFiMulti.h>
12+
13+
#include <ESP8266HTTPClient.h>
14+
15+
#define USE_SERIAL Serial
16+
17+
ESP8266WiFiMulti WiFiMulti;
18+
19+
void setup() {
20+
21+
USE_SERIAL.begin(115200);
22+
// USE_SERIAL.setDebugOutput(true);
23+
24+
USE_SERIAL.println();
25+
USE_SERIAL.println();
26+
USE_SERIAL.println();
27+
28+
for(uint8_t t = 4; t > 0; t--) {
29+
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
30+
USE_SERIAL.flush();
31+
delay(1000);
32+
}
33+
34+
WiFiMulti.addAP("SSID", "PASSWORD");
35+
36+
}
37+
38+
void loop() {
39+
// wait for WiFi connection
40+
if((WiFiMulti.run() == WL_CONNECTED)) {
41+
42+
HTTPClient http;
43+
44+
USE_SERIAL.print("[HTTP] begin...\n");
45+
// configure traged server and url
46+
//http.begin("https://192.168.1.12/test.html", "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPS
47+
http.begin("http://192.168.1.12/test.html"); //HTTP
48+
49+
USE_SERIAL.print("[HTTP] GET...\n");
50+
// start connection and send HTTP header
51+
int httpCode = http.GET();
52+
53+
// httpCode will be negative on error
54+
if(httpCode > 0) {
55+
// HTTP header has been send and Server response header has been handled
56+
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
57+
58+
// file found at server
59+
if(httpCode == HTTP_CODE_OK) {
60+
String payload = http.getString();
61+
USE_SERIAL.println(payload);
62+
}
63+
} else {
64+
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
65+
}
66+
67+
http.end();
68+
}
69+
70+
delay(10000);
71+
}
72+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* reuseConnection.ino
3+
*
4+
* Created on: 22.11.2015
5+
*
6+
*/
7+
8+
9+
#include <Arduino.h>
10+
11+
#include <ESP8266WiFi.h>
12+
#include <ESP8266WiFiMulti.h>
13+
14+
#include <ESP8266HTTPClient.h>
15+
16+
#define USE_SERIAL Serial
17+
18+
ESP8266WiFiMulti WiFiMulti;
19+
20+
HTTPClient http;
21+
22+
void setup() {
23+
24+
USE_SERIAL.begin(115200);
25+
// USE_SERIAL.setDebugOutput(true);
26+
27+
USE_SERIAL.println();
28+
USE_SERIAL.println();
29+
USE_SERIAL.println();
30+
31+
for(uint8_t t = 4; t > 0; t--) {
32+
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
33+
USE_SERIAL.flush();
34+
delay(1000);
35+
}
36+
37+
WiFiMulti.addAP("SSID", "PASSWORD");
38+
39+
// allow reuse (if server supports it)
40+
http.setReuse(true);
41+
}
42+
43+
void loop() {
44+
// wait for WiFi connection
45+
if((WiFiMulti.run() == WL_CONNECTED)) {
46+
47+
http.begin("http://192.168.1.12/test.html");
48+
//http.begin("192.168.1.12", 80, "/test.html");
49+
50+
int httpCode = http.GET();
51+
if(httpCode > 0) {
52+
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
53+
54+
// file found at server
55+
if(httpCode == HTTP_CODE_OK) {
56+
http.writeToStream(&USE_SERIAL);
57+
}
58+
} else {
59+
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
60+
}
61+
62+
http.end();
63+
}
64+
65+
delay(1000);
66+
}
67+
68+
69+
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* StreamHTTPClient.ino
3+
*
4+
* Created on: 24.05.2015
5+
*
6+
*/
7+
8+
#include <Arduino.h>
9+
10+
#include <ESP8266WiFi.h>
11+
#include <ESP8266WiFiMulti.h>
12+
13+
#include <ESP8266HTTPClient.h>
14+
15+
#define USE_SERIAL Serial
16+
17+
ESP8266WiFiMulti WiFiMulti;
18+
19+
void setup() {
20+
21+
USE_SERIAL.begin(115200);
22+
// USE_SERIAL.setDebugOutput(true);
23+
24+
USE_SERIAL.println();
25+
USE_SERIAL.println();
26+
USE_SERIAL.println();
27+
28+
for(uint8_t t = 4; t > 0; t--) {
29+
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
30+
USE_SERIAL.flush();
31+
delay(1000);
32+
}
33+
34+
WiFiMulti.addAP("SSID", "PASSWORD");
35+
36+
}
37+
38+
void loop() {
39+
// wait for WiFi connection
40+
if((WiFiMulti.run() == WL_CONNECTED)) {
41+
42+
HTTPClient http;
43+
44+
USE_SERIAL.print("[HTTP] begin...\n");
45+
46+
// configure server and url
47+
http.begin("http://192.168.1.12/test.html");
48+
//http.begin("192.168.1.12", 80, "/test.html");
49+
50+
USE_SERIAL.print("[HTTP] GET...\n");
51+
// start connection and send HTTP header
52+
int httpCode = http.GET();
53+
if(httpCode > 0) {
54+
// HTTP header has been send and Server response header has been handled
55+
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
56+
57+
// file found at server
58+
if(httpCode == HTTP_CODE_OK) {
59+
60+
// get lenght of document (is -1 when Server sends no Content-Length header)
61+
int len = http.getSize();
62+
63+
// create buffer for read
64+
uint8_t buff[128] = { 0 };
65+
66+
// get tcp stream
67+
WiFiClient * stream = http.getStreamPtr();
68+
69+
// read all data from server
70+
while(http.connected() && (len > 0 || len == -1)) {
71+
// get available data size
72+
size_t size = stream->available();
73+
74+
if(size) {
75+
// read up to 128 byte
76+
int c = stream->readBytes(buff, ((size > sizeof(buff)) ? sizeof(buff) : size));
77+
78+
// write it to Serial
79+
USE_SERIAL.write(buff, c);
80+
81+
if(len > 0) {
82+
len -= c;
83+
}
84+
}
85+
delay(1);
86+
}
87+
88+
USE_SERIAL.println();
89+
USE_SERIAL.print("[HTTP] connection closed or file end.\n");
90+
91+
}
92+
} else {
93+
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
94+
}
95+
96+
http.end();
97+
}
98+
99+
delay(10000);
100+
}
101+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=ESP8266HTTPClient
2+
version=1.1
3+
author=Markus Sattler
4+
maintainer=Markus Sattler
5+
sentence=http Client for ESP8266
6+
paragraph=
7+
category=Communication
8+
url=https://github.com/Links2004/Arduino/tree/libraries/ESP8266HTTPClient
9+
architectures=esp8266

0 commit comments

Comments
 (0)