-
Notifications
You must be signed in to change notification settings - Fork 0
/
CarClient.ino
72 lines (54 loc) · 1.17 KB
/
CarClient.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
/*
Intranet of Things Car Client
*/
#define BUZZER_PIN 0
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
const char* ssid = "xxxxxx";
const char* password = "xxxxxx";
ESP8266WebServer server ( 80 );
IPAddress ip(192,168,0,1);
IPAddress gateway(192,168,0,254);
IPAddress subnet(255,255,255,0);
void beep(int times) {
for( ; times>0; times--) {
digitalWrite(BUZZER_PIN, LOW);
delay(200);
digitalWrite(BUZZER_PIN, HIGH);
delay(200);
}
}
void handleRoot() {
char temp[10];
int sec = millis() / 1000;
snprintf ( temp, 10, "%d", sec);
server.send ( 200, "text/html", temp );
}
void handleBeep1() {
handleRoot();
beep(1);
}
void handleBeep2() {
handleRoot();
beep(2);
}
void handleBeep3() {
handleRoot();
beep(3);
}
void setup() {
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, HIGH);
WiFi.begin(ssid, password);
WiFi.config(ip, gateway, subnet);
server.on ( "/", handleRoot);
server.on ( "/beep1", handleBeep1);
server.on ( "/beep2", handleBeep2);
server.on ( "/beep3", handleBeep3);
server.begin();
}
void loop() {
server.handleClient();
}