Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * ################################################################
- * Sensor Software 1.1 (https://imgur.com/a/xK1eu)
- *
- * Changelog 1.1
- * - Move PIR to another PIN
- * - Invert blue LED and only have on when motion detected
- * - Only turn on display when motion detected
- * - Don't syslog timeout when it is zero
- * - Modify all syslog calls to be Splunk firendly
- * - Increase size of display and rotate through sensors only when Timer is active. Include timer
- * - Merge all rooms into one file based on define
- *
- * TODO
- * - Include switch to deactivate schedule mode and possibly manually trigger lights
- * - Look into ability to have lights as part of schedule
- * - Check if Lights are on before turning on
- * - If lights are on and no timer just turn on don't set hue also double the timeout (allows custom manual hue)
- * - Keep track of when last turned on. If it has been less than 15 minutes don't set hue just turn on. Allows for custom hue
- * - Look into interrupts for PIR and sensor syslogging
- * - Look into HTTP Event Collector
- * - Implement UBER sensor!!!
- *
- */
- #include <Adafruit_SSD1306.h>
- #include <Adafruit_GFX.h>
- #include <gfxfont.h>
- #include <Wire.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_TSL2561_U.h>
- #include <pgmspace.h>
- #include <DHT.h>
- #include <ESP8266WiFi.h>
- #include <ESP8266mDNS.h>
- #include <WiFiUdp.h>
- #include <TimeLib.h>
- #include "RestClient.h"
- ////////////////////////////////////////////////////////////////////////////////////////
- // Device Specific Settings
- #define ROOM_BATHROOM 1
- #define ROOM_BEDROOM 2
- #define ROOM_KITCHEN 3
- #define ROOM_TYPE ROOM_KITCHEN // CHANGE THIS ONE!!!!
- ////////
- // Bedroom configs
- #if ROOM_TYPE == ROOM_BEDROOM
- #define ROOM_NAME "Bedroom"
- #define ESP8266_HOSTNAME "esp8266-bedroom"
- // {4,9}
- #define LIGHTS_ARRAY {4}
- #define LIGHTS_SCHEDULE_TIMES_ARRAY {7,17,21,23}
- #define LIGHTS_SCHEDULE_ACTIONS_ARRAY { \
- "{\"xy\":[0.669,0.314], \"on\": true, \"bri\": 48}", \
- "{\"ct\": 153, \"on\": false, \"bri\": 153}", \
- "{\"ct\": 479, \"on\": true, \"bri\": 231}", \
- "{\"xy\":[0.87,0.294], \"on\": true, \"bri\": 144}" \
- }
- #define LIGHTS_SCHEDULE_TIMEOUT_ARRAY {1,5,2,2}
- #define SYSLOG_SERVER_NAME "device=esp8266-bedroom,"
- ////////
- // Kitchen configs
- #elif ROOM_TYPE == ROOM_KITCHEN
- #define ROOM_NAME "Kitchen"
- #define ESP8266_HOSTNAME "esp8266-kitchen"
- #define LIGHTS_ARRAY {7}
- #define LIGHTS_SCHEDULE_TIMES_ARRAY {7,17,21,23}
- #define LIGHTS_SCHEDULE_ACTIONS_ARRAY { \
- "{\"ct\": 495, \"on\": true, \"bri\": 1}", \
- "{\"ct\": 153, \"on\": true, \"bri\": 153}", \
- "{\"ct\": 447, \"on\": true, \"bri\": 255}", \
- "{\"xy\":[0.658,0.3134], \"on\": true, \"bri\": 109}" \
- }
- #define LIGHTS_SCHEDULE_TIMEOUT_ARRAY {1,10,5,2}
- #define SYSLOG_SERVER_NAME "device=esp8266-kitchen,"
- ////////
- // Bathroom configs
- #elif ROOM_TYPE == ROOM_BATHROOM
- #define ROOM_NAME "Bathroom"
- #define ESP8266_HOSTNAME "esp8266-bathroom"
- #define LIGHTS_ARRAY {5}
- #define LIGHTS_SCHEDULE_TIMES_ARRAY {7,18,21,23}
- #define LIGHTS_SCHEDULE_ACTIONS_ARRAY { \
- "{\"ct\": 495, \"on\": true, \"bri\": 1}", \
- "{\"ct\": 153, \"on\": true, \"bri\": 153}", \
- "{\"ct\": 447, \"on\": true, \"bri\": 255}", \
- "{\"xy\":[0.658,0.3134], \"on\": true, \"bri\": 109}" \
- }
- #define LIGHTS_SCHEDULE_TIMEOUT_ARRAY {1,5,5,2}
- #define SYSLOG_SERVER_NAME "device=esp8266-bathroom,"
- #endif
- #define SYSLOG_SERVER_IP "192.168.1.64"
- #define SYSLOG_SERVER_OCTET 192,168,1,64
- #define SYSLOG_SERVER_PORT 8888
- #define HUE_HUB_IP "192.168.1.60"
- #define HUB_AUTH "8VHGiAtOw**********************6AIv8"
- #define WIFI_ACCESS_POINT "YOUR_AP_NAME"
- #define WIFI_PWD "YOUR_AP_WIRELESS_PASSWORD"
- ////////////////////////////////////////////////////////////////////////////////////////
- // Sensors
- // LUX
- Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
- int globalLux = 0;
- // Define DHT Pin
- #define DHTPIN D6
- #define DHTTYPE DHT22 // DHT 22 (AM2302)
- DHT dht(DHTPIN, DHTTYPE);
- static char globalTemp[10];
- static char globalHumidity[10];
- // Define PIR
- #define PIRPIN D5
- int globalPIR = 0;
- // Define onboard LED
- # define LEDPIN D4
- // Variable to remember the previous value of the motion sensor
- int PIR_PrevValue = 0;
- //////////////////////
- // WiFi and Network Settings
- const char* ssid = WIFI_ACCESS_POINT;
- const char* password = WIFI_PWD;
- const char* syslogServerIP = SYSLOG_SERVER_IP;
- unsigned int localPort = SYSLOG_SERVER_PORT;
- ///////////////////////////
- // Syslog Server: https://gist.github.com/chaeplin/8f4b06aa2bd454232892
- IPAddress syslogServer(SYSLOG_SERVER_OCTET);
- char syslogMessage[512];
- const char* syslogServerName = SYSLOG_SERVER_NAME;
- WiFiUDP Udp;
- void sendUdpSyslog(String msgtosend)
- {
- Serial.println(msgtosend);
- unsigned int msg_length = msgtosend.length();
- byte* p = (byte*)malloc(msg_length);
- memcpy(p, (char*) msgtosend.c_str(), msg_length);
- Udp.beginPacket(syslogServer, 514);
- Udp.write(syslogServerName);
- Udp.write(p, msg_length);
- Udp.endPacket();
- free(p);
- }
- ///////////////////////////
- // NTP Servers:
- const int timeZone = 10; // Australian EST Time
- const char* ntpServerName = "time.nist.gov";
- IPAddress timeServerIP;
- time_t prevDisplay = 0; // when the digital clock was displayed
- const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
- byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets
- time_t last_motion_time = 0; // The last time motion was detected
- ///////////////////////////
- // OLED
- #define OLED_RESET 0 // GPIO0
- Adafruit_SSD1306 display(OLED_RESET);
- #define NUMFLAKES 10
- #define XPOS 0
- #define YPOS 1
- #define DELTAY 2
- #define LOGO16_GLCD_HEIGHT 16
- #define LOGO16_GLCD_WIDTH 16
- //////////////////////
- // Light Settings
- // REST Client for Hue Hub Control
- RestClient client = RestClient(HUE_HUB_IP);
- String HTTP_response;
- // Lights to turn on/off
- // int lights[] = {6,7};
- int lights[] = LIGHTS_ARRAY;
- int lightCount = sizeof(lights)/sizeof(int);
- // Fill this array with the hour you want a schedule to trigger for.
- // If the current hour is less than the hour in this array it will set the lights to the associated lightScheduleTrigger
- int lightScheduleTimes[] = LIGHTS_SCHEDULE_TIMES_ARRAY;
- int scheduleCount = sizeof(lightScheduleTimes)/sizeof(int);
- // Fill this array with the light settings you want to use.
- // The first element in the array will be used if no schedule time is matched
- char *lightScheduleTriggers[] = LIGHTS_SCHEDULE_ACTIONS_ARRAY;
- // Sets the timeout in minutes for each schedule as defined in lightScheduleTimes
- int lightTimers[] = LIGHTS_SCHEDULE_TIMEOUT_ARRAY;
- // global variables to store the timeout and number of motion triggers detected during a lightOn state.
- time_t lightTimeout = 0;
- time_t lastOnTime = 0;
- time_t lastOffTime = 0;
- int currentExpectedLightState = 0;
- int lightTriggers = 0;
- //////////////////////
- // NTP Functions for ensuring the time remains accurate for determining the hour of the day
- // send an NTP request to the time server at the given address
- void sendNTPpacket(IPAddress &address)
- {
- // set all bytes in the buffer to 0
- memset(packetBuffer, 0, NTP_PACKET_SIZE);
- // Initialize values needed to form NTP request
- // (see URL above for details on the packets)
- packetBuffer[0] = 0b11100011; // LI, Version, Mode
- packetBuffer[1] = 0; // Stratum, or type of clock
- packetBuffer[2] = 6; // Polling Interval
- packetBuffer[3] = 0xEC; // Peer Clock Precision
- // 8 bytes of zero for Root Delay & Root Dispersion
- packetBuffer[12] = 49;
- packetBuffer[13] = 0x4E;
- packetBuffer[14] = 49;
- packetBuffer[15] = 52;
- // all NTP fields have been given values, now
- // you can send a packet requesting a timestamp:
- Udp.beginPacket(address, 123); //NTP requests are to port 123
- Udp.write(packetBuffer, NTP_PACKET_SIZE);
- Udp.endPacket();
- }
- time_t getNtpTime()
- {
- while (Udp.parsePacket() > 0) ; // discard any previously received packets
- Serial.println("Transmit NTP Request");
- sendNTPpacket(timeServerIP);
- uint32_t beginWait = millis();
- while (millis() - beginWait < 1500) {
- int size = Udp.parsePacket();
- if (size >= NTP_PACKET_SIZE) {
- Serial.println("Receive NTP Response");
- Udp.read(packetBuffer, NTP_PACKET_SIZE); // read packet into the buffer
- unsigned long secsSince1900;
- // convert four bytes starting at location 40 to a long integer
- secsSince1900 = (unsigned long)packetBuffer[40] << 24;
- secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
- secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
- secsSince1900 |= (unsigned long)packetBuffer[43];
- return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
- }
- }
- Serial.println("No NTP Response :-(");
- return 0; // return 0 if unable to get the time
- }
- void printDigits(int digits){
- // utility for digital clock display: prints preceding colon and leading 0
- Serial.print(":");
- if(digits < 10)
- Serial.print('0');
- Serial.print(digits);
- }
- void digitalClockDisplay(){
- // digital clock display of the time
- Serial.print(hour());
- printDigits(minute());
- printDigits(second());
- Serial.print(" ");
- Serial.print(day());
- Serial.print(".");
- Serial.print(month());
- Serial.print(".");
- Serial.print(year());
- Serial.println();
- }
- //////////////////////
- // Send to Splunk HTTP Event Collector
- /*
- const char* splunkHost = "192.168.64.64";
- const int splunkHecPort = 8088;
- // Use web browser to view and copy
- // SHA1 fingerprint of the certificate
- const char* splunkFingerprint = "a8 d9 bb 87 d2 dd 97 06 66 34 a3 15 9c c1 78 3b f7 75 01 d1";
- sendHttpEventCollectorMessage(){
- char httpPostPayload[512];
- // Use WiFiClientSecure class to create TLS connection
- WiFiClientSecure client;
- Serial.print("connecting to ");
- Serial.println(splunkHost);
- if (!client.connect(splunkHost, httpsPort)) {
- Serial.println("connection failed");
- return;
- }
- if (client.verify(splunkFingerprint, splunkHecPort)) {
- Serial.println("certificate matches");
- } else {
- Serial.println("certificate doesn't match");
- }
- String url = "/services/collector/event";
- Serial.print("requesting URL: ");
- Serial.println(url);
- sprintf(httpPostPayload, "{\"event\":\"device=%s,version=%02d","esp8266-kitchen",1);
- client.print(String("POST ") + url + " HTTP/1.1\r\n" +
- "Host: " + host + "\r\n" +
- "Accept: *\/*" +
- "Authorization: Splunk 21d02a08-25cf-4eaa-9787-0395a50151a2" +
- "User-Agent: ESP8266_Sensors\r\n" +
- "Connection: close\r\n\r\n");
- Serial.println("Payload: %s",httpPostPayload);
- Serial.println("request sent");
- while (client.connected()) {
- String line = client.readStringUntil('\n');
- if (line == "\r") {
- Serial.println("headers received");
- break;
- }
- }
- String line = client.readStringUntil('\n');
- if (line.startsWith("{\"state\":\"success\"")) {
- Serial.println("esp8266/Arduino CI successfull!");
- } else {
- Serial.println("esp8266/Arduino CI has failed");
- }
- Serial.println("reply was:");
- Serial.println("==========");
- Serial.println(line);
- Serial.println("==========");
- Serial.println("closing connection");
- }
- */
- //////////////////////
- // Set timeouts
- int setLightTimeouts(int timeoutMinutes){
- sprintf(syslogMessage, "type=info,func=setLightTimeouts,msg=Started");
- sendUdpSyslog(syslogMessage);
- // Check if timer still set
- if (now() < lightTimeout) {
- sprintf(syslogMessage, "type=info,func=setLightTimeouts,msg=Timer still active");
- sendUdpSyslog(syslogMessage);
- // check if trigger counter warrants an increase in the timer (Never greater than 3 times the timeout)
- // Reset timer and increase trigger counter
- lightTimeout = now() + (timeoutMinutes * 60);
- lightTriggers = lightTriggers + 1;
- }
- // Timer is not set
- else {
- sprintf(syslogMessage, "type=info,func=setLightTimeouts,msg=Timer not set");
- sendUdpSyslog(syslogMessage);
- // Set timer and zero trigger counter
- lightTimeout = now() + (timeoutMinutes * 60);
- lightTriggers = 1;
- }
- sprintf(syslogMessage, "type=timeoutSet,func=setLightTimeouts,timeoutMins=%d,timeoutSetTime=%02d:%02d,triggers=%d", timeoutMinutes, hour(lightTimeout), minute(lightTimeout),lightTriggers);
- sendUdpSyslog(syslogMessage);
- }
- //////////////////////
- // Trigger Lights
- int triggerLights(char* strTriggerState){
- int j = 0;
- char lightURI[255];
- char HTTP_response_buffer[255];
- // Turn on all lights in lights array
- for (j = 0; j < lightCount; j = j + 1) {
- sprintf(lightURI, "/api/%s/lights/%d/state", HUB_AUTH, lights[j]);
- sprintf(syslogMessage, "type=hue_comms_out,func=triggerLights,light=%d,setJson=\"%s\",msg=\"Sending light trigger", lights[j], strTriggerState);
- sendUdpSyslog(syslogMessage);
- HTTP_response = "";
- int statusCode = client.put(lightURI, strTriggerState, &HTTP_response);
- HTTP_response.toCharArray(HTTP_response_buffer,255);
- sprintf(syslogMessage, "type=hue_comms_in,func=triggerLights,status=%d,response=\"%s\"", statusCode, HTTP_response_buffer);
- sendUdpSyslog(syslogMessage);
- }
- }
- //////////////////////
- // Trigger Light On
- int lightsOn() {
- // GET HOUR OF DAY
- int currentHour = hour();
- sprintf(syslogMessage, "type=info,func=lightsOn,msg=\"Triggering light for current hour %d\"", currentHour);
- sendUdpSyslog(syslogMessage);
- String hueHubURI = "";
- int i, j;
- int triggered = 0;
- // Loop through schedules until we find one that matches the current hour
- for (i = 0; i < scheduleCount; i = i + 1) {
- if (currentHour < lightScheduleTimes[i]) {
- sprintf(syslogMessage, "type=info,func=lightsOn,msg=\"Hour match for scheduled hour %d (%d)\"", lightScheduleTimes[i],i);
- sendUdpSyslog(syslogMessage);
- // TODO: check light on was a success
- triggerLights(lightScheduleTriggers[i]);
- setLightTimeouts(lightTimers[i]);
- triggered = 1;
- // Break out of loop we have turned on the light and set the timers
- last_motion_time = now();
- break;
- }
- }
- // Hour not present in lightScheduleTimes array use default schedule light settings
- if (triggered == 0) {
- sprintf(syslogMessage, "type=info,func=lightsOn,msg=\"Hour didn't match schedule so trigger default light config.\"");
- sendUdpSyslog(syslogMessage);
- triggerLights(lightScheduleTriggers[0]);
- setLightTimeouts(lightTimers[0]);
- }
- lastOnTime = now();
- currentExpectedLightState = 1;
- }
- //////////////////////
- // Trigger Light Off
- int lightsOff() {
- char lightURI[255];
- int i, j;
- int triggered = 0;
- char* strTriggerStateOff = "{\"on\": false}";
- sprintf(syslogMessage, "type=info,func=lightsOff,msg=\"Triggered turning off lights and resetting timeout.\"");
- sendUdpSyslog(syslogMessage);
- triggerLights(strTriggerStateOff);
- lightTimeout = 0;
- lastOffTime = now();
- currentExpectedLightState = 0;
- lightTriggers = 0;
- }
- //////////////////////
- // Display routines
- int currentDisplayValue = 0;
- int displayOn() {
- // text display tests
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.clearDisplay();
- sprintf(syslogMessage, "type=info,func=displayRotate,msg=\"Showing Room Type.\"");
- sendUdpSyslog(syslogMessage);
- display.setCursor(0,0);
- display.println(ROOM_NAME);
- display.display();
- delay(1000);
- }
- int displayRotate() {
- // sprintf(syslogMessage, "type=info,func=displayRotate,msg=\"Clearing display current value %d.\"",currentDisplayValue);
- // sendUdpSyslog(syslogMessage);
- // Clear the display buffer.
- display.clearDisplay();
- switch (currentDisplayValue) {
- case 1:
- // sprintf(syslogMessage, "type=info,func=displayRotate,msg=\"Showing Triggers.\"");
- // sendUdpSyslog(syslogMessage);
- display.setCursor(0,0);
- display.print("Trig: ");
- display.println(lightTriggers);
- display.print("TO: ");
- if (lightTimeout < 0)
- display.println(0);
- else
- display.println(lightTimeout - now());
- break;
- default:
- // sprintf(syslogMessage, "type=info,func=displayRotate,msg=\"Showing Temp.\"");
- // sendUdpSyslog(syslogMessage);
- display.setCursor(0,0);
- display.print("Temp: ");
- display.println(globalTemp);
- display.print("Hum: ");
- display.print(globalHumidity);
- display.print(" %");
- currentDisplayValue = 0;
- break;
- }
- display.display();
- currentDisplayValue = currentDisplayValue + 1;
- }
- int displayOff() {
- // Clear the buffer.
- display.clearDisplay();
- display.display();
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // SETUP
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- void setup() {
- // Start up serial
- Serial.begin(9600);
- delay(10);
- // Init Lux sensor
- if(!tsl.begin())
- {
- Serial.print("No TSL2561 detected");
- while(1);
- }
- tsl.enableAutoRange(true);
- tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);
- // set humidity/temp pin
- pinMode(DHTPIN, INPUT);
- // set motion pin
- pinMode(PIRPIN, INPUT);
- // set motion LED signal pin and clear with default
- pinMode(LEDPIN, OUTPUT);
- digitalWrite(LEDPIN,1);
- ///////////////////////
- // Connect to WiFi network
- Serial.println();
- Serial.println();
- Serial.print("Connecting to ");
- Serial.println(ssid);
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- WiFi.hostname(ESP8266_HOSTNAME);
- // Open up port for NTP and Syslog Server Response
- Udp.begin(localPort);
- sendUdpSyslog("type=info,func=start,msg=\"WiFi connected\"");
- // Print the IP address
- Serial.print("Local IP Address = ");
- Serial.println(WiFi.localIP());
- // Get IP address for time server and set at NTP server
- sprintf(syslogMessage, "type=info,func=start,msg=\"Setting time server %s\"",ntpServerName);
- sendUdpSyslog(syslogMessage);
- WiFi.hostByName(ntpServerName, timeServerIP);
- IPAddress timeServer(timeServerIP); // time-a.timefreq.bldrdoc.gov
- sprintf(syslogMessage, "type=info,func=start,msg=\"Setting up NTP %s\"",ntpServerName);
- sendUdpSyslog(syslogMessage);
- Serial.print("Local port: ");
- Serial.println(Udp.localPort());
- Serial.println("waiting for sync");
- setSyncProvider(getNtpTime);
- setSyncInterval(3600);
- sendUdpSyslog("type=info,func=start,msg=\"esp8266-02-syslog started\"");
- ///////////////////////
- // INIT OLED
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 64x48)
- display.display();
- delay(2000);
- // Clear the buffer.
- display.clearDisplay();
- // text display tests
- displayOn();
- ///////////////////////
- // REST Client for Hue Hub Control
- client = RestClient("192.168.64.69");
- HTTP_response = "";
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // MAIN LOOP
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- int loopCounter = 0;
- void loop() {
- Serial.println("Starting Loop");
- if (timeStatus() != timeNotSet) {
- if (now() != prevDisplay) { //update the display only if time has changed
- prevDisplay = now();
- digitalClockDisplay();
- }
- }
- ///////////////////////
- // READ DHT
- float humidity = dht.readHumidity();
- if (humidity > 0) {
- dtostrf(humidity,2, 0, globalHumidity);
- }
- float temp = dht.readTemperature();
- if (temp > 0) {
- dtostrf(temp,2, 0, globalTemp);
- }
- ///////////////////////
- // READ PIR MOTION
- int PIR_value = digitalRead(PIRPIN);
- digitalWrite(LEDPIN,!PIR_value); // set onboard LED to value of PIR pin
- Serial.print("PIR_Value = ");
- Serial.println(PIR_value);
- Serial.print("PIR_PrevValue = ");
- Serial.println(PIR_PrevValue);
- if (PIR_value == 1 && PIR_PrevValue == 0) {
- Serial.println("Triggering lights");
- lightsOn();
- // turn on display only if timeout not set. If timeout set then the display is already on
- if (lightTimeout < 0) {
- displayOn();
- }
- }
- PIR_PrevValue = PIR_value;
- ///////////////////////
- // READ LUX
- /* Get a new sensor event */
- sensors_event_t event;
- tsl.getEvent(&event);
- ///////////////////////
- // READ AIR
- ///////////////////////
- // Loop counter to only put a syslog message out every 5 seconds
- loopCounter = loopCounter + 1;
- if (loopCounter > 5) {
- sprintf(syslogMessage, "type=metrics,func=loop,temp=%s,humidity=%s,pir=%d,lux=%d,triggers=%d,lightState=%d,lightLastOn=%02d:%02d,lightLastOff=%02d:%02d,timeoutSetTime=%02d:%02d,nowTime=%02d:%02d,msg=\"Sensor Values\"\"",globalTemp,globalHumidity,PIR_value,(int)event.light,lightTriggers,currentExpectedLightState,hour(lastOnTime), minute(lastOnTime),hour(lastOffTime), minute(lastOffTime),hour(lightTimeout), minute(lightTimeout), hour(), minute());
- sendUdpSyslog(syslogMessage);
- loopCounter = 0;
- }
- if (lightTimeout > 0) {
- displayRotate();
- }
- ///////////////////////
- // Check light timeouts
- if (lightTimeout > 0) {
- if (now() > lightTimeout) {
- sprintf(syslogMessage, "type=info,func=loop,action=timeout_triggered,timeoutSetTime=%02d:%02d,nowTime=%02d:%02d,msg=\"Timeout triggered\"\"",hour(lightTimeout), minute(lightTimeout), hour(), minute());
- sendUdpSyslog(syslogMessage);
- lightsOff();
- displayOff();
- }
- }
- Serial.println("Finished");
- Serial.println("-----------------");
- if (PIR_value > 0)
- {
- }
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement