Add files via upload
parent
bd8422b228
commit
3ac8d74799
|
|
@ -45,7 +45,6 @@ SOFTWARE.
|
|||
#include <ArduinoOTA.h>
|
||||
#include <ESP8266HTTPUpdateServer.h>
|
||||
#include "TimeClient.h"
|
||||
#include "RepetierClient.h"
|
||||
#include "OctoPrintClient.h"
|
||||
#include "OpenWeatherMapClient.h"
|
||||
#include "WeatherStationFonts.h"
|
||||
|
|
@ -58,20 +57,19 @@ SOFTWARE.
|
|||
// Start Settings
|
||||
//******************************
|
||||
|
||||
// OctoPrint / Repetier Monitoring -- Monitor your 3D OctoPrint or Repetier Server
|
||||
//#define USE_REPETIER_CLIENT // Uncomment this line to use the Repetier Printer Server -- OctoPrint is used by default and is most common
|
||||
String PrinterApiKey = ""; // ApiKey from your User Account on OctoPrint / Repetier
|
||||
String PrinterHostName = "octopi";// Default 'octopi' -- or hostname if different (optional if your IP changes)
|
||||
String PrinterServer = ""; // IP or Address of your OctoPrint / Repetier Server (DO NOT include http://)
|
||||
int PrinterPort = 80; // the port you are running your OctoPrint / Repetier server on (usually 80);
|
||||
String PrinterAuthUser = ""; // only used if you have haproxy or basic athentintication turned on (not default)
|
||||
String PrinterAuthPass = ""; // only used with haproxy or basic auth (only needed if you must authenticate)
|
||||
// OctoPrint Monitoring -- Monitor your 3D printer OctoPrint Server
|
||||
String OctoPrintApiKey = "ABCDEF1234"; // ApiKey from your User Account on OctoPrint
|
||||
String OctoPrintHostName = "3D Printer";// Default 'octopi' -- or hostname if different (optional if your IP changes)
|
||||
String OctoPrintServer = "192.168.0.10"; // IP or Address of your OctoPrint Server (DO NOT include http://)
|
||||
int OctoPrintPort = 80; // the port you are running your OctoPrint server on (usually 80);
|
||||
String OctoAuthUser = ""; // only used if you have haproxy or basic athentintication turned on (not default)
|
||||
String OctoAuthPass = ""; // only used with haproxy or basic auth (only needed if you must authenticate)
|
||||
|
||||
// Weather Configuration
|
||||
boolean DISPLAYWEATHER = true; // true = show weather when not printing / false = no weather
|
||||
String WeatherApiKey = ""; // Your API Key from http://openweathermap.org/
|
||||
String WeatherApiKey = "ABCDEF1234"; // Your API Key from http://openweathermap.org/
|
||||
// Default City Location (use http://openweathermap.org/find to find city ID)
|
||||
int CityIDs[] = { 5304391 }; //Only USE ONE for weather marquee
|
||||
int CityIDs[] = {4499612}; //Only USE ONE for weather marquee
|
||||
boolean IS_METRIC = false; // false = Imperial and true = Metric
|
||||
// Languages: ar, bg, ca, cz, de, el, en, fa, fi, fr, gl, hr, hu, it, ja, kr, la, lt, mk, nl, pl, pt, ro, ru, se, sk, sl, es, tr, ua, vi, zh_cn, zh_tw
|
||||
String WeatherLanguage = "en"; //Default (en) English
|
||||
|
|
@ -80,25 +78,27 @@ String WeatherLanguage = "en"; //Default (en) English
|
|||
const int WEBSERVER_PORT = 80; // The port you can access this device on over HTTP
|
||||
const boolean WEBSERVER_ENABLED = true; // Device will provide a web interface via http://[ip]:[port]/
|
||||
boolean IS_BASIC_AUTH = true; // true = require athentication to change configuration settings / false = no auth
|
||||
char* www_username = "admin"; // User account for the Web Interface
|
||||
char* www_password = "password"; // Password for the Web Interface
|
||||
char* www_username = "user"; // User account for the Web Interface
|
||||
char* www_password = "P@ssW0rd123"; // Password for the Web Interface
|
||||
|
||||
// Date and Time
|
||||
float UtcOffset = -7; // Hour offset from GMT for your timezone
|
||||
boolean IS_24HOUR = false; // 23:00 millitary 24 hour clock
|
||||
float UtcOffset = -4; // Hour offset from GMT for your timezone
|
||||
boolean IS_24HOUR = true; // 23:00 millitary 24 hour clock
|
||||
int minutesBetweenDataRefresh = 15;
|
||||
boolean DISPLAYCLOCK = true; // true = Show Clock when not printing / false = turn off display when not printing
|
||||
|
||||
// Display Settings
|
||||
const int I2C_DISPLAY_ADDRESS = 0x3c; // I2C Address of your Display (usually 0x3c or 0x3d)
|
||||
const int SDA_PIN = D2;
|
||||
const int SCL_PIN = D5; // original code D5 -- Monitor Easy Board use D1
|
||||
const int SCL_PIN = D3;
|
||||
boolean INVERT_DISPLAY = false; // true = pins at top | false = pins at the bottom
|
||||
//#define DISPLAY_SH1106 // Uncomment this line to use the SH1106 display -- SSD1306 is used by default and is most common
|
||||
#define DISPLAY_SH1106 // Uncomment this line to use the SH1106 display -- SSD1306 is used by default and is most common
|
||||
|
||||
// LED Settings
|
||||
const int externalLight = LED_BUILTIN; // LED will always flash on bootup or Wifi Errors
|
||||
boolean USE_FLASH = true; // true = System LED will Flash on Service Calls; false = disabled LED flashing
|
||||
const int externalLight = D1; // Set to unused pin, like D1, to disable use of built-in LED (LED_BUILTIN)
|
||||
|
||||
//Light Dependant Resistor (LDR) Port
|
||||
const int ldrPin = A0;
|
||||
|
||||
// PSU Control
|
||||
boolean HAS_PSU = false; // Set to true if https://github.com/kantlivelong/OctoPrint-PSUControl/ in use
|
||||
|
|
|
|||
|
|
@ -1,38 +1,39 @@
|
|||
#include <ArduinoOTA.h>
|
||||
|
||||
/** The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 David Payne
|
||||
Copyright (c) 2018 David Payne
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
// Additional Contributions:
|
||||
/* 15 Jan 2019 : Owen Carter : Add psucontrol option and processing */
|
||||
|
||||
/**********************************************
|
||||
* Edit Settings.h for personalization
|
||||
***********************************************/
|
||||
/**********************************************
|
||||
Edit Settings.h for personalization
|
||||
***********************************************/
|
||||
|
||||
#include "Settings.h"
|
||||
|
||||
#define VERSION "3.0"
|
||||
#define VERSION "2.5"
|
||||
|
||||
#define HOSTNAME "PrintMon-"
|
||||
#define HOSTNAME "OctMon-"
|
||||
#define CONFIG "/conf.txt"
|
||||
|
||||
/* Useful Constants */
|
||||
|
|
@ -47,11 +48,17 @@ SOFTWARE.
|
|||
// Initialize the oled display for I2C_DISPLAY_ADDRESS
|
||||
// SDA_PIN and SCL_PIN
|
||||
#if defined(DISPLAY_SH1106)
|
||||
SH1106Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SCL_PIN);
|
||||
SH1106Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SCL_PIN);
|
||||
#else
|
||||
SSD1306Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SCL_PIN); // this is the default
|
||||
SSD1306Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SCL_PIN); // this is the default
|
||||
#endif
|
||||
|
||||
#include <WiFiUdp.h> //for UDP
|
||||
int ledstat;
|
||||
unsigned int localPort = 2000; // local port to listen for UDP packets
|
||||
IPAddress SendIP(192, 168, 0, 255); //UDP Broadcast IP data sent to all devicess on same network
|
||||
WiFiUDP udp;
|
||||
char packetBuffer[9]; //Where we get the UDP data
|
||||
OLEDDisplayUi ui( &display );
|
||||
|
||||
void drawProgress(OLEDDisplay *display, int percentage, String label);
|
||||
|
|
@ -84,12 +91,11 @@ String lastSecond = "xx";
|
|||
String lastReportStatus = "";
|
||||
boolean displayOn = true;
|
||||
|
||||
// Printer Client
|
||||
#if defined(USE_REPETIER_CLIENT)
|
||||
RepetierClient printerClient(PrinterApiKey, PrinterServer, PrinterPort, PrinterAuthUser, PrinterAuthPass, HAS_PSU);
|
||||
#else
|
||||
OctoPrintClient printerClient(PrinterApiKey, PrinterServer, PrinterPort, PrinterAuthUser, PrinterAuthPass, HAS_PSU);
|
||||
#endif
|
||||
//LDR
|
||||
int ldrStatus =0;
|
||||
|
||||
// OctoPrint Client
|
||||
OctoPrintClient printerClient(OctoPrintApiKey, OctoPrintServer, OctoPrintPort, OctoAuthUser, OctoAuthPass, HAS_PSU);
|
||||
int printerCount = 0;
|
||||
|
||||
// Weather Client
|
||||
|
|
@ -102,7 +108,7 @@ int8_t getWifiQuality();
|
|||
ESP8266WebServer server(WEBSERVER_PORT);
|
||||
ESP8266HTTPUpdateServer serverUpdater;
|
||||
|
||||
static const char WEB_ACTIONS[] PROGMEM = "<a class='w3-bar-item w3-button' href='/'><i class='fa fa-home'></i> Home</a>"
|
||||
String WEB_ACTIONS = "<a class='w3-bar-item w3-button' href='/'><i class='fa fa-home'></i> Home</a>"
|
||||
"<a class='w3-bar-item w3-button' href='/configure'><i class='fa fa-cog'></i> Configure</a>"
|
||||
"<a class='w3-bar-item w3-button' href='/configureweather'><i class='fa fa-cloud'></i> Weather</a>"
|
||||
"<a class='w3-bar-item w3-button' href='/systemreset' onclick='return confirm(\"Do you want to reset to default settings?\")'><i class='fa fa-undo'></i> Reset Settings</a>"
|
||||
|
|
@ -110,34 +116,39 @@ static const char WEB_ACTIONS[] PROGMEM = "<a class='w3-bar-item w3-button' hre
|
|||
"<a class='w3-bar-item w3-button' href='/update'><i class='fa fa-wrench'></i> Firmware Update</a>"
|
||||
"<a class='w3-bar-item w3-button' href='https://github.com/Qrome' target='_blank'><i class='fa fa-question-circle'></i> About</a>";
|
||||
|
||||
String CHANGE_FORM = ""; // moved to config to make it dynamic
|
||||
|
||||
static const char CLOCK_FORM[] PROGMEM = "<hr><p><input name='isClockEnabled' class='w3-check w3-margin-top' type='checkbox' %IS_CLOCK_CHECKED%> Display Clock when printer is off</p>"
|
||||
String CHANGE_FORM = "<form class='w3-container' action='/updateconfig' method='get'><h2>Station Config:</h2>"
|
||||
"<p><label>OctoPrint API Key (get from your server)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='octoPrintApiKey' value='%OCTOKEY%' maxlength='60'></p>"
|
||||
"<p><label>OctoPrint Host Name (usually octopi)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='octoPrintHostName' value='%OCTOHOST%' maxlength='60'></p>"
|
||||
"<p><label>OctoPrint Address (do not include http://)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='octoPrintAddress' value='%OCTOADDRESS%' maxlength='60'></p>"
|
||||
"<p><label>OctoPrint Port</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='octoPrintPort' value='%OCTOPORT%' maxlength='5' onkeypress='return isNumberKey(event)'></p>"
|
||||
"<p><label>OctoPrint User (only needed if you have haproxy or basic auth turned on)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='octoUser' value='%OCTOUSER%' maxlength='30'></p>"
|
||||
"<p><label>OctoPrint Password </label><input class='w3-input w3-border w3-margin-bottom' type='password' name='octoPass' value='%OCTOPASS%'></p><hr>"
|
||||
"<p><input name='isClockEnabled' class='w3-check w3-margin-top' type='checkbox' %IS_CLOCK_CHECKED%> Display Clock when printer is off</p>"
|
||||
"<p><input name='is24hour' class='w3-check w3-margin-top' type='checkbox' %IS_24HOUR_CHECKED%> Use 24 Hour Clock (military time)</p>"
|
||||
"<p><input name='invDisp' class='w3-check w3-margin-top' type='checkbox' %IS_INVDISP_CHECKED%> Flip display orientation</p>"
|
||||
"<p><input name='useFlash' class='w3-check w3-margin-top' type='checkbox' %USEFLASH%> Flash System LED on Service Calls</p>"
|
||||
"<p><input name='hasPSU' class='w3-check w3-margin-top' type='checkbox' %HAS_PSU_CHECKED%> Use OctoPrint PSU control plugin for clock/blank</p>"
|
||||
"<p>Clock Sync / Weather Refresh (minutes) <select class='w3-option w3-padding' name='refresh'>%OPTIONS%</select></p>";
|
||||
|
||||
static const char THEME_FORM[] PROGMEM = "<p>Theme Color <select class='w3-option w3-padding' name='theme'>%THEME_OPTIONS%</select></p>"
|
||||
String THEME_FORM = "<p>Theme Color <select class='w3-option w3-padding' name='theme'>%THEME_OPTIONS%</select></p>"
|
||||
"<p><label>UTC Time Offset</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='utcoffset' value='%UTCOFFSET%' maxlength='12'></p><hr>"
|
||||
"<p><input name='isBasicAuth' class='w3-check w3-margin-top' type='checkbox' %IS_BASICAUTH_CHECKED%> Use Security Credentials for Configuration Changes</p>"
|
||||
"<p><label>User ID (for this interface)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='userid' value='%USERID%' maxlength='20'></p>"
|
||||
"<p><label>Password </label><input class='w3-input w3-border w3-margin-bottom' type='password' name='stationpassword' value='%STATIONPASSWORD%'></p>"
|
||||
"<button class='w3-button w3-block w3-grey w3-section w3-padding' type='submit'>Save</button></form>";
|
||||
|
||||
static const char WEATHER_FORM[] PROGMEM = "<form class='w3-container' action='/updateweatherconfig' method='get'><h2>Weather Config:</h2>"
|
||||
String WEATHER_FORM = "<form class='w3-container' action='/updateweatherconfig' method='get'><h2>Weather Config:</h2>"
|
||||
"<p><input name='isWeatherEnabled' class='w3-check w3-margin-top' type='checkbox' %IS_WEATHER_CHECKED%> Display Weather when printer is off</p>"
|
||||
"<label>OpenWeatherMap API Key (get from <a href='https://openweathermap.org/' target='_BLANK'>here</a>)</label>"
|
||||
"<input class='w3-input w3-border w3-margin-bottom' type='text' name='openWeatherMapApiKey' value='%WEATHERKEY%' maxlength='60'>"
|
||||
"<p><label>%CITYNAME1% (<a href='http://openweathermap.org/find' target='_BLANK'><i class='fa fa-search'></i> Search for City ID</a>) "
|
||||
"or full <a href='http://openweathermap.org/help/city_list.txt' target='_BLANK'>city list</a></label>"
|
||||
"<input class='w3-input w3-border w3-margin-bottom' type='text' name='city1' value='%CITY1%' onkeypress='return isNumberKey(event)'></p>"
|
||||
"<p><input name='metric' class='w3-check w3-margin-top' type='checkbox' %METRIC%> Use Metric (Celsius)</p>"
|
||||
"<p>Weather Language <select class='w3-option w3-padding' name='language'>%LANGUAGEOPTIONS%</select></p>"
|
||||
"<button class='w3-button w3-block w3-grey w3-section w3-padding' type='submit'>Save</button></form>"
|
||||
"<script>function isNumberKey(e){var h=e.which?e.which:event.keyCode;return!(h>31&&(h<48||h>57))}</script>";
|
||||
|
||||
static const char LANG_OPTIONS[] PROGMEM = "<option>ar</option>"
|
||||
String LANG_OPTIONS = "<option>ar</option>"
|
||||
"<option>bg</option>"
|
||||
"<option>ca</option>"
|
||||
"<option>cz</option>"
|
||||
|
|
@ -171,7 +182,7 @@ static const char LANG_OPTIONS[] PROGMEM = "<option>ar</option>"
|
|||
"<option>zh_cn</option>"
|
||||
"<option>zh_tw</option>";
|
||||
|
||||
static const char COLOR_THEMES[] PROGMEM = "<option>red</option>"
|
||||
String COLOR_THEMES = "<option>red</option>"
|
||||
"<option>pink</option>"
|
||||
"<option>purple</option>"
|
||||
"<option>deep-purple</option>"
|
||||
|
|
@ -207,9 +218,6 @@ void setup() {
|
|||
// Initialize digital pin for LED (little blue light on the Wemos D1 Mini)
|
||||
pinMode(externalLight, OUTPUT);
|
||||
|
||||
//Some Defaults before loading from Config.txt
|
||||
PrinterPort = printerClient.getPrinterPort();
|
||||
|
||||
readSettings();
|
||||
|
||||
// initialize display
|
||||
|
|
@ -221,16 +229,10 @@ void setup() {
|
|||
display.display();
|
||||
|
||||
//display.flipScreenVertically();
|
||||
|
||||
display.setFont(ArialMT_Plain_16);
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display.setContrast(255); // default is 255
|
||||
display.setFont(ArialMT_Plain_16);
|
||||
display.drawString(64, 1, "Printer Monitor");
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.drawString(64, 18, "for " + printerClient.getPrinterType());
|
||||
display.setFont(ArialMT_Plain_16);
|
||||
display.drawString(64, 30, "By Qrome");
|
||||
display.drawString(64, 46, "V" + String(VERSION));
|
||||
display.drawString(64, 5, "Printer Monitor\nBy Qrome\nV" + String(VERSION));
|
||||
display.display();
|
||||
|
||||
//WiFiManager
|
||||
|
|
@ -333,68 +335,82 @@ void setup() {
|
|||
display.drawString(64, 20, "Enable in Settings.h");
|
||||
display.display();
|
||||
}
|
||||
flashLED(5, 100);
|
||||
findMDNS(); //go find Printer Server by the hostname
|
||||
flashLED(5, 500);
|
||||
findMDNS(); //go find Octoprint Server by the hostname
|
||||
Serial.println("*** Leaving setup()");
|
||||
{
|
||||
|
||||
|
||||
pinMode(D8, OUTPUT);
|
||||
digitalWrite(D8, LOW);
|
||||
Serial.println("");
|
||||
Serial.print("Connected to ");
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
Serial.println("Starting UDP");
|
||||
udp.begin(localPort);
|
||||
Serial.print("Local port: ");
|
||||
Serial.println(udp.localPort());
|
||||
}
|
||||
}
|
||||
|
||||
void findMDNS() {
|
||||
if (PrinterHostName == "" || ENABLE_OTA == false) {
|
||||
if (OctoPrintHostName == "" || ENABLE_OTA == false) {
|
||||
return; // nothing to do here
|
||||
}
|
||||
// We now query our network for 'web servers' service
|
||||
// over tcp, and get the number of available devices
|
||||
int n = MDNS.queryService("http", "tcp");
|
||||
if (n == 0) {
|
||||
Serial.println("no services found - make sure Printer server is turned on");
|
||||
Serial.println("no services found - make sure OctoPrint server is turned on");
|
||||
return;
|
||||
}
|
||||
Serial.println("*** Looking for " + PrinterHostName + " over mDNS");
|
||||
Serial.println("*** Looking for " + OctoPrintHostName + " over mDNS");
|
||||
for (int i = 0; i < n; ++i) {
|
||||
// Going through every available service,
|
||||
// we're searching for the one whose hostname
|
||||
// matches what we want, and then get its IP
|
||||
Serial.println("Found: " + MDNS.hostname(i));
|
||||
if (MDNS.hostname(i) == PrinterHostName) {
|
||||
if (MDNS.hostname(i) == OctoPrintHostName) {
|
||||
IPAddress serverIp = MDNS.IP(i);
|
||||
PrinterServer = serverIp.toString();
|
||||
PrinterPort = MDNS.port(i); // save the port
|
||||
Serial.println("*** Found Printer Server " + PrinterHostName + " http://" + PrinterServer + ":" + PrinterPort);
|
||||
OctoPrintServer = serverIp.toString();
|
||||
OctoPrintPort = MDNS.port(i); // save the port
|
||||
Serial.println("*** Found OctoPrint Server " + OctoPrintHostName + " http://" + OctoPrintServer + ":" + OctoPrintPort);
|
||||
writeSettings(); // update the settings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//************************************************************
|
||||
// Main Loop
|
||||
// Main Looop
|
||||
//************************************************************
|
||||
void loop() {
|
||||
|
||||
//Get Time Update
|
||||
if((getMinutesFromLastRefresh() >= minutesBetweenDataRefresh) || lastEpoch == 0) {
|
||||
if ((getMinutesFromLastRefresh() >= minutesBetweenDataRefresh) || lastEpoch == 0) {
|
||||
getUpdateTime();
|
||||
}
|
||||
|
||||
if (lastMinute != timeClient.getMinutes() && !printerClient.isPrinting()) {
|
||||
// Check status every 60 seconds
|
||||
ledOnOff(true);
|
||||
digitalWrite(externalLight, LOW);
|
||||
lastMinute = timeClient.getMinutes(); // reset the check value
|
||||
printerClient.getPrinterJobResults();
|
||||
printerClient.getPrinterPsuState();
|
||||
ledOnOff(false);
|
||||
digitalWrite(externalLight, HIGH);
|
||||
} else if (printerClient.isPrinting()) {
|
||||
if (lastSecond != timeClient.getSeconds() && timeClient.getSeconds().endsWith("0")) {
|
||||
lastSecond = timeClient.getSeconds();
|
||||
// every 10 seconds while printing get an update
|
||||
ledOnOff(true);
|
||||
digitalWrite(externalLight, LOW);
|
||||
printerClient.getPrinterJobResults();
|
||||
printerClient.getPrinterPsuState();
|
||||
ledOnOff(false);
|
||||
digitalWrite(externalLight, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
checkDisplay(); // Check to see if the printer is on or offline and change display.
|
||||
|
||||
lightOn();
|
||||
ui.update();
|
||||
|
||||
if (WEBSERVER_ENABLED) {
|
||||
|
|
@ -403,10 +419,47 @@ void loop() {
|
|||
if (ENABLE_OTA) {
|
||||
ArduinoOTA.handle();
|
||||
}
|
||||
{ //Loop for motion LED
|
||||
int cb = udp.parsePacket();//start of UDP
|
||||
if (!cb)
|
||||
{
|
||||
//If serial data is recived send it to UDP
|
||||
if (Serial.available() > 0)
|
||||
{
|
||||
udp.beginPacket(SendIP, 2000); //Send Data to Master unit
|
||||
//Send UDP requests are to port
|
||||
char a[1];
|
||||
a[0] = char(Serial.read()); //Serial Byte Read
|
||||
udp.write(a, 1); //Send one byte to ESP8266
|
||||
udp.endPacket();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
digitalWrite(D8, HIGH);
|
||||
delay(5000);
|
||||
digitalWrite(D8, LOW);
|
||||
delay(20);
|
||||
}
|
||||
}//end of UDP
|
||||
}
|
||||
|
||||
void lightOn() {
|
||||
ldrStatus = analogRead(ldrPin);
|
||||
if(ldrStatus>=250){
|
||||
Serial.print("LDR true");
|
||||
DISPLAYCLOCK = true;
|
||||
//enableDisplay(true);
|
||||
}
|
||||
else{
|
||||
Serial.print("LDR false");
|
||||
DISPLAYCLOCK = false;
|
||||
// enableDisplay(false);
|
||||
}
|
||||
}
|
||||
|
||||
void getUpdateTime() {
|
||||
ledOnOff(true); // turn on the LED
|
||||
digitalWrite(externalLight, LOW); // turn on the LED
|
||||
Serial.println();
|
||||
|
||||
if (displayOn && DISPLAYWEATHER) {
|
||||
|
|
@ -420,7 +473,7 @@ void getUpdateTime() {
|
|||
lastEpoch = timeClient.getCurrentEpoch();
|
||||
Serial.println("Local time: " + timeClient.getAmPmFormattedTime());
|
||||
|
||||
ledOnOff(false); // turn off the LED
|
||||
digitalWrite(externalLight, HIGH); // turn off the LED
|
||||
}
|
||||
|
||||
boolean authentication() {
|
||||
|
|
@ -462,19 +515,15 @@ void handleUpdateConfig() {
|
|||
if (!authentication()) {
|
||||
return server.requestAuthentication();
|
||||
}
|
||||
if (server.hasArg("printer")) {
|
||||
printerClient.setPrinterName(server.arg("printer"));
|
||||
}
|
||||
PrinterApiKey = server.arg("PrinterApiKey");
|
||||
PrinterHostName = server.arg("PrinterHostName");
|
||||
PrinterServer = server.arg("PrinterAddress");
|
||||
PrinterPort = server.arg("PrinterPort").toInt();
|
||||
PrinterAuthUser = server.arg("octoUser");
|
||||
PrinterAuthPass = server.arg("octoPass");
|
||||
OctoPrintApiKey = server.arg("octoPrintApiKey");
|
||||
OctoPrintHostName = server.arg("octoPrintHostName");
|
||||
OctoPrintServer = server.arg("octoPrintAddress");
|
||||
OctoPrintPort = server.arg("octoPrintPort").toInt();
|
||||
OctoAuthUser = server.arg("octoUser");
|
||||
OctoAuthPass = server.arg("octoPass");
|
||||
DISPLAYCLOCK = server.hasArg("isClockEnabled");
|
||||
IS_24HOUR = server.hasArg("is24hour");
|
||||
INVERT_DISPLAY = server.hasArg("invDisp");
|
||||
USE_FLASH = server.hasArg("useFlash");
|
||||
HAS_PSU = server.hasArg("hasPSU");
|
||||
minutesBetweenDataRefresh = server.arg("refresh").toInt();
|
||||
themeColor = server.arg("theme");
|
||||
|
|
@ -489,7 +538,7 @@ void handleUpdateConfig() {
|
|||
printerClient.getPrinterPsuState();
|
||||
if (INVERT_DISPLAY != flipOld) {
|
||||
ui.init();
|
||||
if(INVERT_DISPLAY)
|
||||
if (INVERT_DISPLAY)
|
||||
display.flipScreenVertically();
|
||||
ui.update();
|
||||
}
|
||||
|
|
@ -514,7 +563,7 @@ void handleWeatherConfigure() {
|
|||
if (!authentication()) {
|
||||
return server.requestAuthentication();
|
||||
}
|
||||
ledOnOff(true);
|
||||
digitalWrite(externalLight, LOW);
|
||||
String html = "";
|
||||
|
||||
server.sendHeader("Cache-Control", "no-cache, no-store");
|
||||
|
|
@ -526,7 +575,7 @@ void handleWeatherConfigure() {
|
|||
html = getHeader();
|
||||
server.sendContent(html);
|
||||
|
||||
String form = FPSTR(WEATHER_FORM);
|
||||
String form = WEATHER_FORM;
|
||||
String isWeatherChecked = "";
|
||||
if (DISPLAYWEATHER) {
|
||||
isWeatherChecked = "checked='checked'";
|
||||
|
|
@ -540,8 +589,8 @@ void handleWeatherConfigure() {
|
|||
checked = "checked='checked'";
|
||||
}
|
||||
form.replace("%METRIC%", checked);
|
||||
String options = FPSTR(LANG_OPTIONS);
|
||||
options.replace(">"+String(WeatherLanguage)+"<", " selected>"+String(WeatherLanguage)+"<");
|
||||
String options = LANG_OPTIONS;
|
||||
options.replace(">" + String(WeatherLanguage) + "<", " selected>" + String(WeatherLanguage) + "<");
|
||||
form.replace("%LANGUAGEOPTIONS%", options);
|
||||
server.sendContent(form);
|
||||
|
||||
|
|
@ -549,14 +598,14 @@ void handleWeatherConfigure() {
|
|||
server.sendContent(html);
|
||||
server.sendContent("");
|
||||
server.client().stop();
|
||||
ledOnOff(false);
|
||||
digitalWrite(externalLight, HIGH);
|
||||
}
|
||||
|
||||
void handleConfigure() {
|
||||
if (!authentication()) {
|
||||
return server.requestAuthentication();
|
||||
}
|
||||
ledOnOff(true);
|
||||
digitalWrite(externalLight, LOW);
|
||||
String html = "";
|
||||
|
||||
server.sendHeader("Cache-Control", "no-cache, no-store");
|
||||
|
|
@ -568,61 +617,14 @@ void handleConfigure() {
|
|||
html = getHeader();
|
||||
server.sendContent(html);
|
||||
|
||||
CHANGE_FORM = "<form class='w3-container' action='/updateconfig' method='get'><h2>Station Config:</h2>"
|
||||
"<p><label>" + printerClient.getPrinterType() + " API Key (get from your server)</label>"
|
||||
"<input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterApiKey' id='PrinterApiKey' value='%OCTOKEY%' maxlength='60'></p>";
|
||||
if (printerClient.getPrinterType() == "OctoPrint") {
|
||||
CHANGE_FORM += "<p><label>" + printerClient.getPrinterType() + " Host Name (usually octopi)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterHostName' value='%OCTOHOST%' maxlength='60'></p>";
|
||||
}
|
||||
CHANGE_FORM += "<p><label>" + printerClient.getPrinterType() + " Address (do not include http://)</label>"
|
||||
"<input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterAddress' id='PrinterAddress' value='%OCTOADDRESS%' maxlength='60'></p>"
|
||||
"<p><label>" + printerClient.getPrinterType() + " Port</label>"
|
||||
"<input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterPort' id='PrinterPort' value='%OCTOPORT%' maxlength='5' onkeypress='return isNumberKey(event)'></p>";
|
||||
if (printerClient.getPrinterType() == "Repetier") {
|
||||
CHANGE_FORM += "<input type='button' value='Test Connection' onclick='testRepetier()'>"
|
||||
"<input type='hidden' id='selectedPrinter' value='" + printerClient.getPrinterName() + "'><p id='RepetierTest'></p>"
|
||||
"<script>testRepetier();</script>";
|
||||
} else {
|
||||
CHANGE_FORM += "<input type='button' value='Test Connection and API JSON Response' onclick='testOctoPrint()'><p id='OctoPrintTest'></p>";
|
||||
}
|
||||
CHANGE_FORM += "<p><label>" + printerClient.getPrinterType() + " User (only needed if you have haproxy or basic auth turned on)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='octoUser' value='%OCTOUSER%' maxlength='30'></p>"
|
||||
"<p><label>" + printerClient.getPrinterType() + " Password </label><input class='w3-input w3-border w3-margin-bottom' type='password' name='octoPass' value='%OCTOPASS%'></p>";
|
||||
|
||||
|
||||
|
||||
if (printerClient.getPrinterType() == "Repetier") {
|
||||
html = "<script>function testRepetier(){var e=document.getElementById(\"RepetierTest\"),r=document.getElementById(\"PrinterAddress\").value,"
|
||||
"t=document.getElementById(\"PrinterPort\").value;if(\"\"==r||\"\"==t)return e.innerHTML=\"* Address and Port are required\","
|
||||
"void(e.style.background=\"\");var n=\"http://\"+r+\":\"+t;n+=\"/printer/api/?a=listPrinter&apikey=\"+document.getElementById(\"PrinterApiKey\").value,"
|
||||
"console.log(n);var o=new XMLHttpRequest;o.open(\"GET\",n,!0),o.onload=function(){if(200===o.status){var r=JSON.parse(o.responseText);"
|
||||
"if(!r.error&&r.length>0){var t=\"<label>Connected -- Select Printer</label> \";t+=\"<select class='w3-option w3-padding' name='printer'>\";"
|
||||
"var n=document.getElementById(\"selectedPrinter\").value,i=\"\";for(printer in r)i=r[printer].slug==n?\"selected\":\"\","
|
||||
"t+=\"<option value='\"+r[printer].slug+\"' \"+i+\">\"+r[printer].name+\"</option>\";t+=\"</select>\","
|
||||
"e.innerHTML=t,e.style.background=\"lime\"}else e.innerHTML=\"Error invalid API Key: \"+r.error,"
|
||||
"e.style.background=\"red\"}else e.innerHTML=\"Error: \"+o.statusText,e.style.background=\"red\"},"
|
||||
"o.onerror=function(){e.innerHTML=\"Error connecting to server -- check IP and Port\",e.style.background=\"red\"},o.send(null)}</script>";
|
||||
|
||||
server.sendContent(html);
|
||||
} else {
|
||||
html = "<script>function testOctoPrint(){var e=document.getElementById(\"OctoPrintTest\"),t=document.getElementById(\"PrinterAddress\").value,"
|
||||
"n=document.getElementById(\"PrinterPort\").value;if(e.innerHTML=\"\",\"\"==t||\"\"==n)return e.innerHTML=\"* Address and Port are required\","
|
||||
"void(e.style.background=\"\");var r=\"http://\"+t+\":\"+n;r+=\"/api/job?apikey=\"+document.getElementById(\"PrinterApiKey\").value,window.open(r,\"_blank\").focus()}</script>";
|
||||
server.sendContent(html);
|
||||
}
|
||||
|
||||
String form = CHANGE_FORM;
|
||||
|
||||
form.replace("%OCTOKEY%", PrinterApiKey);
|
||||
form.replace("%OCTOHOST%", PrinterHostName);
|
||||
form.replace("%OCTOADDRESS%", PrinterServer);
|
||||
form.replace("%OCTOPORT%", String(PrinterPort));
|
||||
form.replace("%OCTOUSER%", PrinterAuthUser);
|
||||
form.replace("%OCTOPASS%", PrinterAuthPass);
|
||||
|
||||
server.sendContent(form);
|
||||
|
||||
form = FPSTR(CLOCK_FORM);
|
||||
|
||||
form.replace("%OCTOKEY%", OctoPrintApiKey);
|
||||
form.replace("%OCTOHOST%", OctoPrintHostName);
|
||||
form.replace("%OCTOADDRESS%", OctoPrintServer);
|
||||
form.replace("%OCTOPORT%", String(OctoPrintPort));
|
||||
form.replace("%OCTOUSER%", OctoAuthUser);
|
||||
form.replace("%OCTOPASS%", OctoAuthPass);
|
||||
String isClockChecked = "";
|
||||
if (DISPLAYCLOCK) {
|
||||
isClockChecked = "checked='checked'";
|
||||
|
|
@ -638,11 +640,6 @@ void handleConfigure() {
|
|||
isInvDisp = "checked='checked'";
|
||||
}
|
||||
form.replace("%IS_INVDISP_CHECKED%", isInvDisp);
|
||||
String isFlashLED = "";
|
||||
if (USE_FLASH) {
|
||||
isFlashLED = "checked='checked'";
|
||||
}
|
||||
form.replace("%USEFLASH%", isFlashLED);
|
||||
String hasPSUchecked = "";
|
||||
if (HAS_PSU) {
|
||||
hasPSUchecked = "checked='checked'";
|
||||
|
|
@ -650,15 +647,15 @@ void handleConfigure() {
|
|||
form.replace("%HAS_PSU_CHECKED%", hasPSUchecked);
|
||||
|
||||
String options = "<option>10</option><option>15</option><option>20</option><option>30</option><option>60</option>";
|
||||
options.replace(">"+String(minutesBetweenDataRefresh)+"<", " selected>"+String(minutesBetweenDataRefresh)+"<");
|
||||
options.replace(">" + String(minutesBetweenDataRefresh) + "<", " selected>" + String(minutesBetweenDataRefresh) + "<");
|
||||
form.replace("%OPTIONS%", options);
|
||||
|
||||
server.sendContent(form);
|
||||
|
||||
form = FPSTR(THEME_FORM);
|
||||
form = THEME_FORM;
|
||||
|
||||
String themeOptions = FPSTR(COLOR_THEMES);
|
||||
themeOptions.replace(">"+String(themeColor)+"<", " selected>"+String(themeColor)+"<");
|
||||
String themeOptions = COLOR_THEMES;
|
||||
themeOptions.replace(">" + String(themeColor) + "<", " selected>" + String(themeColor) + "<");
|
||||
form.replace("%THEME_OPTIONS%", themeOptions);
|
||||
form.replace("%UTCOFFSET%", String(UtcOffset));
|
||||
String isUseSecurityChecked = "";
|
||||
|
|
@ -675,11 +672,11 @@ void handleConfigure() {
|
|||
server.sendContent(html);
|
||||
server.sendContent("");
|
||||
server.client().stop();
|
||||
ledOnOff(false);
|
||||
digitalWrite(externalLight, HIGH);
|
||||
}
|
||||
|
||||
void displayMessage(String message) {
|
||||
ledOnOff(true);
|
||||
digitalWrite(externalLight, LOW);
|
||||
|
||||
server.sendHeader("Cache-Control", "no-cache, no-store");
|
||||
server.sendHeader("Pragma", "no-cache");
|
||||
|
|
@ -694,7 +691,7 @@ void displayMessage(String message) {
|
|||
server.sendContent("");
|
||||
server.client().stop();
|
||||
|
||||
ledOnOff(false);
|
||||
digitalWrite(externalLight, HIGH);
|
||||
}
|
||||
|
||||
void redirectHome() {
|
||||
|
|
@ -712,7 +709,7 @@ String getHeader() {
|
|||
}
|
||||
|
||||
String getHeader(boolean refresh) {
|
||||
String menu = FPSTR(WEB_ACTIONS);
|
||||
String menu = WEB_ACTIONS;
|
||||
|
||||
String html = "<!DOCTYPE HTML>";
|
||||
html += "<html><head><title>Printer Monitor</title><link rel='icon' href='data:;base64,='>";
|
||||
|
|
@ -760,7 +757,7 @@ String getFooter() {
|
|||
}
|
||||
|
||||
void displayPrinterStatus() {
|
||||
ledOnOff(true);
|
||||
digitalWrite(externalLight, LOW);
|
||||
String html = "";
|
||||
|
||||
server.sendHeader("Cache-Control", "no-cache, no-store");
|
||||
|
|
@ -775,14 +772,9 @@ void displayPrinterStatus() {
|
|||
displayTime = timeClient.getHours() + ":" + timeClient.getMinutes() + ":" + timeClient.getSeconds();
|
||||
}
|
||||
|
||||
html += "<div class='w3-cell-row' style='width:100%'><h2>" + printerClient.getPrinterType() + " Monitor</h2></div><div class='w3-cell-row'>";
|
||||
html += "<div class='w3-cell-row' style='width:100%'><h2>Time: " + displayTime + "</h2></div><div class='w3-cell-row'>";
|
||||
html += "<div class='w3-cell w3-container' style='width:100%'><p>";
|
||||
if (printerClient.getPrinterType() == "Repetier") {
|
||||
html += "Printer Name: " + printerClient.getPrinterName() + " <a href='/configure' title='Configure'><i class='fa fa-cog'></i></a><br>";
|
||||
} else {
|
||||
html += "Host Name: " + PrinterHostName + " <a href='/configure' title='Configure'><i class='fa fa-cog'></i></a><br>";
|
||||
}
|
||||
|
||||
html += "Host Name: " + OctoPrintHostName + "<br>";
|
||||
if (printerClient.getError() != "") {
|
||||
html += "Status: Offline<br>";
|
||||
html += "Reason: " + printerClient.getError() + "<br>";
|
||||
|
|
@ -831,8 +823,6 @@ void displayPrinterStatus() {
|
|||
|
||||
html += "</p></div></div>";
|
||||
|
||||
html += "<div class='w3-cell-row' style='width:100%'><h2>Time: " + displayTime + "</h2></div>";
|
||||
|
||||
server.sendContent(html); // spit out what we got
|
||||
html = "";
|
||||
|
||||
|
|
@ -863,7 +853,7 @@ void displayPrinterStatus() {
|
|||
server.sendContent(String(getFooter()));
|
||||
server.sendContent("");
|
||||
server.client().stop();
|
||||
ledOnOff(false);
|
||||
digitalWrite(externalLight, HIGH);
|
||||
}
|
||||
|
||||
void configModeCallback (WiFiManager *myWiFiManager) {
|
||||
|
|
@ -876,9 +866,9 @@ void configModeCallback (WiFiManager *myWiFiManager) {
|
|||
display.drawString(64, 0, "Wifi Manager");
|
||||
display.drawString(64, 10, "Please connect to AP");
|
||||
display.setFont(ArialMT_Plain_16);
|
||||
display.drawString(64, 26, myWiFiManager->getConfigPortalSSID());
|
||||
display.drawString(64, 23, myWiFiManager->getConfigPortalSSID());
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.drawString(64, 46, "To setup Wifi connection");
|
||||
display.drawString(64, 42, "To setup Wifi connection");
|
||||
display.display();
|
||||
|
||||
Serial.println("Wifi Manager");
|
||||
|
|
@ -888,22 +878,12 @@ void configModeCallback (WiFiManager *myWiFiManager) {
|
|||
flashLED(20, 50);
|
||||
}
|
||||
|
||||
void ledOnOff(boolean value) {
|
||||
if (USE_FLASH) {
|
||||
if (value) {
|
||||
digitalWrite(externalLight, LOW); // LED ON
|
||||
} else {
|
||||
digitalWrite(externalLight, HIGH); // LED OFF
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void flashLED(int number, int delayTime) {
|
||||
for (int inx = 0; inx <= number; inx++) {
|
||||
for (int inx = 0; inx < number; inx++) {
|
||||
delay(delayTime);
|
||||
digitalWrite(externalLight, LOW); // ON
|
||||
digitalWrite(externalLight, LOW);
|
||||
delay(delayTime);
|
||||
digitalWrite(externalLight, HIGH); // OFF
|
||||
digitalWrite(externalLight, HIGH);
|
||||
delay(delayTime);
|
||||
}
|
||||
}
|
||||
|
|
@ -914,8 +894,7 @@ void drawScreen1(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int
|
|||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display->setFont(ArialMT_Plain_16);
|
||||
if (bed != "0") {
|
||||
display->drawString(29 + x, 0 + y, "Tool");
|
||||
display->drawString(89 + x, 0 + y, "Bed");
|
||||
display->drawString(64 + x, 0 + y, "Bed / Tool Temp");
|
||||
} else {
|
||||
display->drawString(64 + x, 0 + y, "Tool Temp");
|
||||
}
|
||||
|
|
@ -923,8 +902,8 @@ void drawScreen1(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int
|
|||
display->setFont(ArialMT_Plain_24);
|
||||
if (bed != "0") {
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display->drawString(12 + x, 14 + y, tool + "°");
|
||||
display->drawString(74 + x, 14 + y, bed + "°");
|
||||
display->drawString(2 + x, 14 + y, bed + "°");
|
||||
display->drawString(64 + x, 14 + y, tool + "°");
|
||||
} else {
|
||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display->drawString(64 + x, 14 + y, tool + "°");
|
||||
|
|
@ -970,12 +949,8 @@ void drawClock(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16
|
|||
if (IS_24HOUR) {
|
||||
displayTime = timeClient.getHours() + ":" + timeClient.getMinutes() + ":" + timeClient.getSeconds();
|
||||
}
|
||||
String displayName = PrinterHostName;
|
||||
if (printerClient.getPrinterType() == "Repetier") {
|
||||
displayName = printerClient.getPrinterName();
|
||||
}
|
||||
display->setFont(ArialMT_Plain_16);
|
||||
display->drawString(64 + x, 0 + y, displayName);
|
||||
display->drawString(64 + x, 0 + y, OctoPrintHostName);
|
||||
display->setFont(ArialMT_Plain_24);
|
||||
display->drawString(64 + x, 17 + y, displayTime);
|
||||
}
|
||||
|
|
@ -1067,16 +1042,12 @@ void drawClockHeaderOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
|
|||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
if (printerClient.isPSUoff()) {
|
||||
display->drawString(64, 47, "psu off");
|
||||
} else if (printerClient.getState() == "Operational") {
|
||||
display->drawString(64, 47, "online");
|
||||
} else {
|
||||
display->drawString(64, 47, "offline");
|
||||
}
|
||||
} else {
|
||||
if (printerClient.isPSUoff()) {
|
||||
display->drawString(0, 47, "psu off");
|
||||
} else if (printerClient.getState() == "Operational") {
|
||||
display->drawString(0, 47, "online");
|
||||
} else {
|
||||
display->drawString(0, 47, "offline");
|
||||
}
|
||||
|
|
@ -1103,9 +1074,9 @@ void drawRssi(OLEDDisplay *display) {
|
|||
// converts the dBm to a range between 0 and 100%
|
||||
int8_t getWifiQuality() {
|
||||
int32_t dbm = WiFi.RSSI();
|
||||
if(dbm <= -100) {
|
||||
if (dbm <= -100) {
|
||||
return 0;
|
||||
} else if(dbm >= -50) {
|
||||
} else if (dbm >= -50) {
|
||||
return 100;
|
||||
} else {
|
||||
return 2 * (dbm + 100);
|
||||
|
|
@ -1121,13 +1092,12 @@ void writeSettings() {
|
|||
} else {
|
||||
Serial.println("Saving settings now...");
|
||||
f.println("UtcOffset=" + String(UtcOffset));
|
||||
f.println("printerApiKey=" + PrinterApiKey);
|
||||
f.println("printerHostName=" + PrinterHostName);
|
||||
f.println("printerServer=" + PrinterServer);
|
||||
f.println("printerPort=" + String(PrinterPort));
|
||||
f.println("printerName=" + printerClient.getPrinterName());
|
||||
f.println("printerAuthUser=" + PrinterAuthUser);
|
||||
f.println("printerAuthPass=" + PrinterAuthPass);
|
||||
f.println("octoKey=" + OctoPrintApiKey);
|
||||
f.println("octoHost=" + OctoPrintHostName);
|
||||
f.println("octoServer=" + OctoPrintServer);
|
||||
f.println("octoPort=" + String(OctoPrintPort));
|
||||
f.println("octoUser=" + OctoAuthUser);
|
||||
f.println("octoPass=" + OctoAuthPass);
|
||||
f.println("refreshRate=" + String(minutesBetweenDataRefresh));
|
||||
f.println("themeColor=" + themeColor);
|
||||
f.println("IS_BASIC_AUTH=" + String(IS_BASIC_AUTH));
|
||||
|
|
@ -1136,7 +1106,6 @@ void writeSettings() {
|
|||
f.println("DISPLAYCLOCK=" + String(DISPLAYCLOCK));
|
||||
f.println("is24hour=" + String(IS_24HOUR));
|
||||
f.println("invertDisp=" + String(INVERT_DISPLAY));
|
||||
f.println("USE_FLASH=" + String(USE_FLASH));
|
||||
f.println("isWeather=" + String(DISPLAYWEATHER));
|
||||
f.println("weatherKey=" + WeatherApiKey);
|
||||
f.println("CityID=" + String(CityIDs[0]));
|
||||
|
|
@ -1145,7 +1114,7 @@ void writeSettings() {
|
|||
f.println("hasPSU=" + String(HAS_PSU));
|
||||
}
|
||||
f.close();
|
||||
readSettings();
|
||||
//readSettings();
|
||||
timeClient.setUtcOffset(UtcOffset);
|
||||
}
|
||||
|
||||
|
|
@ -1157,47 +1126,41 @@ void readSettings() {
|
|||
}
|
||||
File fr = SPIFFS.open(CONFIG, "r");
|
||||
String line;
|
||||
while(fr.available()) {
|
||||
while (fr.available()) {
|
||||
line = fr.readStringUntil('\n');
|
||||
|
||||
if (line.indexOf("UtcOffset=") >= 0) {
|
||||
UtcOffset = line.substring(line.lastIndexOf("UtcOffset=") + 10).toFloat();
|
||||
Serial.println("UtcOffset=" + String(UtcOffset));
|
||||
}
|
||||
if (line.indexOf("printerApiKey=") >= 0) {
|
||||
PrinterApiKey = line.substring(line.lastIndexOf("printerApiKey=") + 14);
|
||||
PrinterApiKey.trim();
|
||||
Serial.println("PrinterApiKey=" + PrinterApiKey);
|
||||
if (line.indexOf("octoKey=") >= 0) {
|
||||
OctoPrintApiKey = line.substring(line.lastIndexOf("octoKey=") + 8);
|
||||
OctoPrintApiKey.trim();
|
||||
Serial.println("OctoPrintApiKey=" + OctoPrintApiKey);
|
||||
}
|
||||
if (line.indexOf("printerHostName=") >= 0) {
|
||||
PrinterHostName = line.substring(line.lastIndexOf("printerHostName=") + 16);
|
||||
PrinterHostName.trim();
|
||||
Serial.println("PrinterHostName=" + PrinterHostName);
|
||||
if (line.indexOf("octoHost=") >= 0) {
|
||||
OctoPrintHostName = line.substring(line.lastIndexOf("octoHost=") + 9);
|
||||
OctoPrintHostName.trim();
|
||||
Serial.println("OctoPrintHostName=" + OctoPrintHostName);
|
||||
}
|
||||
if (line.indexOf("printerServer=") >= 0) {
|
||||
PrinterServer = line.substring(line.lastIndexOf("printerServer=") + 14);
|
||||
PrinterServer.trim();
|
||||
Serial.println("PrinterServer=" + PrinterServer);
|
||||
if (line.indexOf("octoServer=") >= 0) {
|
||||
OctoPrintServer = line.substring(line.lastIndexOf("octoServer=") + 11);
|
||||
OctoPrintServer.trim();
|
||||
Serial.println("OctoPrintServer=" + OctoPrintServer);
|
||||
}
|
||||
if (line.indexOf("printerPort=") >= 0) {
|
||||
PrinterPort = line.substring(line.lastIndexOf("printerPort=") + 12).toInt();
|
||||
Serial.println("PrinterPort=" + String(PrinterPort));
|
||||
if (line.indexOf("octoPort=") >= 0) {
|
||||
OctoPrintPort = line.substring(line.lastIndexOf("octoPort=") + 9).toInt();
|
||||
Serial.println("OctoPrintPort=" + String(OctoPrintPort));
|
||||
}
|
||||
if (line.indexOf("printerName=") >= 0) {
|
||||
String printer = line.substring(line.lastIndexOf("printerName=") + 12);
|
||||
printer.trim();
|
||||
printerClient.setPrinterName(printer);
|
||||
Serial.println("PrinterName=" + printerClient.getPrinterName());
|
||||
if (line.indexOf("octoUser=") >= 0) {
|
||||
OctoAuthUser = line.substring(line.lastIndexOf("octoUser=") + 9);
|
||||
OctoAuthUser.trim();
|
||||
Serial.println("OctoAuthUser=" + OctoAuthUser);
|
||||
}
|
||||
if (line.indexOf("printerAuthUser=") >= 0) {
|
||||
PrinterAuthUser = line.substring(line.lastIndexOf("printerAuthUser=") + 16);
|
||||
PrinterAuthUser.trim();
|
||||
Serial.println("PrinterAuthUser=" + PrinterAuthUser);
|
||||
}
|
||||
if (line.indexOf("printerAuthPass=") >= 0) {
|
||||
PrinterAuthPass = line.substring(line.lastIndexOf("printerAuthPass=") + 16);
|
||||
PrinterAuthPass.trim();
|
||||
Serial.println("PrinterAuthPass=" + PrinterAuthPass);
|
||||
if (line.indexOf("octoPass=") >= 0) {
|
||||
OctoAuthPass = line.substring(line.lastIndexOf("octoPass=") + 9);
|
||||
OctoAuthPass.trim();
|
||||
Serial.println("OctoAuthPass=" + OctoAuthPass);
|
||||
}
|
||||
if (line.indexOf("refreshRate=") >= 0) {
|
||||
minutesBetweenDataRefresh = line.substring(line.lastIndexOf("refreshRate=") + 12).toInt();
|
||||
|
|
@ -1232,14 +1195,10 @@ void readSettings() {
|
|||
IS_24HOUR = line.substring(line.lastIndexOf("is24hour=") + 9).toInt();
|
||||
Serial.println("IS_24HOUR=" + String(IS_24HOUR));
|
||||
}
|
||||
if(line.indexOf("invertDisp=") >= 0) {
|
||||
if (line.indexOf("invertDisp=") >= 0) {
|
||||
INVERT_DISPLAY = line.substring(line.lastIndexOf("invertDisp=") + 11).toInt();
|
||||
Serial.println("INVERT_DISPLAY=" + String(INVERT_DISPLAY));
|
||||
}
|
||||
if(line.indexOf("USE_FLASH=") >= 0) {
|
||||
USE_FLASH = line.substring(line.lastIndexOf("USE_FLASH=") + 10).toInt();
|
||||
Serial.println("USE_FLASH=" + String(USE_FLASH));
|
||||
}
|
||||
if (line.indexOf("hasPSU=") >= 0) {
|
||||
HAS_PSU = line.substring(line.lastIndexOf("hasPSU=") + 7).toInt();
|
||||
Serial.println("HAS_PSU=" + String(HAS_PSU));
|
||||
|
|
@ -1268,7 +1227,7 @@ void readSettings() {
|
|||
}
|
||||
}
|
||||
fr.close();
|
||||
printerClient.updatePrintClient(PrinterApiKey, PrinterServer, PrinterPort, PrinterAuthUser, PrinterAuthPass, HAS_PSU);
|
||||
printerClient.updateOctoPrintClient(OctoPrintApiKey, OctoPrintServer, OctoPrintPort, OctoAuthUser, OctoAuthPass, HAS_PSU);
|
||||
weatherClient.updateWeatherApiKey(WeatherApiKey);
|
||||
weatherClient.updateLanguage(WeatherLanguage);
|
||||
weatherClient.setMetric(IS_METRIC);
|
||||
|
|
@ -1291,16 +1250,16 @@ void checkDisplay() {
|
|||
if (!displayOn && DISPLAYCLOCK) {
|
||||
enableDisplay(true);
|
||||
}
|
||||
if (displayOn && !printerClient.isPrinting() && !DISPLAYCLOCK) {
|
||||
if (displayOn && !(printerClient.isOperational() || printerClient.isPrinting()) && !DISPLAYCLOCK) {
|
||||
// Put Display to sleep
|
||||
display.clear();
|
||||
display.display();
|
||||
display.setFont(ArialMT_Plain_16);
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display.setContrast(255); // default is 255
|
||||
display.drawString(64, 5, "Printer Offline\nSleep Mode...");
|
||||
display.display();
|
||||
delay(5000);
|
||||
//display.drawString(64, 5, "Printer Offline\nSleep Mode...");
|
||||
// display.display();
|
||||
//delay(5000);
|
||||
enableDisplay(false);
|
||||
Serial.println("Printer is offline going down to sleep...");
|
||||
return;
|
||||
|
|
@ -1320,7 +1279,7 @@ void checkDisplay() {
|
|||
return;
|
||||
}
|
||||
} else if (DISPLAYCLOCK) {
|
||||
if ((!printerClient.isPrinting() || printerClient.isPSUoff()) && !isClockOn) {
|
||||
if ((!printerClient.isOperational() || printerClient.isPSUoff()) && !isClockOn) {
|
||||
Serial.println("Clock Mode is turned on.");
|
||||
if (!DISPLAYWEATHER) {
|
||||
ui.disableAutoTransition();
|
||||
|
|
@ -1334,7 +1293,7 @@ void checkDisplay() {
|
|||
}
|
||||
ui.setOverlays(clockOverlay, numberOfOverlays);
|
||||
isClockOn = true;
|
||||
} else if (printerClient.isPrinting() && !printerClient.isPSUoff() && isClockOn) {
|
||||
} else if (printerClient.isOperational() && !printerClient.isPSUoff() && isClockOn) {
|
||||
Serial.println("Printer Monitor is active.");
|
||||
ui.setFrames(frames, numberOfFrames);
|
||||
ui.setOverlays(overlays, numberOfOverlays);
|
||||
|
|
|
|||
Loading…
Reference in New Issue