From 4755a38442dbb7b83009ffac9b410841260199bd Mon Sep 17 00:00:00 2001 From: Chrome Legion Date: Sun, 22 Apr 2018 22:31:12 -0700 Subject: [PATCH 1/9] Qrome - updated spelling on some items on the web forms --- marquee/marquee.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/marquee/marquee.ino b/marquee/marquee.ino index 8202049..b669cf8 100644 --- a/marquee/marquee.ino +++ b/marquee/marquee.ino @@ -100,9 +100,9 @@ const String CHANGE_FORM = "
%CITYNAME1%" "

Search for City ID

" " Use 24 Hour Clock (military time)

" - " Use Metric (Celcius)

" + " Use Metric (Celsius)

" " Display News Headlines

" - "Select News Srouce

" + "Select News Source

" " Display Advice

" "" "

" @@ -888,4 +888,4 @@ String decodeHtmlString(String msg) { decodedMsg.toUpperCase(); decodedMsg.trim(); return decodedMsg; -} +} From fcb54daf8d3eda8bdd15ccd958b3d6ad2684cbbd Mon Sep 17 00:00:00 2001 From: Qrome <32021227+Qrome@users.noreply.github.com> Date: Sun, 22 Apr 2018 22:39:17 -0700 Subject: [PATCH 2/9] Qrome - updated spelling issue. --- marquee/marquee.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/marquee/marquee.ino b/marquee/marquee.ino index 8202049..2bcf878 100644 --- a/marquee/marquee.ino +++ b/marquee/marquee.ino @@ -100,9 +100,9 @@ const String CHANGE_FORM = "%CITYNAME1%" "

Search for City ID

" " Use 24 Hour Clock (military time)

" - " Use Metric (Celcius)

" + " Use Metric (Celsius)

" " Display News Headlines

" - "Select News Srouce

" + "Select News Source

" " Display Advice

" "" "

