diff --git a/Arduino/BTCDieselHeater/BTCDieselHeater.ino b/Arduino/BTCDieselHeater/BTCDieselHeater.ino index 2af9090..3db3484 100644 --- a/Arduino/BTCDieselHeater/BTCDieselHeater.ino +++ b/Arduino/BTCDieselHeater/BTCDieselHeater.ino @@ -103,6 +103,9 @@ #include "src/OLED/keypad.h" #include #include "src/RTC/Clock.h" +#if USE_SPIFFS == 1 +#include +#endif #define FAILEDSSID "BTCESP32" #define FAILEDPASSWORD "thereisnospoon" @@ -266,6 +269,16 @@ void setup() { sprintf(msg, " Temperature for device#1 (idx 0) is: %.1f", TempSensor.getTempCByIndex(0)); DebugPort.println(msg); +#if USE_SPIFFS == 1 + // Initialize SPIFFS + if(!SPIFFS.begin(true)){ + DebugPort.println("An Error has occurred while mounting SPIFFS"); + } + else { + DebugPort.println("Mounted SPIFFS OK"); + } +#endif + // locate devices on the bus DebugPort.print(" Locating DS18B20 devices..."); @@ -316,7 +329,7 @@ void setup() { initWifi(WiFi_TriggerPin, FAILEDSSID, FAILEDPASSWORD); #if USE_OTA == 1 -// initOTA(); + initOTA(); #endif // USE_OTA #if USE_WEBSERVER == 1 initWebServer(); diff --git a/Arduino/BTCDieselHeater/data/favicon.ico b/Arduino/BTCDieselHeater/data/favicon.ico new file mode 100644 index 0000000..f225d9d Binary files /dev/null and b/Arduino/BTCDieselHeater/data/favicon.ico differ diff --git a/Arduino/BTCDieselHeater/data/index.html b/Arduino/BTCDieselHeater/data/index.html new file mode 100644 index 0000000..bf33f3b --- /dev/null +++ b/Arduino/BTCDieselHeater/data/index.html @@ -0,0 +1,502 @@ + + + + + +Chinese Diesel Heater Web Controller Interface + + + + + + + + + +
+ + + +
+ +

Power Control

+ +
+ + +
+ + +
+

Temperature Control

+
+ +
+Desired Temp: + +
+
+Fixed Hz: + +
+
+Current Temp: +
+ + + +
+Advanced Settings +Pump Min + +
+Pump Max + +
+
+Fan Min + +
+
+Fan Max + +
+
+ + +
+Current Date:
+ + +
+Current Time (24 Hour Format):
+ + +
+

