/* Home Dynamic System v3 Desktop Control Panel Firmware Author: tobychui [Compile Options] Wemos D1 R2 & Mini CPU: 160Mhz IwIP: High Bandwidth v2 [Wiring Definations] D0 -> Button 4 D5 -> Button 3 D6 -> Button 2 D7 -> Button 1 [HMI Element Definations] page: home p0 -> background wallpaper (night: 0, day: 1) time -> current time ampm -> am / pm string date -> current date dow -> Date of Week, e.g. MON temp -> Current temp, max 2 digit humd -> Current humditiy, max 2 digit rain -> Current rainfall in mm, max 2 digit wicon -> Weather icon (large) 6: Sunny Day 7: Clear Night 8: Cloudy 9: Rainy 10: Cloudy Day 11: Heavy Rain 12: Thunder 13: Cloudy Night */ //Include libraries #include #include #include #include #include #include #include //WiFi Related WiFiManager wifiManager; //UART HMI SoftwareSerial HMISerial(D2, D1); // RX, TX bool debugMode = true; //Clock & NTP WiFiUDP UDPconn; NTPClient ntpClient(UDPconn, "pool.ntp.org"); const String weekDays[7] = {"Sun", "Mon", "Tues", "Wed", "Thu", "Fri", "Sat"}; const String months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; //Global Variables int currentPage = 0; //0 = home, 1 = forcast, 2 = iot bool buttonState[4] = {false, false, false, false}; //Current weather int currentTemp = 25; int currentHumd = 50; int currentRain = 0; bool currentIsRaining = false; //Schedulers void keyboardListenerCallback(); void datetimeUpdateCallback(); void todayWeatherUpdateCallback(); void weatherForcastCallback(); Task t_kb(50, TASK_FOREVER, &keyboardListenerCallback); Task t_dt(10000, TASK_FOREVER, &datetimeUpdateCallback); Task t_wt(3600000, TASK_FOREVER, &todayWeatherUpdateCallback); Task t_wf(3600000, TASK_FOREVER, &weatherForcastCallback); Scheduler runner; // the setup function runs once when you press reset or power the board void setup() { //Serial Serial.begin(9600); HMISerial.begin(9600); delay(100); sendCommand("page init"); sendCommand("t0.txt=\"Waiting WiFi\""); // Connect to Wi-Fi wifiManager.setClass("invert"); wifiManager.autoConnect("HomeDynamic Panel"); if (!debugMode) { wifiManager.setDebugOutput(false); } sendCommand("t0.txt=\"Setting up NTP conn\""); delay(1000); //Start NTP Client ntpClient.begin(); ntpClient.setTimeOffset(28800); // setup button pins pinMode(D7, INPUT); //1 pinMode(D6, INPUT); //2 pinMode(D5, INPUT); //3 pinMode(D0, INPUT); //4 sendCommand("t0.txt=\"Starting scheduler\""); // setup schedulers runner.init(); Serial.println("Initialized scheduler"); runner.addTask(t_kb); //Keyboard update task runner.addTask(t_dt); //Date-time update task runner.addTask(t_wt); //Weather update task runner.addTask(t_wf); //Weather forcast task //Enable all the backtground tasks delay(300); t_kb.enable(); delay(300); t_dt.enable(); delay(300); t_wt.enable(); delay(300); t_wf.enable(); //Switch over to homepage sendCommand("page home"); } // the loop function runs over and over again forever void loop() { runner.execute(); }