This repository has been archived by the owner on Jul 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLED-Service.ino
78 lines (66 loc) · 2.78 KB
/
LED-Service.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
/**
* LED-Service
* @author Curt Henrichs
* @date 1-23-2018
*
* Window LED Service is an ESP8266 based home automation device that interfaces
* a strip of LEDs with a REST API.
*
* Inspiration derived from preserving LED strip's IR remote controller module
* attached to the LED strip but also a desire not to use the IR remote control.
* Thus an microcontroller with WiFi was needed to connect to the network and
* translate commands into an IR stream that is blasted at the LED strip
* controller.
*
* This project consists of a REST API, IR Remote Blaster, and a WiFi Management
* server. See program modules for details.
*/
//==============================================================================
// Libraries
//==============================================================================
#include "HardwareConfig.h"
#include "Station.h"
#include <elapsedMillis.h>
//==============================================================================
// Constant and Macro Definitions
//==============================================================================
#define STATUS_LED_BLINK_TIME (500) //! 1/2 LED flash rate
//==============================================================================
// Private Attributes
//==============================================================================
/**
* Time counter which will act as the timer that periodically toggles status
* LED according to the defined BLINK_TIME
*/
static elapsedMillis status_led_blink_etime = 0;
//==============================================================================
// MAIN
//==============================================================================
/**
* Main setup will configure hardware dependecies before connecting to Wifi. If
* connected then the REST service will start, else application will wait in
* AP mode for new configuration or until manually reset.
*/
void setup(void) {
hwcfig_init();
st_init();
}
/**
* Main loop will maintain wifi station and LED service. Additionally a status
* LED will be flashed periodically to indicate to a user that the device is
* still operating correctly.
*
* If Wifi is lost during operation, device will block execution. During this
* time the Wifi will be configred as in AP mode serving a configuration page.
* Device will exit block when reconfigured or manually reset and connects to
* Wifi.
*/
void loop(void) {
// update wifi station (which will update service)
st_update();
// blink status LED to indicate server still operating
if(status_led_blink_etime >= STATUS_LED_BLINK_TIME){
status_led_blink_etime -= STATUS_LED_BLINK_TIME;
digitalWrite(STATUS_LED_PIN,!digitalRead(STATUS_LED_PIN));
}
}