+Timer1:
+Timer2:
+ +
+ + diff --git a/Arduino/BTCDieselHeater/src/Bluetooth/BluetoothESP32.cpp b/Arduino/BTCDieselHeater/src/Bluetooth/BluetoothESP32.cpp index a06bcb7..aa534dd 100644 --- a/Arduino/BTCDieselHeater/src/Bluetooth/BluetoothESP32.cpp +++ b/Arduino/BTCDieselHeater/src/Bluetooth/BluetoothESP32.cpp @@ -27,10 +27,8 @@ #include "../cfg/BTCConfig.h" - #ifdef ESP32 - ///////////////////////////////////////////////////////////////////////////////////////// // HC-05 BLUETOOTH with ESP32 // | @@ -60,7 +58,7 @@ CBluetoothESP32HC05::openSerial(int baudrate) - +#if USE_CLASSIC_BLUETOOTH == 1 ///////////////////////////////////////////////////////////////////////////////////////// // CLASSIC BLUETOOTH on ESP32 // | @@ -115,8 +113,10 @@ CBluetoothESP32Classic::isConnected() // | // CLASSIC BLUETOOTH on ESP32 ///////////////////////////////////////////////////////////////////////////////////////// +#endif +#if USE_BLE_BLUETOOTH == 1 ///////////////////////////////////////////////////////////////////////////////////////// // BLE on ESP32 // | @@ -327,6 +327,7 @@ CBluetoothESP32BLE::BLE_Send(std::string Data) // | // BLE on ESP32 ///////////////////////////////////////////////////////////////////////////////////////// +#endif diff --git a/Arduino/BTCDieselHeater/src/OLED/PasswordScreen.cpp b/Arduino/BTCDieselHeater/src/OLED/PasswordScreen.cpp index 292e7dc..9fcea35 100644 --- a/Arduino/BTCDieselHeater/src/OLED/PasswordScreen.cpp +++ b/Arduino/BTCDieselHeater/src/OLED/PasswordScreen.cpp @@ -50,6 +50,7 @@ bool CPasswordScreen::show() { CPasswordScreen::animate(); // precautionary, in case derived class forgets to call + if(_SaveTime) { _printInverted(_display.xCentre(), 28, " ", true, eCentreJustify); _printInverted(_display.xCentre(), 39, " ", true, eCentreJustify); diff --git a/Arduino/BTCDieselHeater/src/OLED/SettingsScreen.cpp b/Arduino/BTCDieselHeater/src/OLED/SettingsScreen.cpp new file mode 100644 index 0000000..7e288c3 --- /dev/null +++ b/Arduino/BTCDieselHeater/src/OLED/SettingsScreen.cpp @@ -0,0 +1,165 @@ +/* + * This file is part of the "bluetoothheater" distribution + * (https://gitlab.com/mrjones.id.au/bluetoothheater) + * + * Copyright (C) 2018 Ray Jones + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + + +/////////////////////////////////////////////////////////////////////////// +// +// CSettingsScreen +// +// This screen allows the fuel mixture endpoints to be adjusted +// +/////////////////////////////////////////////////////////////////////////// + +#include "SettingsScreen.h" +#include "KeyPad.h" +#include "../Protocol/helpers.h" +#include "../Wifi/BTCWifi.h" + +static const int Line3 = 20; // system voltage +static const int Line2 = 30; // fan sensor +static const int Line1 = 40; // plug drive +static const int Column = 98; + +static const int plugPowers[] = { 35, 40, 45, 80, 85, 90}; + +CSettingsScreen::CSettingsScreen(C128x64_OLED& display, CScreenManager& mgr) : CPasswordScreen(display, mgr) +{ + _animateCount = 0; +} + + +bool +CSettingsScreen::show() +{ + char str[16]; + + CScreenHeader::show(); + + _display.writeFillRect(0, 16, 96, 12, WHITE); + _printInverted(3, 18, "Heater Settings", true); + + if(!CPasswordScreen::show()) { + + sprintf(str, "%.0fV", getHeaterInfo().getSystemVoltage()); + _printMenuText(_display.width(), Line3, str, false, eRightJustify); + + sprintf(str, "Min: %.1f/%d", getHeaterInfo().getPump_Min(), getHeaterInfo().getFan_Min()); + _printMenuText(0, Line2, str); + // sprintf(str, "SN-%d", getHeaterInfo().getFan_Sensor()); + // _printMenuText(_display.width(), yPos, str, false, eRightJustify); + + sprintf(str, "Max: %.1f/%d", getHeaterInfo().getPump_Max(), getHeaterInfo().getFan_Max()); + _printMenuText(0, Line1, str); + // sprintf(str, "PF-%d", getHeaterInfo().getGlow_Drive()); + // _printMenuText(_display.width(), yPos, str, false, eRightJustify); + // navigation line + int yPos = 53; + int xPos = _display.xCentre(); + _printMenuText(xPos, yPos, "<- enter ->", true, eCentreJustify); + } + + return true; +} + +bool +CSettingsScreen::animate() +{ + char msg[16]; + + if(isPasswordBusy()) { // Password screen activity + _printMenuText(Column, Line1, " "); + _printMenuText(Column, Line2, " "); + } + else { + _animateCount++; + ROLLUPPERLIMIT(_animateCount, 9, 0); + + int glowDrive = getHeaterInfo().getGlow_Drive(); + _printMenuText(Column, Line1, " "); + if(_animateCount < 4) { + sprintf(msg, "PF-%d", glowDrive); + _printMenuText(Column+6, Line1, msg); + } + else { + sprintf(msg, "(%dW)", plugPowers[glowDrive-1]); + _printMenuText(Column, Line1, msg); + } + + int fanSensor = getHeaterInfo().getFan_Sensor(); + if(_animateCount < 4) { + sprintf(msg, "SN-%d", fanSensor); + _printMenuText(Column+6, Line2, msg); + } + else { + int xPos = Column+6; + _printMenuText(xPos, Line2, " "); // erase + _printMenuText(xPos, Line2, "("); + xPos += 6; + // . + // draw old fashioned divide symbol ----- + // . + int barOfs = 3; + _display.drawLine(xPos, Line2+barOfs, xPos+4, Line2+barOfs, WHITE); + _display.drawPixel(xPos+2, Line2+barOfs-2, WHITE); + _display.drawPixel(xPos+2, Line2+barOfs+2, WHITE); + xPos += 6; + sprintf(msg, "%d)", fanSensor); + _printMenuText(xPos, Line2, msg); + } + + } + return true; +} + +bool +CSettingsScreen::keyHandler(uint8_t event) +{ + if(CPasswordScreen::keyHandler(event)) { + if(_isPasswordOK()) { + _ScreenManager.selectSettingsScreen(true); + } + } + + else { + + if(event & keyPressed) { + // press LEFT + if(event & key_Left) { + _ScreenManager.prevScreen(); + } + // press RIGHT + if(event & key_Right) { + _ScreenManager.nextScreen(); + } + // press UP + if(event & (key_Up | key_Centre)) { + if(hasOEMcontroller()) + _reqOEMWarning(); + else { + _getPassword(); + } + } + } + } + _ScreenManager.reqUpdate(); + return true; +} + diff --git a/Arduino/BTCDieselHeater/src/OLED/SettingsScreen.h b/Arduino/BTCDieselHeater/src/OLED/SettingsScreen.h new file mode 100644 index 0000000..db01749 --- /dev/null +++ b/Arduino/BTCDieselHeater/src/OLED/SettingsScreen.h @@ -0,0 +1,40 @@ +/* + * This file is part of the "bluetoothheater" distribution + * (https://gitlab.com/mrjones.id.au/bluetoothheater) + * + * Copyright (C) 2018 Ray Jones + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef __SETTINGSSCREEN_H__ +#define __SETTINGSSCREEN_H__ + +#include +#include "PasswordScreen.h" + +class C128x64_OLED; +class CScreenManager; + +class CSettingsScreen : public CPasswordScreen { + int _animateCount; +public: + CSettingsScreen(C128x64_OLED& display, CScreenManager& mgr); + bool show(); + bool keyHandler(uint8_t event); + bool animate(); +}; + +#endif \ No newline at end of file diff --git a/Arduino/BTCDieselHeater/src/WiFi/BTCWebServer.cpp b/Arduino/BTCDieselHeater/src/WiFi/BTCWebServer.cpp index c3149ec..486f3ab 100644 --- a/Arduino/BTCDieselHeater/src/WiFi/BTCWebServer.cpp +++ b/Arduino/BTCDieselHeater/src/WiFi/BTCWebServer.cpp @@ -30,6 +30,9 @@ #include "../Utility/BTC_JSON.h" #include "../Utility/Moderator.h" #include +#if USE_SPIFFS == 1 +#include +#endif extern WiFiManager wm; @@ -41,10 +44,60 @@ bool bTxWebData = false; const int led = 13; +#if USE_SPIFFS == 1 + +String getContentType(String filename) { // convert the file extension to the MIME type + if (filename.endsWith(".html")) return "text/html"; + else if (filename.endsWith(".css")) return "text/css"; + else if (filename.endsWith(".js")) return "application/javascript"; + else if (filename.endsWith(".ico")) return "image/x-icon"; + return "text/plain"; +} + +bool handleFileRead(String path) { // send the right file to the client (if it exists) + DebugPort.println("handleFileRead: " + path); + if (path.endsWith("/")) path += "index.html"; // If a folder is requested, send the index file + String contentType = getContentType(path); // Get the MIME type + if (SPIFFS.exists(path)) { // If the file exists + File file = SPIFFS.open(path, "r"); // Open it + size_t sent = server.streamFile(file, contentType); // And send it to the client + file.close(); // Then close the file again + return true; + } + DebugPort.println("\tFile Not Found"); + return false; // If the file doesn't exist, return false +} + +void handleFavIcon() { + handleFileRead("/favicon.ico"); +/* if(SPIFFS.exists("/favicon.ico")) { + File favicon = SPIFFS.open("/favicon.ico"); + server.streamFile(favicon, "image/x-icon"); + favicon.close(); + } + else { + DebugPort.println("\"/favicon.ico\" does not exist!!!"); + }*/ +} + +void handleBTCRoot() { + handleFileRead("/index.html"); +/* if(SPIFFS.exists("/index.html")) { + File html = SPIFFS.open("/index.html"); + server.streamFile(html, "text/html"); + html.close(); + } + else { + DebugPort.println("\"/index.html\" does not exist!!!"); + }*/ +} +#else void handleBTCRoot() { String s = MAIN_PAGE; //Read HTML contents server.send(200, "text/html", s); //Send web page } +#endif + void handleWMConfig() { server.send(200, "text/plain", "Start Config Portal - Retaining credential"); @@ -89,7 +142,18 @@ void initWebServer(void) { DebugPort.println("MDNS responder started"); } +// server.serveStatic("/", SPIFFS, "/index.html"); +// server.serveStatic("/favicon.ico", SPIFFS, "/favicon.ico"); server.on("/", handleBTCRoot); +// server.on("/favicon.ico", handleFavIcon); +#if USE_SPIFFS == 1 + server.onNotFound([]() + { // If the client requests any URI + if (!handleFileRead(server.uri())) // send it if it exists + server.send(404, "text/plain", "404: Not Found"); // otherwise, respond with a 404 (Not Found) error + } + ); +#endif server.on("/wmconfig", handleWMConfig); server.on("/resetwifi",handleReset); server.onNotFound(handleBTCNotFound); diff --git a/Arduino/BTCDieselHeater/src/WiFi/mainpage.cpp b/Arduino/BTCDieselHeater/src/WiFi/mainpage.cpp index b6fcd7a..fe8b62f 100644 --- a/Arduino/BTCDieselHeater/src/WiFi/mainpage.cpp +++ b/Arduino/BTCDieselHeater/src/WiFi/mainpage.cpp @@ -21,6 +21,9 @@ */ #include +#include "../cfg/BTCConfig.h" + +#if USE_SPIFFS != 1 const char* MAIN_PAGE PROGMEM = R"=====( @@ -527,3 +530,5 @@ Timer2: