-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteliot_sensor.ino
67 lines (51 loc) · 1.32 KB
/
teliot_sensor.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
/*
* Flash settings:
* Board type: Wemos D1 mini
*/
// Libraries
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ESP8266WebServer.h>
#include <WebSocketsServer.h>
#include <ESP8266HTTPClient.h> // To make HTTP requests
// Wifi settings
#define WIFI_STA_SSID "toiletIndicatorNorth"
#define WIFI_STA_PASSWORD "poketenashi"
// Web server setting
#define WWW_PORT 80
#define WS_PORT 81
// IO
#define LED_PIN D4
#define SENSOR_PIN D2
// Wifi callbacks
WiFiEventHandler gotIpEventHandler;
WiFiEventHandler disconnectedEventHandler;
// Wifi client for HTTP requests
WiFiClient wifi_client;
// Web server. mainly used for updates
ESP8266WebServer www_server(WWW_PORT);
WebSocketsServer ws_server = WebSocketsServer(WS_PORT);
// Commands sent through Web Socket
const char VACANT[] = "vacant";
const char OCCUPIED[] = "occupied";
// Toilet occupancy variable
// -1: unknown, 0: vacant, 1: occupied
int toilet_occupied = -1;
void setup() {
// Mandatory initial delay
delay(10);
// Serial init
Serial.begin(115200);
Serial.println();
Serial.println(); // Separate serial stream from initial gibberish
Serial.println(F(__FILE__ " " __DATE__ " " __TIME__));
IO_setup();
wifi_setup();
web_server_setup();
websocket_setup();
}
void loop() {
www_server.handleClient();
ws_server.loop();
read_sensor();
}