" From 8d817991ef97e652097c4cef551d6d0596394809 Mon Sep 17 00:00:00 2001 From: Chrome Legion Date: Sun, 22 Apr 2018 22:47:17 -0700 Subject: [PATCH 3/9] Qrome - updated version number to 1.1 --- marquee/marquee.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/marquee/marquee.ino b/marquee/marquee.ino index b669cf8..1661a86 100644 --- a/marquee/marquee.ino +++ b/marquee/marquee.ino @@ -27,7 +27,7 @@ SOFTWARE. #include "Settings.h" -#define VERSION "1.0" +#define VERSION "1.1" #define HOSTNAME "ESP8266-" #define CONFIG "/conf.txt" From 3afae899b3f747de7f22b1c2ca8ded5899ac5dd1 Mon Sep 17 00:00:00 2001 From: yann Date: Wed, 25 Apr 2018 20:15:15 +0200 Subject: [PATCH 4/9] replace diacritic characters --- marquee/marquee.ino | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/marquee/marquee.ino b/marquee/marquee.ino index 8202049..9bbe3ab 100644 --- a/marquee/marquee.ino +++ b/marquee/marquee.ino @@ -827,7 +827,38 @@ void readCityIds() { fr.close(); } +// remove diacritic character +String diacriticCleaner(String message) +{ + String withDiacritic("ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÌÍÎÏìíîïÙÚÛÜùúûüÿÑñÇç"); + String withoutDiacritic("AAAAAAaaaaaaOOOOOOooooooEEEEeeeeIIIIiiiiUUUUuuuuyNnCc"); + String messageCourt; + int i=0,j=0,k=0,messageSize; + + messageSize=message.length(); + + for (i=0;i<=messageSize;i++) + { + for(j=0;j<=104;j=j+2) + { + if((message[i]==withDiacritic[j])&&(message[i+1]==withDiacritic[j+1])) + { + message[i]=withoutDiacritic[j/2]; + for(k=i+1;k Date: Thu, 26 Apr 2018 22:22:18 -0700 Subject: [PATCH 5/9] David - updated with new webservice code and OctoPrint --- marquee/OctoPrintClient.cpp | 67 ++++--- marquee/OctoPrintClient.h | 2 +- marquee/marquee.ino | 346 +++++++++++++++++------------------- 3 files changed, 206 insertions(+), 209 deletions(-) diff --git a/marquee/OctoPrintClient.cpp b/marquee/OctoPrintClient.cpp index de727e1..12757b7 100644 --- a/marquee/OctoPrintClient.cpp +++ b/marquee/OctoPrintClient.cpp @@ -35,6 +35,7 @@ void OctoPrintClient::updateOctoPrintClient(String ApiKey, String server, int po void OctoPrintClient::getPrinterJobResults() { WiFiClient printClient; + printClient.setTimeout(10000); String apiGetData = "GET /api/job HTTP/1.1"; Serial.println("Getting Octoprint Data"); @@ -46,7 +47,11 @@ void OctoPrintClient::getPrinterJobResults() { printClient.println("X-Api-Key: " + myApiKey); printClient.println("User-Agent: ArduinoWiFi/1.1"); printClient.println("Connection: close"); - printClient.println(); + if (printClient.println() == 0) { + Serial.println("OctoPrint Connection failed."); + printerData.state = ""; + return; + } } else { Serial.println("connection for OctoPrint data failed"); //error message if no client connect @@ -55,31 +60,34 @@ void OctoPrintClient::getPrinterJobResults() { return; } - while(printClient.connected() && !printClient.available()) delay(1); //waits for data - - Serial.println("Waiting for data..."); + // Check HTTP status + char status[32] = {0}; + printClient.readBytesUntil('\r', status, sizeof(status)); + if (strcmp(status, "HTTP/1.1 200 OK") != 0) { + Serial.print(F("Unexpected response: ")); + Serial.println(status); + printerData.state = ""; + return; + } - boolean isBody = false; - char c; - while (printClient.connected() || printClient.available()) { //connected or data available - c = printClient.read(); //gets byte from ethernet buffer - if (c == '{' || c == '[') { - isBody = true; - } - if (isBody) { - result = result + c; - } + // Skip HTTP headers + char endOfHeaders[] = "\r\n\r\n"; + if (!printClient.find(endOfHeaders)) { + Serial.println(F("Invalid response")); + printerData.state = ""; + return; } - - printClient.stop(); //stop client - Serial.println(result); - char jsonArray [result.length()+1]; - result.toCharArray(jsonArray,sizeof(jsonArray)); - jsonArray[result.length() + 1] = '\0'; - DynamicJsonBuffer json_buf; - JsonObject& root = json_buf.parseObject(jsonArray); + const size_t bufferSize = JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 2*JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(6) + 710; + DynamicJsonBuffer jsonBuffer(bufferSize); + // Parse JSON object + JsonObject& root = jsonBuffer.parseObject(printClient); + if (!root.success()) { + Serial.println(F("OctoPrint Data Parsing failed!")); + return; + } + printerData.averagePrintTime = (const char*)root["job"]["averagePrintTime"]; printerData.estimatedPrintTime = (const char*)root["job"]["estimatedPrintTime"]; printerData.fileName = (const char*)root["job"]["file"]["name"]; @@ -90,6 +98,17 @@ void OctoPrintClient::getPrinterJobResults() { printerData.progressPrintTime = (const char*)root["progress"]["printTime"]; printerData.progressPrintTimeLeft = (const char*)root["progress"]["printTimeLeft"]; printerData.state = (const char*)root["state"]; + + if (isPrinting()) { + Serial.println("Status: " + printerData.state + " " + printerData.fileName + "(" + printerData.progressCompletion + "%)"); + } else if (isOperational()) { + Serial.println("Status: " + printerData.state); + } else { + Serial.println("Printer Not Opperational"); + } + + + printClient.stop(); //stop client } String OctoPrintClient::getAveragePrintTime(){ @@ -146,6 +165,4 @@ boolean OctoPrintClient::isOperational() { operational = true; } return operational; -} - - +} diff --git a/marquee/OctoPrintClient.h b/marquee/OctoPrintClient.h index cf8ce34..84e66c8 100644 --- a/marquee/OctoPrintClient.h +++ b/marquee/OctoPrintClient.h @@ -68,4 +68,4 @@ class OctoPrintClient { boolean isPrinting(); boolean isOperational(); }; - + diff --git a/marquee/marquee.ino b/marquee/marquee.ino index cb3fb4b..f98ea06 100644 --- a/marquee/marquee.ino +++ b/marquee/marquee.ino @@ -84,9 +84,7 @@ OpenWeatherMapClient weatherClient(APIKEY, CityIDs, 1, IS_METRIC); OctoPrintClient printerClient(OctoPrintApiKey, OctoPrintServer, OctoPrintPort); int printerCount = 0; -WiFiServer server(WEBSERVER_PORT); -WiFiClient webClient; - +ESP8266WebServer server(WEBSERVER_PORT); const String WEB_ACTIONS = " Home" " Configure" @@ -94,7 +92,7 @@ const String WEB_ACTIONS = " Reset Settings" " Forget WiFi" - " About"; + " About"; const String CHANGE_FORM = "

