diff --git a/printermonitor/Settings.h b/printermonitor/Settings.h index 96adc95..0c973b2 100644 --- a/printermonitor/Settings.h +++ b/printermonitor/Settings.h @@ -43,6 +43,7 @@ SOFTWARE. #include "TimeClient.h" #include "OctoPrintClient.h" #include "FS.h" +#include "SH1106Wire.h" #include "SSD1306Wire.h" #include "OLEDDisplayUi.h" @@ -51,25 +52,26 @@ SOFTWARE. //****************************** // OctoPrint Monitoring -- Monitor your 3D printer OctoPrint Server -String OctoPrintApiKey = ""; // ApiKey from your User Account on OctoPrint -String OctoPrintServer = ""; // 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 OctoPrintApiKey = ""; // ApiKey from your User Account on OctoPrint +String OctoPrintServer = ""; // 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); 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]/ char* www_username = "admin"; // User account for the Web Interface char* www_password = "password"; // Password for the Web Interface float UtcOffset = -7; // Hour offset from GMT for your timezone -boolean IS_24HOUR = false; // 23:00 millitary 24 hour clock +boolean IS_24HOUR = false; // 23:00 millitary 24 hour clock int minutesBetweenDataRefresh = 60; -boolean DISPLAYCLOCK = true; // true = Show Clock when not printing / false = turn off display when not printing +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; +//#define DISPLAY_SH1106 // Uncomment this line to use the SH1106 display -- SSD1306 is used by default and is most common -boolean ENABLE_OTA = true; // this will allow you to load firmware to the device over WiFi (see OTA for ESP8266) +boolean ENABLE_OTA = true; // this will allow you to load firmware to the device over WiFi (see OTA for ESP8266) //****************************** // End Settings diff --git a/printermonitor/printermonitor.ino b/printermonitor/printermonitor.ino index 11e360d..cdf0628 100644 --- a/printermonitor/printermonitor.ino +++ b/printermonitor/printermonitor.ino @@ -27,9 +27,9 @@ SOFTWARE. #include "Settings.h" -#define VERSION "1.3" +#define VERSION "1.4" -#define HOSTNAME "ESP8266-" +#define HOSTNAME "OctMon-" #define CONFIG "/conf.txt" /* Useful Constants */ @@ -45,7 +45,12 @@ SOFTWARE. // Initialize the oled display for I2C_DISPLAY_ADDRESS // SDA_PIN and SCL_PIN -SSD1306Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SCL_PIN); +#if defined(DISPLAY_SH1106) + SH1106Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SCL_PIN); +#else + SSD1306Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SCL_PIN); // this is the default +#endif + OLEDDisplayUi ui( &display ); void drawProgress(OLEDDisplay *display, int percentage, String label); @@ -167,23 +172,15 @@ void setup() { //wifiManager.resetSettings(); wifiManager.setAPCallback(configModeCallback); - //or use this for auto generated name ESP + ChipID - wifiManager.autoConnect(); - - //Manual Wifi String hostname(HOSTNAME); hostname += String(ESP.getChipId(), HEX); - WiFi.hostname(hostname); - - int cnt = 0; - while (WiFi.status() != WL_CONNECTED) { - digitalWrite(externalLight, LOW); - delay(500); - Serial.print("."); - cnt++; - digitalWrite(externalLight, HIGH); + if (!wifiManager.autoConnect((const char *)hostname.c_str())) {// new addition + delay(3000); + WiFi.disconnect(true); + ESP.reset(); + delay(5000); } - + // You can change the transition that is used // SLIDE_LEFT, SLIDE_RIGHT, SLIDE_TOP, SLIDE_DOWN ui.setFrameAnimation(SLIDE_LEFT); @@ -222,6 +219,7 @@ void setup() { else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); else if (error == OTA_END_ERROR) Serial.println("End Failed"); }); + ArduinoOTA.setHostname((const char *)hostname.c_str()); ArduinoOTA.begin(); } @@ -552,7 +550,19 @@ void displayPrinterStatus() { void configModeCallback (WiFiManager *myWiFiManager) { Serial.println("Entered config mode"); - Serial.println(WiFi.softAPIP()); + Serial.println(WiFi.softAPIP()); + + display.clear(); + display.setTextAlignment(TEXT_ALIGN_CENTER); + display.setFont(ArialMT_Plain_10); + display.drawString(64, 0, "Wifi Manager"); + display.drawString(64, 10, "Please connect to AP"); + display.setFont(ArialMT_Plain_16); + display.drawString(64, 23, myWiFiManager->getConfigPortalSSID()); + display.setFont(ArialMT_Plain_10); + display.drawString(64, 42, "To setup Wifi connection"); + display.display(); + Serial.println("Wifi Manager"); Serial.println("Please connect to AP"); Serial.println(myWiFiManager->getConfigPortalSSID());