-
Notifications
You must be signed in to change notification settings - Fork 18
/
ESP8266_WiFiClient.ino
47 lines (40 loc) · 1.07 KB
/
ESP8266_WiFiClient.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <ESP8266WiFi.h>
const char *ssid = "MY_SSID"; // TODO
const char *password = "MY_PASSWORD"; // TODO
void setup() {
Serial.begin(115200);
Serial.print("\nConnecting to network ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
Serial.print("Connected to network, local IP = ");
Serial.println(WiFi.localIP());
const char *host = "tmb.gr";
const char *path = "/hello.json";
const int port = 80;
// connect to remote host
WiFiClient client;
if (client.connect(host, port)) {
// send HTTP request
client.print("GET ");
client.print(path);
client.print(" HTTP/1.1\r\n");
client.print("Host: ");
client.print(host);
client.print("\r\n");
client.print("Connection: close\r\n");
client.print("\r\n");
// read HTTP response
while (client.connected() || client.available()) {
int ch = client.read();
while (ch >= 0) {
Serial.print((char) ch);
ch = client.read();
}
}
}
}
void loop() {}