City ID:

" "" @@ -221,7 +219,19 @@ void setup() { Serial.print(getWifiQuality()); Serial.println("%"); + if (MDNS.begin ("scroller")) { + Serial.println ("MDNS responder started"); + } + if (WEBSERVER_ENABLED) { + server.on("/", displayWeatherData); + server.on("/pull", handlePull); + server.on("/locations", handleLocations); + server.on("/systemreset", handleSystemReset); + server.on("/forgetwifi", handleForgetWifi); + server.on("/configure", handleConfigure); + server.on("/display", handleDisplay); + server.onNotFound(handleNotFound); // Start the server server.begin(); Serial.println("Server started"); @@ -300,138 +310,107 @@ void loop() { hourMinutes = timeClient.getHours() + ":" + timeClient.getMinutes(); } centerPrint(hourMinutes); + + server.handleClient(); +} - handleWebClient(); +void handlePull() { + timeOffsetFetched = false; + getWeatherData(); // this will force a data pull for new weather + displayWeatherData(); } -//*************************************** -// WEBCLIENT -//*************************************** -void handleWebClient() { - // Check if a client has connected - webClient = server.available(); - if (!webClient) { - return; - } - timeoutCount = 0; - while(!webClient.available()){ - delay(1); - timeoutCount++; - if (timeoutCount == TIMEOUT) { - Serial.println("Ping and No Connection..."); - webClient.stop(); - return; - } - } - - Serial.print("Remote IP: "); - Serial.println(webClient.remoteIP()); - - // Read the first line of the request - String request = webClient.readStringUntil('\r'); - Serial.println(request); - webClient.flush(); - - // Return the response ********************************************************************** - if (request.indexOf("/pull") != -1) { - timeOffsetFetched = false; - getWeatherData(); // this will force a data pull for new weather - displayWeatherData(); - } else if (request.indexOf("/locations") != -1) { - String lastCity = request.substring(request.lastIndexOf("city1=") + 6); - CityIDs[0] = lastCity.substring(0, lastCity.indexOf("&")).toInt(); - NEWS_ENABLED = (request.indexOf("displaynews=") > 0); - ADVICE_ENABLED = (request.indexOf("displayadvice=") > 0); - IS_24HOUR = (request.indexOf("is24hour=") > 0); - IS_METRIC = (request.indexOf("metric=") > 0); - NEWS_SOURCE = request.substring(request.lastIndexOf("newssource=") + 11, request.lastIndexOf("&marqueeMsg=")); - marqueeMessage = decodeHtmlString(request.substring(request.lastIndexOf("marqueeMsg=") + 11, request.lastIndexOf("&startTime="))); - timeDisplayTurnsOn = decodeHtmlString(request.substring(request.lastIndexOf("startTime=") + 10, request.lastIndexOf("&endTime="))); - timeDisplayTurnsOff = decodeHtmlString(request.substring(request.lastIndexOf("endTime=") + 8, request.lastIndexOf("&ledintensity="))); - displayIntensity = request.substring(request.lastIndexOf("ledintensity=") + 13, request.lastIndexOf("&refresh=")).toInt(); - minutesBetweenDataRefresh = request.substring(request.lastIndexOf("refresh=") + 8, request.indexOf(" HTTP/")).toInt(); - weatherClient.setMetric(IS_METRIC); - matrix.fillScreen(LOW); // show black - writeCityIds(); - getWeatherData(); // this will force a data pull for new weather - redirectHome(); - } else if (request.indexOf("/systemreset") != -1) { - Serial.println("Reset System Configuration"); - if (SPIFFS.remove(CONFIG)) { - redirectHome(); - ESP.restart(); - } - } else if (request.indexOf("/forgetwifi") != -1) { - //WiFiManager - //Local intialization. Once its business is done, there is no need to keep it around +void handleLocations() { + CityIDs[0] = server.arg("city1").toInt(); + NEWS_ENABLED = server.hasArg("displaynews"); + ADVICE_ENABLED = server.hasArg("displayadvice"); + IS_24HOUR = server.hasArg("is24hour"); + IS_METRIC = server.hasArg("metric"); + NEWS_SOURCE = server.arg("newssource"); + marqueeMessage = decodeHtmlString(server.arg("marqueeMsg")); + timeDisplayTurnsOn = decodeHtmlString(server.arg("startTime")); + timeDisplayTurnsOff = decodeHtmlString(server.arg("endTime")); + displayIntensity = server.arg("ledintensity").toInt(); + minutesBetweenDataRefresh = server.arg("refresh").toInt(); + weatherClient.setMetric(IS_METRIC); + matrix.fillScreen(LOW); // show black + writeCityIds(); + getWeatherData(); // this will force a data pull for new weather + redirectHome(); +} + +void handleSystemReset() { + Serial.println("Reset System Configuration"); + if (SPIFFS.remove(CONFIG)) { redirectHome(); - WiFiManager wifiManager; - wifiManager.resetSettings(); ESP.restart(); - } else if (request.indexOf("/configure") != -1) { - String form = String(CHANGE_FORM); - for (int inx = 0; inx < 1; inx++) { - String cityName = ""; - if (CityIDs[inx] > 0) { - cityName = weatherClient.getCity(inx) + ", " + weatherClient.getCountry(inx); - } else { - cityName = "Available"; - } - form.replace(String("%CITYNAME" + String(inx +1) + "%"), cityName); - form.replace(String("%CITY" + String(inx +1) + "%"), String(CityIDs[inx])); - } - String isNewsDisplayedChecked = ""; - if (NEWS_ENABLED) { - isNewsDisplayedChecked = "checked='checked'"; - } - form.replace("%NEWSCHECKED%", isNewsDisplayedChecked); - String isAdviceDisplayedChecked = ""; - if (ADVICE_ENABLED) { - isAdviceDisplayedChecked = "checked='checked'"; - } - form.replace("%ADVICECHECKED%", isAdviceDisplayedChecked); - String is24hourChecked = ""; - if (IS_24HOUR) { - is24hourChecked = "checked='checked'"; - } - form.replace("%IS_24HOUR_CHECKED%", is24hourChecked); - String checked = ""; - if (IS_METRIC) { - checked = "checked='checked'"; - } - form.replace("%CHECKED%", checked); - form.replace("%MSG%", marqueeMessage); - form.replace("%STARTTIME%", timeDisplayTurnsOn); - form.replace("%ENDTIME%", timeDisplayTurnsOff); - String options = ""; - options.replace(">"+String(minutesBetweenDataRefresh)+"<", " selected>"+String(minutesBetweenDataRefresh)+"<"); - form.replace("%OPTIONS%", options); - String newsOptions = String(NEWS_OPTIONS); - newsOptions.replace(">"+String(NEWS_SOURCE)+"<", " selected>"+String(NEWS_SOURCE)+"<"); - form.replace("%NEWSOPTIONS%", newsOptions); - String ledOptions = ""; - ledOptions.replace(">"+String(displayIntensity)+"<", " selected>"+String(displayIntensity)+"<"); - form.replace("%INTENSITYOPTIONS%", ledOptions); - displayMessage(form); - } else if (request.indexOf("/display") != -1) { - enableDisplay(!displayOn); - String state = "OFF"; - if (displayOn) { - state = "ON"; + } +} + +void handleForgetWifi() { + //WiFiManager + //Local intialization. Once its business is done, there is no need to keep it around + redirectHome(); + WiFiManager wifiManager; + wifiManager.resetSettings(); + ESP.restart(); +} + +void handleConfigure() { + String form = String(CHANGE_FORM); + for (int inx = 0; inx < 1; inx++) { + String cityName = ""; + if (CityIDs[inx] > 0) { + cityName = weatherClient.getCity(inx) + ", " + weatherClient.getCountry(inx); + } else { + cityName = "Available"; } - displayMessage("Display is now " + state); - } else { - //*********************************************** - displayWeatherData(); - //*********************************************** + form.replace(String("%CITYNAME" + String(inx +1) + "%"), cityName); + form.replace(String("%CITY" + String(inx +1) + "%"), String(CityIDs[inx])); } - // END Return the response ********************************************************************** - - delay(1); - Serial.println("Client disconnected"); - Serial.println(); - webClient.stop(); + String isNewsDisplayedChecked = ""; + if (NEWS_ENABLED) { + isNewsDisplayedChecked = "checked='checked'"; + } + form.replace("%NEWSCHECKED%", isNewsDisplayedChecked); + String isAdviceDisplayedChecked = ""; + if (ADVICE_ENABLED) { + isAdviceDisplayedChecked = "checked='checked'"; + } + form.replace("%ADVICECHECKED%", isAdviceDisplayedChecked); + String is24hourChecked = ""; + if (IS_24HOUR) { + is24hourChecked = "checked='checked'"; + } + form.replace("%IS_24HOUR_CHECKED%", is24hourChecked); + String checked = ""; + if (IS_METRIC) { + checked = "checked='checked'"; + } + form.replace("%CHECKED%", checked); + form.replace("%MSG%", marqueeMessage); + form.replace("%STARTTIME%", timeDisplayTurnsOn); + form.replace("%ENDTIME%", timeDisplayTurnsOff); + String options = ""; + options.replace(">"+String(minutesBetweenDataRefresh)+"<", " selected>"+String(minutesBetweenDataRefresh)+"<"); + form.replace("%OPTIONS%", options); + String newsOptions = String(NEWS_OPTIONS); + newsOptions.replace(">"+String(NEWS_SOURCE)+"<", " selected>"+String(NEWS_SOURCE)+"<"); + form.replace("%NEWSOPTIONS%", newsOptions); + String ledOptions = ""; + ledOptions.replace(">"+String(displayIntensity)+"<", " selected>"+String(displayIntensity)+"<"); + form.replace("%INTENSITYOPTIONS%", ledOptions); + displayMessage(form); +} + +void handleDisplay() { + enableDisplay(!displayOn); + String state = "OFF"; + if (displayOn) { + state = "ON"; + } + displayMessage("Display is now " + state); } void getWeatherData() //client function to send/receive GET request data. @@ -487,29 +466,34 @@ void getWeatherData() //client function to send/receive GET request data. } void displayMessage(String message) { - String html = ""; + digitalWrite(externalLight, LOW); - displayHeader(); + server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); + server.sendHeader("Pragma", "no-cache"); + server.sendHeader("Expires", "-1"); + server.setContentLength(CONTENT_LENGTH_UNKNOWN); + server.send(200, "text/html", ""); + server.sendContent(String(getHeader())); + server.sendContent(String(message)); + server.sendContent(String(getFooter())); + server.client().stop(); - html += message; - - webClient.print(html); - displayFooter(); + digitalWrite(externalLight, HIGH); } void redirectHome() { - // Send them back to the Root Directory - webClient.println("HTTP/1.1 302 Found"); - webClient.println("Location: /"); + // Send them back to the Root Directory + server.sendHeader("Location", String("/"), true); + server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); + server.sendHeader("Pragma", "no-cache"); + server.sendHeader("Expires", "-1"); + server.send(302, "text/plain", ""); + server.client().stop(); } -void displayHeader() { - digitalWrite(externalLight, LOW); +String getHeader() { String menu = String(WEB_ACTIONS); menu.replace("%TOGGLEDISPLAY%", (displayOn) ? " Turn Display OFF" : " Turn Display ON"); - webClient.println("HTTP/1.1 200 OK"); - webClient.println("Content-Type: text/html"); - webClient.println(""); // do not forget this one String html = ""; html += ""; html += ""; @@ -529,10 +513,10 @@ void displayHeader() { html += "function openSidebar(){document.getElementById('mySidebar').style.display='block'}function closeSidebar(){document.getElementById('mySidebar').style.display='none'}closeSidebar();"; html += ""; html += "
"; - webClient.println(html); + return html; } -void displayFooter() { +String getFooter() { int8_t rssi = getWifiQuality(); Serial.print("Signal Strength (RSSI): "); Serial.print(rssi); @@ -546,14 +530,20 @@ void displayFooter() { html += String(rssi) + "%"; html += ""; html += ""; - webClient.println(html); - digitalWrite(externalLight, HIGH); + return html; } void displayWeatherData() { + digitalWrite(externalLight, LOW); String html = ""; - displayHeader(); + server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); + server.sendHeader("Pragma", "no-cache"); + server.sendHeader("Expires", "-1"); + server.setContentLength(CONTENT_LENGTH_UNKNOWN); + server.send(200, "text/html", ""); + server.sendContent(String(getHeader())); + for (int inx = 0; inx < 1; inx++) { if (weatherClient.getTemp(inx) == "") { break; // no more data @@ -586,7 +576,7 @@ void displayWeatherData() { html += " Map It!
"; html += "


