-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathWindow_CONFIGURE.ino
73 lines (61 loc) · 1.41 KB
/
Window_CONFIGURE.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
//#include <SPI.h>
#include <PubSubClient.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
//USER CONFIGURED SECTION START//
const char* ssid = "YOUR_WIRELESS_SSID";
const char* password = "YOUR_WIRELESS_SSID";
const char* mqtt_server = "YOUR_MQTT_SERVER_ADDRESS";
const int mqtt_port = YOUR_MQTT_SERVER_PORT;
const char *mqtt_user = "YOUR_MQTT_USERNAME";
const char *mqtt_pass = "YOUR_MQTT_PASSWORD";
const char *mqtt_client_name = "PICK_UNIQUE_WINDOW_NAME"; // Client connections cant have the same connection name
const char *mqtt_topic = "PICK_UNIQUE_WINDOW_TOPIC";
//USER CONFIGURED SECTION END//
WiFiClient espClient;
PubSubClient client(espClient);
// Variables
bool boot = true;
//Functions
void setup_wifi()
{
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}
}
void reconnect()
{
while (!client.connected())
{
if (client.connect(mqtt_client_name, mqtt_user, mqtt_pass, mqtt_topic, 0, 0, "closed"))
{
if(boot == true)
{
client.publish(mqtt_topic,"open");
boot = false;
}
}
else
{
ESP.restart();
}
}
}
void setup() {
// GPIO Pin Setup
setup_wifi();
client.setServer(mqtt_server, mqtt_port);
}
void loop()
{
if (boot == true)
{
reconnect();
}
else
{
ESP.deepSleep(0);
}
}