-
Notifications
You must be signed in to change notification settings - Fork 0
/
RF-Blaster.ino
114 lines (80 loc) · 1.85 KB
/
RF-Blaster.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <Arduino.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266WebServer.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <RCSwitch.h>
#include "fauxmoESP.h"
#include <PubSubClient.h>
#include "config.h"
// this library does all the wemo things
fauxmoESP fauxmo;
// use via browser
ESP8266WebServer server(80);
// network name
MDNSResponder mdns;
// MQTT
WiFiClient espWifiClient;
PubSubClient mqttClient(espWifiClient);
// rc stuff
RCSwitch rfLib = RCSwitch();
// last received code
int lastcode = 0;
void setup()
{
// Initialize serial output
Serial.begin(SERIAL_BAUDRATE);
Serial.println();
Serial.print("starting ");
Serial.println(HOSTNAME);
setupWifi();
mqttSetup();
setupMDNS();
setupWebServer();
setupOTA();
setupRF();
setupFauxmo();
Serial.println("--Setup OK");
Serial.println("");
blinkled(3);
}
void loop()
{
// re connect wifi if down
if (WiFi.status() != WL_CONNECTED) {
setupWifi();
}
// perform Fauxmo actions
fauxmo.handle();
// perform MDNS actions
mdns.update();
// perform webserver actions
server.handleClient();
// perform OTA actions
ArduinoOTA.handle();
// RF Receive
rf_receive();
yield();
}
void blinkled(int count)
{
// clear serial data
Serial.flush();
delay(100);
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
for (int i = 0; i < count; i++)
{
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is active low on the ESP-01)
delay(500);
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
if (i + 1 < count)
delay(500);
}
// Initialize serial output
Serial.begin(SERIAL_BAUDRATE);
Serial.println();
}