"; - webClient.print(html); // spit out what we got + server.sendContent(String(html)); // spit out what we got html = ""; // fresh start } @@ -595,7 +585,7 @@ void displayWeatherData() { for (int inx = 0; inx < 10; inx++) { html += ""; html += "
" + newsClient.getDescription(inx) + "

"; - webClient.print(html); + server.sendContent(String(html)); html = ""; } } @@ -604,11 +594,13 @@ void displayWeatherData() { html = "

Advice Slip

"; html += "
Current Advice:
"; html += "
" + adviceClient.getAdvice() + "

"; - webClient.print(html); + server.sendContent(String(html)); html = ""; } - displayFooter(); + server.sendContent(String(getFooter())); + server.client().stop(); + digitalWrite(externalLight, HIGH); } float getTimeOffset(int index) { @@ -624,6 +616,25 @@ float getTimeOffset(int index) { return UtcOffset; } +void handleNotFound() { + digitalWrite(externalLight, LOW); + String message = "File Not Found\n\n"; + message += "URI: "; + message += server.uri(); + message += "\nMethod: "; + message += ( server.method() == HTTP_GET ) ? "GET" : "POST"; + message += "\nArguments: "; + message += server.args(); + message += "\n"; + + for ( uint8_t i = 0; i < server.args(); i++ ) { + message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n"; + } + + server.send ( 404, "text/plain", message ); + digitalWrite(externalLight, HIGH); +} + void configModeCallback (WiFiManager *myWiFiManager) { Serial.println("Entered config mode"); Serial.println(WiFi.softAPIP()); @@ -827,41 +838,10 @@ void readCityIds() { fr.close(); } -// remove diacritic character -String diacriticCleaner(String message) -{ - String withDiacritic("ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÌÍÎÏìíîïÙÚÛÜùúûüÿÑñÇç"); - String withoutDiacritic("AAAAAAaaaaaaOOOOOOooooooEEEEeeeeIIIIiiiiUUUUuuuuyNnCc"); - String messageCourt; - int i=0,j=0,k=0,messageSize; - - messageSize=message.length(); - - for (i=0;i<=messageSize;i++) - { - for(j=0;j<=104;j=j+2) - { - if((message[i]==withDiacritic[j])&&(message[i+1]==withDiacritic[j+1])) - { - message[i]=withoutDiacritic[j/2]; - for(k=i+1;k Date: Thu, 26 Apr 2018 22:37:50 -0700 Subject: [PATCH 6/9] Added the header for mDNS --- marquee/Settings.h | 1 + 1 file changed, 1 insertion(+) diff --git a/marquee/Settings.h b/marquee/Settings.h index 953239a..b873a4f 100644 --- a/marquee/Settings.h +++ b/marquee/Settings.h @@ -31,6 +31,7 @@ SOFTWARE. #include #include #include +#include #include #include "FS.h" #include From ffaa4f45442264b6b9b039569e74949aa78c6c99 Mon Sep 17 00:00:00 2001 From: Chrome Legion Date: Thu, 26 Apr 2018 23:56:23 -0700 Subject: [PATCH 7/9] David - added OctoPrint to the Configuration Web Form --- marquee/marquee.ino | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/marquee/marquee.ino b/marquee/marquee.ino index f98ea06..fe67ad6 100644 --- a/marquee/marquee.ino +++ b/marquee/marquee.ino @@ -107,6 +107,10 @@ const String CHANGE_FORM = "

" "Select Display Brightness

" "Refresh Data (minutes)

" + " Show OctoPrint Status

" + "" + "" + "" "

" ""; @@ -333,6 +337,10 @@ void handleLocations() { timeDisplayTurnsOff = decodeHtmlString(server.arg("endTime")); displayIntensity = server.arg("ledintensity").toInt(); minutesBetweenDataRefresh = server.arg("refresh").toInt(); + OCTOPRINT_ENABLED = server.hasArg("displayoctoprint"); + OctoPrintApiKey = server.arg("octoPrintApiKey"); + OctoPrintServer = server.arg("octoPrintAddress"); + OctoPrintPort = server.arg("octoPrintPort").toInt(); weatherClient.setMetric(IS_METRIC); matrix.fillScreen(LOW); // show black writeCityIds(); @@ -401,7 +409,15 @@ void handleConfigure() { String ledOptions = ""; ledOptions.replace(">"+String(displayIntensity)+"<", " selected>"+String(displayIntensity)+"<"); form.replace("%INTENSITYOPTIONS%", ledOptions); - displayMessage(form); + String isOctoPrintDisplayedChecked = ""; + if (OCTOPRINT_ENABLED) { + isOctoPrintDisplayedChecked = "checked='checked'"; + } + form.replace("%OCTOCHECKED%", isOctoPrintDisplayedChecked); + form.replace("%OCTOKEY%", OctoPrintApiKey); + form.replace("%OCTOADDRESS%", OctoPrintServer); + form.replace("%OCTOPORT%", String(OctoPrintPort)); + displayMessage(String(form)); } void handleDisplay() { @@ -767,6 +783,10 @@ String writeCityIds() { f.println("is24hour=" + String(IS_24HOUR)); f.println("isMetric=" + String(IS_METRIC)); f.println("refreshRate=" + String(minutesBetweenDataRefresh)); + f.println("isOctoPrint=" + String(OCTOPRINT_ENABLED)); + f.println("octoKey=" + OctoPrintApiKey); + f.println("octoServer=" + OctoPrintServer); + f.println("octoPort=" + String(OctoPrintPort)); } f.close(); readCityIds(); @@ -830,12 +850,33 @@ void readCityIds() { displayIntensity = line.substring(line.lastIndexOf("ledIntensity=") + 13).toInt(); Serial.println("displayIntensity=" + String(displayIntensity)); } + if (line.indexOf("isOctoPrint=") >= 0) { + OCTOPRINT_ENABLED = line.substring(line.lastIndexOf("isOctoPrint=") + 12).toInt(); + Serial.println("OCTOPRINT_ENABLED=" + String(OCTOPRINT_ENABLED)); + } + if (line.indexOf("octoKey=") >= 0) { + OctoPrintApiKey = line.substring(line.lastIndexOf("octoKey=") + 8); + OctoPrintApiKey.trim(); + Serial.println("OctoPrintApiKey=" + OctoPrintApiKey); + } + if (line.indexOf("octoServer=") >= 0) { + OctoPrintServer = line.substring(line.lastIndexOf("octoServer=") + 11); + OctoPrintServer.trim(); + Serial.println("OctoPrintServer=" + OctoPrintServer); + } + if (line.indexOf("octoPort=") >= 0) { + OctoPrintPort = line.substring(line.lastIndexOf("octoPort=") + 9).toInt(); + Serial.println("OctoPrintPort=" + String(OctoPrintPort)); + } } + fr.close(); matrix.setIntensity(displayIntensity); newsClient.updateNewsSource(NEWS_SOURCE); weatherClient.setMetric(IS_METRIC); weatherClient.updateCityIdList(CityIDs, 1); - fr.close(); + if (OCTOPRINT_ENABLED) { + printerClient.getPrinterJobResults(); + } } void scrollMessage(String msg) { From c81b78c4f0d17fbbf6e9d9455f5378b48cc1d0bb Mon Sep 17 00:00:00 2001 From: Chrome Legion Date: Fri, 27 Apr 2018 01:23:22 -0700 Subject: [PATCH 8/9] David - added support for OTA updating --- marquee/marquee.ino | 47 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/marquee/marquee.ino b/marquee/marquee.ino index fe67ad6..66373d9 100644 --- a/marquee/marquee.ino +++ b/marquee/marquee.ino @@ -223,10 +223,25 @@ void setup() { Serial.print(getWifiQuality()); Serial.println("%"); - if (MDNS.begin ("scroller")) { - Serial.println ("MDNS responder started"); - } - + ArduinoOTA.onStart([]() { + Serial.println("Start"); + }); + ArduinoOTA.onEnd([]() { + Serial.println("\nEnd"); + }); + ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { + Serial.printf("Progress: %u%%\r", (progress / (total / 100))); + }); + ArduinoOTA.onError([](ota_error_t error) { + Serial.printf("Error[%u]: ", error); + if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); + else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); + else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed"); + else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); + else if (error == OTA_END_ERROR) Serial.println("End Failed"); + }); + ArduinoOTA.begin(); + if (WEBSERVER_ENABLED) { server.on("/", displayWeatherData); server.on("/pull", handlePull); @@ -316,6 +331,7 @@ void loop() { centerPrint(hourMinutes); server.handleClient(); + ArduinoOTA.handle(); } @@ -596,6 +612,20 @@ void displayWeatherData() { html = ""; // fresh start } + if (OCTOPRINT_ENABLED) { + html = "
OctoPrint Status: "; + if (printerClient.isPrinting()) { + html += printerClient.getState() + " " + printerClient.getFileName() + " (" + printerClient.getProgressCompletion() + "%)"; + } else if (printerClient.isOperational()) { + html += printerClient.getState(); + } else { + html += "Not Opperational"; + } + html += "


"; + server.sendContent(String(html)); + html = ""; + } + if (NEWS_ENABLED) { html = "

News (" + NEWS_SOURCE + ")

"; for (int inx = 0; inx < 10; inx++) { @@ -608,10 +638,10 @@ void displayWeatherData() { if (ADVICE_ENABLED) { html = "

Advice Slip

"; - html += "
Current Advice:
"; - html += "
" + adviceClient.getAdvice() + "

"; - server.sendContent(String(html)); - html = ""; + html += "
Current Advice:
"; + html += "
" + adviceClient.getAdvice() + "

"; + server.sendContent(String(html)); + html = ""; } server.sendContent(String(getFooter())); @@ -883,6 +913,7 @@ void scrollMessage(String msg) { msg += " "; // add a space at the end for ( int i = 0 ; i < width * msg.length() + matrix.width() - 1 - spacer; i++ ) { server.handleClient(); + ArduinoOTA.handle(); if (refresh==1) i=0; refresh=0; matrix.fillScreen(LOW); From 1daf800e941a24adc5dcec3731f22f31cfd1a859 Mon Sep 17 00:00:00 2001 From: Qrome <32021227+Qrome@users.noreply.github.com> Date: Fri, 27 Apr 2018 01:25:46 -0700 Subject: [PATCH 9/9] Added includes for OTA --- marquee/Settings.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/marquee/Settings.h b/marquee/Settings.h index 953239a..0d3c819 100644 --- a/marquee/Settings.h +++ b/marquee/Settings.h @@ -32,6 +32,8 @@ SOFTWARE. #include #include #include +#include +#include #include "FS.h" #include #include