-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathesp8266.ino
82 lines (60 loc) · 1.81 KB
/
esp8266.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <Wire.h>
#include "SSD1306.h"
IPAddress staticIP(10,0,0,20);
IPAddress gateway(10,0,0,20);
IPAddress subnet(255,255,255,0);
SSD1306 display(0x3C, 0, 2);
ESP8266WebServer server(80);
const char* ssid = "Rick's WiFi";
const char* password = "picklerick";
void handleBody();
void clear_display();
void setup() {
display.init();
display.setFont(ArialMT_Plain_10);
// Connect to WiFi network
display.clear();
display.drawString(0,2,"Connecting to ");
display.drawString(0,15,ssid);
display.display();
WiFi.begin(ssid, password);
WiFi.config(staticIP, gateway, subnet);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
display.clear();
display.drawString(0,2,"...");
display.display();
}
server.on("/body", handleBody); //Associate the handler function to the path
server.on("/clear",clear_display);
display.clear();
display.drawString(0,2,"WiFi connected");
display.display();
delay(2000);
server.begin();
display.clear();
}
void loop() {
server.handleClient(); //Handling of incoming requests
}
void handleBody() { //Handler for the body path
if (server.hasArg("text")== false){ //Check if body received
server.send(200, "text/plain", "Body not received");
return;
}
String message = "Body received:\n";
message += server.arg("text");
message += "\n";
String display_message=server.arg("text");
display.clear();
display.drawString(0,2,display_message);
display.display();
server.send(200, "text/plain", message);
}
void clear_display() { //Handler for the body path
display.clear();
display.display();
server.send(200, "text/plain", "Display Cleared");
}