From c32905663b96d4971a8c0ca3c31938a8be17ae6b Mon Sep 17 00:00:00 2001 From: Ondrej-Trochta Date: Wed, 24 Apr 2024 03:29:50 +0200 Subject: [PATCH] Working code - rewrite classes and bussines logic --- .vscode/settings.json | 1 + {src => lib}/.theia/launch.json | 0 lib/Data/DeviceBase.cpp | 3 + lib/Data/DeviceBase.h | 14 +++ lib/Data/GSMMobileData.cpp | 50 +++++++++++ {src => lib}/Data/GSMMobileData.h | 8 +- lib/Data/PinTypeIn.cpp | 8 ++ lib/Data/PinTypeIn.h | 31 +++++++ lib/Data/PinTypeOut.cpp | 21 +++++ lib/Data/PinTypeOut.h | 37 ++++++++ lib/Data/WebServerData.cpp | 48 +++++++++++ lib/Data/WebServerData.h | 22 +++++ lib/Device/EEPROMUtils.cpp | 32 +++++++ lib/Device/EEPROMUtils.h | 13 +++ lib/Device/GSMMobileDevice.cpp | 82 ++++++++++++++++++ lib/Device/GSMMobileDevice.h | 31 +++++++ lib/Device/WebServer.cpp | 66 ++++++++++++++ lib/Device/WebServer.h | 25 ++++++ lib/Helper/DebugLog.cpp | 12 +++ lib/Helper/DebugLog.h | 13 +++ lib/Helper/HTMLGenerator.cpp | 22 +++++ {src => lib}/Helper/HTMLGenerator.h | 2 +- lib/Helper/Helper.cpp | 29 +++++++ lib/Helper/Helper.h | 17 ++++ src/Data/DeviceBase.cpp | 9 -- src/Data/DeviceBase.h | 13 --- src/Data/GSMMobileData.cpp | 43 ---------- src/Data/PinTypeIn.cpp | 57 ------------- src/Data/PinTypeIn.h | 23 ----- src/Data/PinTypeOut.cpp | 59 ------------- src/Data/PinTypeOut.h | 32 ------- src/Data/WebServerData.cpp | 47 ---------- src/Data/WebServerData.h | 19 ----- src/Device/EEPROMUtils.cpp | 34 -------- src/Device/EEPROMUtils.h | 11 --- src/Device/GSMDevice.cpp | 88 ------------------- src/Device/GSMDevice.h | 29 ------- src/Device/WebServer.cpp | 68 --------------- src/Device/WebServer.h | 33 ------- src/Helper/HTMLGenerator.cpp | 25 ------ src/Utills.cpp | 10 --- src/Utills.h | 12 --- src/main.cpp | 128 ++++++++++++++++------------ 43 files changed, 658 insertions(+), 669 deletions(-) rename {src => lib}/.theia/launch.json (100%) create mode 100644 lib/Data/DeviceBase.cpp create mode 100644 lib/Data/DeviceBase.h create mode 100644 lib/Data/GSMMobileData.cpp rename {src => lib}/Data/GSMMobileData.h (68%) create mode 100644 lib/Data/PinTypeIn.cpp create mode 100644 lib/Data/PinTypeIn.h create mode 100644 lib/Data/PinTypeOut.cpp create mode 100644 lib/Data/PinTypeOut.h create mode 100644 lib/Data/WebServerData.cpp create mode 100644 lib/Data/WebServerData.h create mode 100644 lib/Device/EEPROMUtils.cpp create mode 100644 lib/Device/EEPROMUtils.h create mode 100644 lib/Device/GSMMobileDevice.cpp create mode 100644 lib/Device/GSMMobileDevice.h create mode 100644 lib/Device/WebServer.cpp create mode 100644 lib/Device/WebServer.h create mode 100644 lib/Helper/DebugLog.cpp create mode 100644 lib/Helper/DebugLog.h create mode 100644 lib/Helper/HTMLGenerator.cpp rename {src => lib}/Helper/HTMLGenerator.h (67%) create mode 100644 lib/Helper/Helper.cpp create mode 100644 lib/Helper/Helper.h delete mode 100644 src/Data/DeviceBase.cpp delete mode 100644 src/Data/DeviceBase.h delete mode 100644 src/Data/GSMMobileData.cpp delete mode 100644 src/Data/PinTypeIn.cpp delete mode 100644 src/Data/PinTypeIn.h delete mode 100644 src/Data/PinTypeOut.cpp delete mode 100644 src/Data/PinTypeOut.h delete mode 100644 src/Data/WebServerData.cpp delete mode 100644 src/Data/WebServerData.h delete mode 100644 src/Device/EEPROMUtils.cpp delete mode 100644 src/Device/EEPROMUtils.h delete mode 100644 src/Device/GSMDevice.cpp delete mode 100644 src/Device/GSMDevice.h delete mode 100644 src/Device/WebServer.cpp delete mode 100644 src/Device/WebServer.h delete mode 100644 src/Helper/HTMLGenerator.cpp delete mode 100644 src/Utills.cpp delete mode 100644 src/Utills.h diff --git a/.vscode/settings.json b/.vscode/settings.json index 55532de..30f1af8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "files.associations": { "pinsdefinitions": "c", + "new": "cpp" } diff --git a/src/.theia/launch.json b/lib/.theia/launch.json similarity index 100% rename from src/.theia/launch.json rename to lib/.theia/launch.json diff --git a/lib/Data/DeviceBase.cpp b/lib/Data/DeviceBase.cpp new file mode 100644 index 0000000..d3b8c10 --- /dev/null +++ b/lib/Data/DeviceBase.cpp @@ -0,0 +1,3 @@ +#include "DeviceBase.h" + + DeviceBase::DeviceBase(const String id): Id(id) {}; \ No newline at end of file diff --git a/lib/Data/DeviceBase.h b/lib/Data/DeviceBase.h new file mode 100644 index 0000000..f6e336f --- /dev/null +++ b/lib/Data/DeviceBase.h @@ -0,0 +1,14 @@ +#ifndef _DeviceBase_h +#define _DeviceBase_h + +#include + +class DeviceBase +{ +public: + String Id; + DeviceBase(const String id); + +}; + +#endif \ No newline at end of file diff --git a/lib/Data/GSMMobileData.cpp b/lib/Data/GSMMobileData.cpp new file mode 100644 index 0000000..dc330b9 --- /dev/null +++ b/lib/Data/GSMMobileData.cpp @@ -0,0 +1,50 @@ + +#include +#include "GSMMobileData.h" +#include "EEPROMUtils.h" +#include "DeviceBase.h" +#include "DebugLog.h" + +GSMMobileData::GSMMobileData(String id) : DeviceBase(id) +{ + readAllData(id); +} + +void GSMMobileData::readAllData(String id) +{ + EEPROMUtils eepromUtils = EEPROMUtils(); + MobileNumber = eepromUtils.readString(1, 20); + Sms = eepromUtils.readString(21, 100); + DebugLog::log("Load from EEPROM. Mobile Number: " + MobileNumber + " SMS: " + Sms); +} + +void GSMMobileData::updateMobileNumber(const String &newMobileNumber) +{ + if (newMobileNumber.length() <= 0) + { + return; + } + + if (newMobileNumber != MobileNumber) + { + EEPROMUtils eepromUtils = EEPROMUtils(); + MobileNumber = newMobileNumber; + eepromUtils.writeString(1, newMobileNumber, 20); + DebugLog::log("Update Mobile Number: " + newMobileNumber); + } +} + +void GSMMobileData::updateSMS(const String &newSMS) +{ + if (newSMS.length() <= 0) + { + return; + } + if (newSMS != Sms) + { + EEPROMUtils eepromUtils = EEPROMUtils(); + Sms = newSMS; + eepromUtils.writeString(21, newSMS, 100); + DebugLog::log("Update sms: " + newSMS); + } +} diff --git a/src/Data/GSMMobileData.h b/lib/Data/GSMMobileData.h similarity index 68% rename from src/Data/GSMMobileData.h rename to lib/Data/GSMMobileData.h index 6147c68..db64a58 100644 --- a/src/Data/GSMMobileData.h +++ b/lib/Data/GSMMobileData.h @@ -2,15 +2,19 @@ #define GSMMobileData_H #include -#include "Data/DeviceBase.h" +#include "DeviceBase.h" // Include the missing header file + class GSMMobileData : public DeviceBase { +private: + void readAllData(String id); + public: String MobileNumber; String Sms; - GSMMobileData(String id): DeviceBase(id){}; + GSMMobileData(String id); void updateMobileNumber(const String &newMobileNumber); diff --git a/lib/Data/PinTypeIn.cpp b/lib/Data/PinTypeIn.cpp new file mode 100644 index 0000000..17170a2 --- /dev/null +++ b/lib/Data/PinTypeIn.cpp @@ -0,0 +1,8 @@ +#include +#include "PinTypeIn.h" + + +bool PinTypeIn::IsPinHigh() +{ + return digitalRead(_pin) == HIGH ? true : false; +} diff --git a/lib/Data/PinTypeIn.h b/lib/Data/PinTypeIn.h new file mode 100644 index 0000000..33709eb --- /dev/null +++ b/lib/Data/PinTypeIn.h @@ -0,0 +1,31 @@ +#ifndef PinTypeIn_H +#define PinTypeIn_H + +#include +#include "DeviceBase.h" + +class PinTypeIn : public DeviceBase +{ +private: + uint8_t _pin; + unsigned long _debounceDelay; + unsigned long _lastDebounceTime; + int _lastButtonState; + int _buttonState; + +public: + const char *description; + + PinTypeIn(String id, uint8_t pin, unsigned long debounceDelay, const char *description): DeviceBase(id), _pin(pin), _debounceDelay(debounceDelay) + { + this->description = description; + pinMode(pin, INPUT); + } + + /// @brief Get Actual Pin Value if is SET = True, if is NOT SET = False + /// @return + bool IsPinHigh(); + +}; + +#endif \ No newline at end of file diff --git a/lib/Data/PinTypeOut.cpp b/lib/Data/PinTypeOut.cpp new file mode 100644 index 0000000..824dc50 --- /dev/null +++ b/lib/Data/PinTypeOut.cpp @@ -0,0 +1,21 @@ +#include "PinTypeOut.h" +#include +#include "DebugLog.h" + + +void PinTypeOut::setOutputSignalToHigh() +{ + digitalWrite(_pinNumber, HIGH); + lastState = true; +} + +void PinTypeOut::setOutputSignalToLow() +{ + digitalWrite(_pinNumber, LOW); + lastState = false; +} + +bool PinTypeOut::IsPinOn() +{ + return lastState; +} \ No newline at end of file diff --git a/lib/Data/PinTypeOut.h b/lib/Data/PinTypeOut.h new file mode 100644 index 0000000..7346bbb --- /dev/null +++ b/lib/Data/PinTypeOut.h @@ -0,0 +1,37 @@ +#ifndef PINTYPEOUT_H +#define PINTYPEOUT_H + +#include +#include "DeviceBase.h" + +class PinTypeOut : public DeviceBase +{ +private: + uint8_t _pinNumber; + bool lastState; + unsigned long _debounceTime; + unsigned long lastStateChangeTime; + + +public: + const char *description; + + PinTypeOut(String id, uint8_t pinNumber, unsigned long debounceTime, const char *description) + : DeviceBase(id), _pinNumber(pinNumber), lastState(false), _debounceTime(debounceTime), lastStateChangeTime(0), description(description) + { + pinMode(pinNumber, OUTPUT); + } + + PinTypeOut(String id, uint8_t pinNumber, const char *description) + : DeviceBase(id), _pinNumber(pinNumber), lastState(false), _debounceTime(0), lastStateChangeTime(0), description(description) + { + pinMode(pinNumber, OUTPUT); + } + + void setOutputSignalToHigh(); + void setOutputSignalToLow(); + + bool IsPinOn(); +}; + +#endif // PinTypeOut_H \ No newline at end of file diff --git a/lib/Data/WebServerData.cpp b/lib/Data/WebServerData.cpp new file mode 100644 index 0000000..e4c53bf --- /dev/null +++ b/lib/Data/WebServerData.cpp @@ -0,0 +1,48 @@ +#include "WebServerData.h" +#include +#include + +String WebServerData::getValue(const String &data, const String &key) +{ + return getValue(data, key, '&'); +} + +/// @brief Separe data PIN1=ON to PIN1 and ON +/// @param data PIN1=ON +/// @param key = +/// @param endchar end of string & or space or any other character +/// @return +String WebServerData::getValue(const String &data, const String &key, char endchar) +{ + int keyIndex = data.indexOf(key); + if (keyIndex == -1) + { + return ""; // return empty string if key is not found + } + int separatorIndex = data.indexOf(endchar, keyIndex); + + String value = data.substring(keyIndex + key.length(), separatorIndex != -1 ? separatorIndex : data.length()); + + return removeAllCharactersAfterEmptySpace(value); +} + +String WebServerData::getVariableName(const String &data, const String &key) +{ + int keyIndex = data.indexOf(key); + + String value = data.substring(0, keyIndex != -1 ? keyIndex : keyIndex); + + return removeAllCharactersAfterEmptySpace(value); +} + +String WebServerData::removeAllCharactersAfterEmptySpace(String &data) +{ + int keyIndex = data.indexOf(' '); + if (keyIndex == -1) + { + return data; // return empty string if key is not found + } + data.remove(keyIndex); + data.replace("_", " "); + return data; +} diff --git a/lib/Data/WebServerData.h b/lib/Data/WebServerData.h new file mode 100644 index 0000000..8f6038e --- /dev/null +++ b/lib/Data/WebServerData.h @@ -0,0 +1,22 @@ +#ifndef WebServerData_H +#define WebServerData_H + +#include +#include + +class WebServerData +{ +public: + EthernetClient Client; + String Request; + bool IsEmpty; + + WebServerData(EthernetClient client) : Client(client), IsEmpty(true){}; + WebServerData(EthernetClient client, String request) : Client(client), Request(request), IsEmpty(false){}; + String getValue(const String &data, const String &key, char endchar); + String getValue(const String &data, const String &key); + String removeAllCharactersAfterEmptySpace(String &data); + String getVariableName(const String &data, const String &key); +}; + +#endif // WebServerData_H \ No newline at end of file diff --git a/lib/Device/EEPROMUtils.cpp b/lib/Device/EEPROMUtils.cpp new file mode 100644 index 0000000..cdeaae7 --- /dev/null +++ b/lib/Device/EEPROMUtils.cpp @@ -0,0 +1,32 @@ +#include "EEPROMUtils.h" +#include +#include + + +// Statická metoda pro čtení řetězce z EEPROM +String EEPROMUtils::readString(int addr, int length) +{ + String data; + for (int i = 0; i < length; i++) + { + char onedata = char(EEPROM.read(addr + i)); // read one byte at a time + if (onedata == '\n') + return data; + data += onedata; + } + return data; +} + +// Statická metoda pro zápis řetězce do EEPROM +void EEPROMUtils::writeString(int addr, String data, int limit) +{ + int numBytes = data.length(); // get length of the string + for (int i = 0; i < numBytes && i < limit; i++) + { + EEPROM.write(addr + i, data[i]); // write one byte at a time + } + if (numBytes < limit) + { + EEPROM.write(addr + numBytes, '\n'); // add newline character at the end + } +} diff --git a/lib/Device/EEPROMUtils.h b/lib/Device/EEPROMUtils.h new file mode 100644 index 0000000..f7aded6 --- /dev/null +++ b/lib/Device/EEPROMUtils.h @@ -0,0 +1,13 @@ +#ifndef EEPROMUtils_h +#define EEPROMUtils_h + +#include // Include the missing header file for the String class + +class EEPROMUtils +{ +public: + static String readString(int addr, int length); + static void writeString(int addr, const String data, int limit); // Fix the function signature +}; + +#endif \ No newline at end of file diff --git a/lib/Device/GSMMobileDevice.cpp b/lib/Device/GSMMobileDevice.cpp new file mode 100644 index 0000000..54f0578 --- /dev/null +++ b/lib/Device/GSMMobileDevice.cpp @@ -0,0 +1,82 @@ +#include "GSMMobileData.h" +#include +#include "GSMMobileDevice.h" +#include "DebugLog.h" + +void GSMMobileDevice::end() +{ + _gsmSerial.end(); + DebugLog::log("GSM End .."); +} + +void GSMMobileDevice::executeAtCommand(const String &atCommand) +{ + DebugLog::log(atCommand); + _gsmSerial.print(atCommand + "\r"); + delay(500); +} + +String GSMMobileDevice::readStringSerialPort() +{ + return _gsmSerial.readString(); +} + +void GSMMobileDevice::sendSMSToGSM(GSMMobileData gsmData) +{ + DebugLog::log("SMS Start SEND SMS Id:" + gsmData.Id + " M:" + gsmData.MobileNumber + " with message " + gsmData.Sms); + + /*executeAtCommand("AT+CMGF=1"); + executeAtCommand("AT + CMGS =\"" + gsmData.MobileNumber + "\""); + executeAtCommand("ID:" + gsmData.Id + " Msg:" + gsmData.Sms); + + delay(1000); + // Send a Ctrl+Z / ASCII SUB + _gsmSerial.print((char)26); + delay(500); + // Close the connection + _gsmSerial.print((char)27);*/ + delay(500); +} + +bool GSMMobileDevice::checkSMSError() +{ + return true; + String response = readStringSerialPort(); + if (response.indexOf("ERROR") != -1) + { + // If there was an error, try to reconnect and resend + _gsmSerial.println("AT+CFUN=1,1"); // Restart the module + delay(15000); // Wait for the module to restart + return true; + } + return false; +} + +GSMMobileDevice::GSMMobileDevice(uint8_t pinRx, uint8_t pinTx, long baudRate): _gsmSerial(pinRx, pinTx) +{ + _baudRate = baudRate; + // init software serial + _gsmSerial.begin(baudRate); + DebugLog::log("GSM Init .."); + //delay(5000); // initialization GSM module (give it some time to boot up) +} + +void GSMMobileDevice::sendSMS(GSMMobileData gsmData) +{ + init(); + sendSMSToGSM(gsmData); + + if (checkSMSError()) + { + sendSMSToGSM(gsmData); + } + + end(); +} + +// GSMMobileDevice::~GSMMobileDevice() +// { +// // // close gsmSerial +// // // close gsmSerial +// _gsmSerial.end(); +// } \ No newline at end of file diff --git a/lib/Device/GSMMobileDevice.h b/lib/Device/GSMMobileDevice.h new file mode 100644 index 0000000..0f34415 --- /dev/null +++ b/lib/Device/GSMMobileDevice.h @@ -0,0 +1,31 @@ +#ifndef GSMMobileDevice_H +#define GSMMobileDevice_H + +#include "GSMMobileData.h" +#include "SoftwareSerial.h" + +class GSMMobileDevice +{ +private: + + SoftwareSerial _gsmSerial; + // Methods + void end(); + void executeAtCommand(const String &atCommand); + String readStringSerialPort(); + void sendSMSToGSM(GSMMobileData gsmData); + long _baudRate; + bool checkSMSError(); + +public: + // Constructor + GSMMobileDevice(uint8_t pinRx, uint8_t pinTx, long baudRate); + + // Destructor + //~GSMDevice(); + + // Methods + void sendSMS(GSMMobileData gsmData); +}; + +#endif // GSMDevice_H \ No newline at end of file diff --git a/lib/Device/WebServer.cpp b/lib/Device/WebServer.cpp new file mode 100644 index 0000000..b0856ba --- /dev/null +++ b/lib/Device/WebServer.cpp @@ -0,0 +1,66 @@ +#include +#include +#include "WebServerData.h" +#include "WebServer.h" +#include "DebugLog.h" + +// Constructor +WebServer::WebServer() : _server(80) {} + +WebServer::WebServer(byte mac[6], IPAddress ip, uint16_t port) : _ip(ip), _server(port) +{ + memcpy(_mac, mac, 6); +} + +// Initialize the Ethernet and start the server +void WebServer::init() +{ + DebugLog::log("Starting WebServer mac: " + String(_mac[0]) + String(_mac[1]) + ", IP: " + _ip); + Ethernet.begin(_mac, _ip); + DebugLog::log("Ethernet IP: " + Ethernet.localIP()); + _server.begin(); + DebugLog::log("Server Start"); +} + +EthernetClient client; +// Handle client requests +WebServerData WebServer::getWebServerData() +{ + // Check if a client has connected + client = _server.available(); + if (client) + { + if (client.connected()) + { + //DebugLog::log("Client connected"); + if (client.available()) + { + + String request = client.readStringUntil('\r'); + // client.flush(); // Clear the incoming buffer after reading the GET request + // If you've gotten to the end of the line (received a newline + // character) and the line is blank, the http request has ended, + // so you can send a reply + if (request.startsWith("GET")) + { + DebugLog::log("GET WEB SERVER DATA: " + request); + WebServerData webServerData = WebServerData(client, request); + return webServerData; + } + } + } + // Give the web browser time to receive the data + } + + return WebServerData(client); // Return a default-constructed WebServerData object if no client is available +} + +void WebServer::endServer() +{ + if (_server.available()) + { + delay(10); + // Close the connection + client.stop(); + } +} diff --git a/lib/Device/WebServer.h b/lib/Device/WebServer.h new file mode 100644 index 0000000..bc1d738 --- /dev/null +++ b/lib/Device/WebServer.h @@ -0,0 +1,25 @@ +#ifndef WebServer_H +#define WebServer_H + +#include +#include +#include "WebServerData.h" + +class WebServer +{ +private: + byte _mac[6]; + IPAddress _ip; + EthernetServer _server; + +public: + EthernetClient client; + + WebServer(); + WebServer(byte mac[6], IPAddress ip, uint16_t port); + WebServerData getWebServerData(); + void init(); + void endServer(); +}; + +#endif // WebServer_H \ No newline at end of file diff --git a/lib/Helper/DebugLog.cpp b/lib/Helper/DebugLog.cpp new file mode 100644 index 0000000..73058cb --- /dev/null +++ b/lib/Helper/DebugLog.cpp @@ -0,0 +1,12 @@ +#include +#include "DebugLog.h" + +void DebugLog::log(const String &log) +{ + Serial.println(log); +} + +void DebugLog::init(const long &bound) +{ + Serial.begin(bound); +} diff --git a/lib/Helper/DebugLog.h b/lib/Helper/DebugLog.h new file mode 100644 index 0000000..0cce7aa --- /dev/null +++ b/lib/Helper/DebugLog.h @@ -0,0 +1,13 @@ +#ifndef DebugLog_H +#define DebugLog_H + +#include + +class DebugLog +{ +public: + static void init(const long &bound); + static void log(const String &log); +}; + +#endif \ No newline at end of file diff --git a/lib/Helper/HTMLGenerator.cpp b/lib/Helper/HTMLGenerator.cpp new file mode 100644 index 0000000..16b150f --- /dev/null +++ b/lib/Helper/HTMLGenerator.cpp @@ -0,0 +1,22 @@ +#include +#include "HTMLGenerator.h" + +const String HTMLGenerator::GetElement(const String &tag, String &content, const String &attributes) +{ + if (attributes != "") + { + content += "<" + tag + " " + attributes + ">" + content + ""; + } + else + { + content+= "<" + tag + ">" + content + ""; + } + return content; +} + +const String HTMLGenerator::DisplayPinStatus(const String &status, const String &link, bool isOn) +{ + String element = isOn ? "H4" : "p"; + String content = status + (link != "" ? " " + (isOn ? "OFF" : "ON") + "" : ""); + return GetElement(element, content,""); +} diff --git a/src/Helper/HTMLGenerator.h b/lib/Helper/HTMLGenerator.h similarity index 67% rename from src/Helper/HTMLGenerator.h rename to lib/Helper/HTMLGenerator.h index 621b028..36f9d58 100644 --- a/src/Helper/HTMLGenerator.h +++ b/lib/Helper/HTMLGenerator.h @@ -6,7 +6,7 @@ class HTMLGenerator { public: - static const String GetElement(const String &tag, const String &content, const String &attributes = ""); + static const String GetElement(const String &tag, String &content, const String &attributes = ""); static const String DisplayPinStatus(const String &status, const String &link, bool isOn); }; diff --git a/lib/Helper/Helper.cpp b/lib/Helper/Helper.cpp new file mode 100644 index 0000000..a5bc317 --- /dev/null +++ b/lib/Helper/Helper.cpp @@ -0,0 +1,29 @@ + +#include +#include +#include "Helper.h" + +unsigned long currentTime = millis(); +unsigned long lastOverflowTime = 0; // Add missing declaration and initialization + +// Function to check for overflow and update lastOverflowTime +bool Helper::hasOverflowed() +{ + if (currentTime < lastOverflowTime) + { + lastOverflowTime = currentTime; + return true; + } + return false; +} + +// Calculate elapsed time considering overflow +unsigned long Helper::getElapsedTime() +{ + unsigned long elapsedTime = currentTime - lastOverflowTime; + if (hasOverflowed()) + { + elapsedTime += (ULONG_MAX - lastOverflowTime); // Add the time since last overflow + } + return elapsedTime; +} diff --git a/lib/Helper/Helper.h b/lib/Helper/Helper.h new file mode 100644 index 0000000..a027dcb --- /dev/null +++ b/lib/Helper/Helper.h @@ -0,0 +1,17 @@ +#ifndef HELPER_H +#define HELPER_H + +#include +#include + +class Helper +{ +private: + +public: + Helper(); + static bool hasOverflowed(); + static unsigned long getElapsedTime(); +}; + +#endif \ No newline at end of file diff --git a/src/Data/DeviceBase.cpp b/src/Data/DeviceBase.cpp deleted file mode 100644 index fca2f66..0000000 --- a/src/Data/DeviceBase.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -class DeviceBase -{ - -public: - String Id; - DeviceBase(const String id) : Id(id) {} -}; \ No newline at end of file diff --git a/src/Data/DeviceBase.h b/src/Data/DeviceBase.h deleted file mode 100644 index 0492d24..0000000 --- a/src/Data/DeviceBase.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _Device_h -#define _Device_h - -#include - -class DeviceBase -{ -public: - String Id; - DeviceBase(const String id) : Id(id) {} -}; - -#endif \ No newline at end of file diff --git a/src/Data/GSMMobileData.cpp b/src/Data/GSMMobileData.cpp deleted file mode 100644 index 589887a..0000000 --- a/src/Data/GSMMobileData.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "Data/DeviceBase.h" -#include "Device/EEPROMUtils.h" -#include - -class GSMMobileData : public DeviceBase -{ -public: - String MobileNumber; - String Sms; - - GSMMobileData(String id) : DeviceBase(id) - { - MobileNumber = EEPROMUtils::ReadString(1, 20); - Sms = EEPROMUtils::ReadString(21, 100); - } - - void updateMobileNumber(const String &newMobileNumber) - { - if (newMobileNumber.length() <= 0) - { - return; - } - - if (newMobileNumber != MobileNumber) - { - MobileNumber = newMobileNumber; - EEPROMUtils::WriteString(1, newMobileNumber, 20); - } - } - - void updateSMS(const String &newSMS) - { - if (newSMS.length() <= 0) - { - return; - } - if (newSMS != Sms) - { - Sms = newSMS; - EEPROMUtils::WriteString(21, newSMS, 100); - } - } -}; diff --git a/src/Data/PinTypeIn.cpp b/src/Data/PinTypeIn.cpp deleted file mode 100644 index ed3307f..0000000 --- a/src/Data/PinTypeIn.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include "DeviceBase.h" - -class PinTypeIn : DeviceBase -{ -private: - int pin; - unsigned long debounceDelay; - unsigned long lastDebounceTime; - int lastButtonState; - int buttonState; - const char *description; - - bool ReadValue() - { - int reading = digitalRead(pin); - - if (reading != lastButtonState) - { - lastDebounceTime = millis(); - } - - if ((millis() - lastDebounceTime) > debounceDelay) - { - if (reading != buttonState) - { - buttonState = reading; - - if (buttonState == HIGH) - { - return true; - } - } - } - - lastButtonState = reading; - return false; - } - -public: - PinTypeIn(String id, int pin, unsigned long debounceDelay, const char *description) : DeviceBase(id) - { - this->pin = pin; - this->debounceDelay = debounceDelay; - this->description = description; - - lastDebounceTime = 0; - lastButtonState = LOW; - buttonState = LOW; - pinMode(pin, INPUT); - } - - bool IsSetPinValueToHigh() - { - return ReadValue(); - } -}; diff --git a/src/Data/PinTypeIn.h b/src/Data/PinTypeIn.h deleted file mode 100644 index 39994ce..0000000 --- a/src/Data/PinTypeIn.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef PinTypeIn_H -#define PinTypeIn_H - -#include -#include - -class PinTypeIn : public DeviceBase -{ -private: - uint8_t pin; - unsigned long debounceDelay; - unsigned long lastDebounceTime; - int lastButtonState; - int buttonState; - - bool ReadValue(); - -public: - PinTypeIn(String id, int pin, unsigned long debounceDelay, const char *description): DeviceBase(id){}; - -}; - -#endif \ No newline at end of file diff --git a/src/Data/PinTypeOut.cpp b/src/Data/PinTypeOut.cpp deleted file mode 100644 index 9bd5955..0000000 --- a/src/Data/PinTypeOut.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include "DeviceBase.h" -#include "Utills.h" - -class PinTypeOut : public DeviceBase -{ -private: - uint8_t pinNumber; - bool lastState; - unsigned long debounceTime; - unsigned long lastStateChangeTime; - const char *description; - -public: - PinTypeOut(String id, uint8_t pinNumber, bool lastState, unsigned long debounceTime, const char *description) - : DeviceBase(id), pinNumber(pinNumber), lastState(lastState), debounceTime(debounceTime), lastStateChangeTime(0), description(description) - { - pinMode(pinNumber, OUTPUT); - } - - bool IsTimeIgnoredPin() - { - bool currentInputState = digitalRead(pinNumber); - if (currentInputState != lastState && millis() - lastStateChangeTime >= debounceTime) - { - lastState = currentInputState; - lastStateChangeTime = millis(); - // Add pin state change logic here - return true; - } - return false; - } - - void SetOutputSignalToHighWithtimeIgnoring() - { - if (IsTimeIgnoredPin()) - { - digitalWrite(pinNumber, HIGH); - } - } - - void SetOutputSignalToLowWithtimeIgnoring() - { - if (IsTimeIgnoredPin()) - { - digitalWrite(pinNumber, LOW); - } - } - - void SetOutputSignalToHigh() - { - digitalWrite(pinNumber, HIGH); - } - - void SetOutputSignalToLow() - { - digitalWrite(pinNumber, LOW); - } -}; diff --git a/src/Data/PinTypeOut.h b/src/Data/PinTypeOut.h deleted file mode 100644 index a70acfb..0000000 --- a/src/Data/PinTypeOut.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef PinTypeOut_H -#define PinTypeOut_H - -#include -#include "DeviceBase.h" -#include "Utills.h" - -class PinTypeOut : public DeviceBase -{ -private: - uint8_t pinNumber; - bool lastState; - unsigned long debounceTime; - unsigned long lastStateChangeTime; - const char *description; - -public: - PinTypeOut(String id, uint8_t pinNumber, bool lastState, unsigned long debounceTime, const char *description) - : DeviceBase(id), pinNumber(pinNumber), lastState(lastState), debounceTime(debounceTime), lastStateChangeTime(0), description(description) - { - }; - - /// @brief Ignoring input signal for debounce time - /// @return true is signal is ignored (debounced) - bool IsTimeIgnoredPin(); - void SetOutputSignalToHighWithtimeIgnoring(); - void SetOutputSignalToLowWithtimeIgnoring(); - void SetOutputSignalToHigh(); - void SetOutputSignalToLow(); -}; - -#endif // PinOutData_H diff --git a/src/Data/WebServerData.cpp b/src/Data/WebServerData.cpp deleted file mode 100644 index a7e41e4..0000000 --- a/src/Data/WebServerData.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include - -class WebServerData -{ -public: - EthernetClient Client; - String Request; - bool IsEmpty; - - WebServerData() - { - IsEmpty = true; - } - - WebServerData(const EthernetClient &client, const String &request) - { - Client = client; - Request = request; - IsEmpty = false; - } - - String getValue(const String &data, const String &key) - { - int keyIndex = data.indexOf(key); - if (keyIndex == -1) - { - return ""; // return empty string if key is not found - } - int separatorIndex = data.indexOf('&', keyIndex); - - String value = data.substring(keyIndex + key.length(), separatorIndex != -1 ? separatorIndex : data.length()); - - return removeAllCharactesrAfterEmpty(value); - } - - String removeAllCharactesrAfterEmpty(String &data) - { - int keyIndex = data.indexOf(' '); - if (keyIndex == -1) - { - return data; // return empty string if key is not found - } - data.remove(keyIndex); - data.replace("_", " "); - return data; - } -}; diff --git a/src/Data/WebServerData.h b/src/Data/WebServerData.h deleted file mode 100644 index 5d337c7..0000000 --- a/src/Data/WebServerData.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef WebServerData_H -#define WebServerData_H - -#include - -class WebServerData -{ -public: - EthernetClient Client; - String Request; - bool IsEmpty; - - WebServerData(); - WebServerData(EthernetClient &client, String &request); - String getValue(String &data, const String &key); - String removeAllCharactesrAfterEmpty(String &data); -}; - -#endif // WebServerData_H \ No newline at end of file diff --git a/src/Device/EEPROMUtils.cpp b/src/Device/EEPROMUtils.cpp deleted file mode 100644 index 5f1d649..0000000 --- a/src/Device/EEPROMUtils.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include - -class EEPROMUtils -{ -public: - // Statická metoda pro čtení řetězce z EEPROM - static String ReadString(int addr, int length) - { - String data; - for (int i = 0; i < length; i++) - { - char onedata = char(EEPROM.read(addr + i)); // read one byte at a time - if (onedata == '\n') - return data; - data += onedata; - } - return data; - } - - // Statická metoda pro zápis řetězce do EEPROM - static void WriteString(int addr, const String &data, int limit) - { - int numBytes = data.length(); // get length of the string - for (int i = 0; i < numBytes && i < limit; i++) - { - EEPROM.write(addr + i, data[i]); // write one byte at a time - } - if (numBytes < limit) - { - EEPROM.write(addr + numBytes, '\n'); // add newline character at the end - } - } -}; \ No newline at end of file diff --git a/src/Device/EEPROMUtils.h b/src/Device/EEPROMUtils.h deleted file mode 100644 index b3c4d8b..0000000 --- a/src/Device/EEPROMUtils.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef EEPROMUtils_h -#define EEPROMUtils_h - -class EEPROMUtils -{ -public: - static String ReadString(int addr, int length); - static void WriteString(int addr, const String &data, int limit); -}; - -#endif \ No newline at end of file diff --git a/src/Device/GSMDevice.cpp b/src/Device/GSMDevice.cpp deleted file mode 100644 index 2c6a9ca..0000000 --- a/src/Device/GSMDevice.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include "Data/GSMMobileData.h" -#include "Utills.h" -#include - -class GSMDevice -{ -private: - SoftwareSerial gsmSerial; - - void end() - { - gsmSerial.end(); - Utills::logDebug("GSM End .."); - } - - void ExecuteAtCommand(const String &atCommand) - { - Utills::logDebug(atCommand); - gsmSerial.print(atCommand + "\r"); - delay(500); - } - - String ReadStringSerialPort() - { - return gsmSerial.readString(); - } - - void sendSMSToGSM(GSMMobileData gsmData) - { - Utills::logDebug("SMS Start SEND SMS Id:" + gsmData.Id + " M:" + gsmData.MobileNumber + " with message " + gsmData.Sms); - - ExecuteAtCommand("AT+CMGF=1"); - ExecuteAtCommand("AT + CMGS =\"" + gsmData.MobileNumber + "\""); - ExecuteAtCommand("ID:" + gsmData.Id + " Msg:" + gsmData.Sms); - - delay(1000); - // Send a Ctrl+Z / ASCII SUB - gsmSerial.print((char)26); - delay(500); - // Close the connection - gsmSerial.print((char)27); - delay(500); - } - - bool CheckSMSError() - { - String response = ReadStringSerialPort(); - if (response.indexOf("ERROR") != -1) - { - // If there was an error, try to reconnect and resend - gsmSerial.println("AT+CFUN=1,1"); // Restart the module - delay(15000); // Wait for the module to restart - return true; - } - return false; - } - -public: - - GSMDevice(uint8_t pinRx, uint8_t pinTx, long baudRate): gsmSerial(pinRx, pinTx) - { - //init software serial - gsmSerial.begin(baudRate); - Utills::logDebug("GSM Init .."); - delay(5000); // initialization GSM module (give it some time to boot up) - } - - - void sendSMS(GSMMobileData gsmData) - { - init(); - sendSMSToGSM(gsmData); - - if (CheckSMSError()) - { - sendSMSToGSM(gsmData); - } - - end(); - } - - // ~GSMDevice() - // { - // // close gsmSerial - // // close gsmSerial - // gsmSerial.end(); - // } -}; \ No newline at end of file diff --git a/src/Device/GSMDevice.h b/src/Device/GSMDevice.h deleted file mode 100644 index b7b7bd4..0000000 --- a/src/Device/GSMDevice.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef GSMDevice_H -#define GSMDevice_H - -#include "Data/GSMMobileData.h" -#include "SoftwareSerial.h" - - -class GSMDevice -{ -private: - SoftwareSerial gsmSerial; - // Methods - void end(); - void ExecuteAtCommand(const String &atCommand); - String ReadStringSerialPort(); - void sendSMSToGSM(GSMMobileData gsmData); - -public: - // Constructor - GSMDevice(uint8_t pinRx, uint8_t pinTx, long baudRate): gsmSerial(pinRx, pinTx){}; - - // Destructor - // ~GSMDevice(); - - // Methods - void sendSMS(GSMMobileData gsmData); -}; - -#endif // GSMDevice_H \ No newline at end of file diff --git a/src/Device/WebServer.cpp b/src/Device/WebServer.cpp deleted file mode 100644 index 5af0050..0000000 --- a/src/Device/WebServer.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include -#include "Data/WebServerData.h" - -class WebServer -{ -private: - byte mac[6]; - IPAddress ip; - EthernetServer server; - // Event - // Define the callback function type - - // Declare a function pointer - // void (*Callback)(WebServerData) = WebBrowserDataCallback; -public: - EthernetClient client; - // Constructor - WebServer() : server(80) {} - - WebServer(byte mac[6], IPAddress ip, uint16_t port) : ip(ip), server(port) - { - memcpy(this->mac, mac, sizeof(this->mac)); - } - - // Initialize the Ethernet and start the server - void WebServer::Init() - { - Ethernet.begin(mac, ip); - server.begin(); - } - - // Handle client requests - WebServerData GetWebServerData() - { - // Check if a client has connected - client = server.available(); - if (client) - { - if (client.connected()) - { - while (client.available()) - { - String request = client.readStringUntil('\r'); - // If you've gotten to the end of the line (received a newline - // character) and the line is blank, the http request has ended, - // so you can send a reply - - WebServerData webServerData = WebServerData(client, request); - return webServerData; - } - } - // Give the web browser time to receive the data - } - - return WebServerData(); // Return a default-constructed WebServerData object if no client is available - } - - void WebServer::EndServer() - { - if (server.available()) - { - delay(10); - // Close the connection - client.stop(); - } - } -}; diff --git a/src/Device/WebServer.h b/src/Device/WebServer.h deleted file mode 100644 index fe7668a..0000000 --- a/src/Device/WebServer.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef WebServer_H -#define WebServer_H - -#include -#include -#include "Data/WebServerData.h" - -class WebServer -{ -private: - byte mac[6]; - IPAddress ip; - EthernetServer server; - // Define the callback function type - -public: - EthernetClient client; - // Constructor - WebServer() : server(80) {} - WebServer(byte mac[6], IPAddress ip, uint16_t port) : ip(ip), server(port) - { - memcpy(this->mac, mac, sizeof(this->mac)); - } - - // Initialize the Ethernet and start the server - void Init(); - - // Handle client requests - WebServerData GetWebServerData(); - void EndServer(); -}; - -#endif // WebServer_H \ No newline at end of file diff --git a/src/Helper/HTMLGenerator.cpp b/src/Helper/HTMLGenerator.cpp deleted file mode 100644 index 3a8c007..0000000 --- a/src/Helper/HTMLGenerator.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include - -class HTMLGenerator -{ -public: - static const String GetElement(const String &tag, const String &content, const String &attributes = "") - { - String html_content = ""; - if (attributes != "") - { - return "<" + tag + " " + attributes + ">" + content + ""; - } - else - { - return "<" + tag + ">" + content + ""; - } - } - - static const String DisplayPinStatus(const String &status, const String &link, bool isOn) - { - String element = isOn ? "H4" : "p"; - String content = status + (link != "" ? " " + (isOn ? "OFF" : "ON") + "" : ""); - return GetElement(element, content); - } -}; \ No newline at end of file diff --git a/src/Utills.cpp b/src/Utills.cpp deleted file mode 100644 index 05219bc..0000000 --- a/src/Utills.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include - -class Utills -{ - public: - static void logDebug(const String& log) - { - Serial.println(log); - } -}; \ No newline at end of file diff --git a/src/Utills.h b/src/Utills.h deleted file mode 100644 index b9d25f2..0000000 --- a/src/Utills.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef Utills_H -#define Utills_H - -class Utills { -public: -static void logDebug(const String& log) { - // Implementation of the logDebug function goes here - // You can add your desired functionality inside this function -} -}; - -#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index b09afd5..fd524c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,16 +1,19 @@ -#include "Device/GSMDevice.h" -#include "Device/WebServer.h" -#include "Data/PinTypeIn.h" -#include "Data/PinTypeOut.h" -#include "Utills.h" +#include "GSMMobileDevice.h" +#include "WebServer.h" +#include "PinTypeIn.h" +#include "PinTypeOut.h" #include #include #include +#include "WebServer.h" +#include "WebServerData.h" +#include "DebugLog.h" +#include "HTMLGenerator.h" // PIN INPUT Initialization as OUTPUT static const int COUNT_OUTPUTS_PIN_OUT = 2; -static PinTypeOut PinIn8 = PinTypeOut("PIN8", 8, LOW, 10000, "Electric Alarm"); -static PinTypeOut PinIn7 = PinTypeOut("PIN7", 7, LOW, 100, "Default Description"); +static PinTypeOut PinIn8 = PinTypeOut("PIN8", 8, "Electric Alarm"); +static PinTypeOut PinIn7 = PinTypeOut("PIN7", 7, "Default Description"); static const PinTypeOut OUPUTS_PINS_ARRAY[COUNT_OUTPUTS_PIN_OUT] = {PinIn8, PinIn7}; // PIN INPUT Initialization as INPUT @@ -19,7 +22,7 @@ static PinTypeIn PinIn2 = PinTypeIn("PIN2", 2, 100, "Input EZS ALARM"); // 100ms static PinTypeIn PinIn3 = PinTypeIn("PIN3", 3, 100, "Input Contact Box"); static const PinTypeIn INPUTS_PINS_ARRAY[COUNT_INPUTS_PIN_IN] = {PinIn2, PinIn3}; -// GSM Serial Port +// // GSM Serial Port static const uint8_t GSM_PIN_RX = 10; static const uint8_t GSM_PIN_TX = 11; static const long GSM_BAUD_RATE = 115200; @@ -28,89 +31,86 @@ static const long GSM_BAUD_RATE = 115200; static byte WebServerMac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; static IPAddress WebServerIP = IPAddress(192, 168, 1, 177); static const byte WebServerPort = 80; -// Devices +// // Devices -GSMDevice gsmDevice = GSMDevice(GSM_PIN_RX, GSM_PIN_TX, GSM_BAUD_RATE); -// Pin Input +GSMMobileDevice gsmDevice = GSMMobileDevice(GSM_PIN_RX, GSM_PIN_TX, GSM_BAUD_RATE); +// // Pin Input GSMMobileData gsmData = GSMMobileData("GSM"); WebServer webServer; - void SeparateDataFromRequest(WebServerData &request) { - if (request.Request.indexOf("GET /?id=GSM") != -1) + + int indexofHttp = request.Request.indexOf(" HTTP"); + if (indexofHttp == -1) { - Utills::logDebug("it is GSM"); + DebugLog::log("ERROR: HTTP not found in GET Header!"); + return; + } + + DebugLog::log("SeparateDataFromRequest: " + request.Request); + if (request.Request.indexOf("GET /id=GSM") != -1) + { + DebugLog::log("it is GSM"); // int start = request.indexOf("/?id=") + 2; - String data = request.Request.substring(6); - Utills::logDebug("Update Data from GET: " + data); + String data = request.Request.substring(5); + DebugLog::log("Update Data from GET: " + data); String value = request.getValue(data, "mobileNumber="); gsmData.updateMobileNumber(value); value = request.getValue(data, "sms="); gsmData.updateSMS(value); } - - if (request.Request.indexOf("/PIN") == -1) + int indexPin = request.Request.indexOf("/PIN"); + if (indexPin != -1) { - String pinName = request.Request.substring(5, 4); - Utills::logDebug("Update Data from GET as PIN : " + pinName); + String pinName = request.Request.substring(indexPin + 1, indexofHttp); + DebugLog::log("GET as PIN [" + pinName + "]"); // foreach OUPUTS_PINS_ARRAY for (int i = 0; i < COUNT_OUTPUTS_PIN_OUT; i++) { + String actualPinName = request.getVariableName(pinName, "="); PinTypeOut pinValue = OUPUTS_PINS_ARRAY[i]; - if (pinValue.Id == pinName) - { - Utills::logDebug("Update Data from GET as PIN : " + pinName); + DebugLog::log("Compare Pin [" + actualPinName + "] with [" + pinValue.Id + "]"); + if (pinValue.Id == actualPinName) + { + DebugLog::log("Update GET as PIN : " + actualPinName); if (request.Request.indexOf("=ON") != -1) { - pinValue.SetOutputSignalToHighWithtimeIgnoring(); + DebugLog::log("Set " + actualPinName + "=ON"); + pinValue.setOutputSignalToHigh(); } if (request.Request.indexOf("=OFF") != -1) { - pinValue.SetOutputSignalToLowWithtimeIgnoring(); + DebugLog::log("Set " + actualPinName + "=OFF"); + pinValue.setOutputSignalToLow(); } } } } } -void WebServerEvent(WebServerData data) +void WebServerEvent(WebServerData &data) { // Your function implementation here - Utills::logDebug("Request: " + data.Request); SeparateDataFromRequest(data); } void setup() { + DebugLog::init(115200); + DebugLog::log("Called: Setup"); webServer = WebServer(WebServerMac, WebServerIP, WebServerPort); - // serial monitori init and set baud rate - Serial.begin(9600); - webServer.Init(); - Utills::logDebug("Called: Setup"); + // // serial monitori init and set baud rate + + webServer.init(); + DebugLog::log("Web Server Initilized"); } -void GenerateHtml(WebServerData data); - -void loop() -{ - WebServerData data = webServer.GetWebServerData(); - if (!data.IsEmpty) - { - WebServerEvent(data); - } - - if (data.Client.available()) - { - GenerateHtml(data); - } -} - -void GenerateHtml(WebServerData data) +void GenerateHtml(WebServerData &data) { EthernetClient client = data.Client; client.println("HTTP/1.1 200 OK"); @@ -121,20 +121,40 @@ void GenerateHtml(WebServerData data) client.println(" body { display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0;}"); client.println(".content {text-align: center;}"); + for (int i = 0; i < COUNT_OUTPUTS_PIN_OUT; i++) + { + PinTypeOut pinValue = OUPUTS_PINS_ARRAY[i]; + HTMLGenerator::DisplayPinStatus(pinValue.Id + "|" + pinValue.description, pinValue.Id, pinValue.IsPinOn()); + } + + for (int i = 0; i < COUNT_INPUTS_PIN_IN; i++) + { + PinTypeIn pinValue = INPUTS_PINS_ARRAY[i]; + HTMLGenerator::DisplayPinStatus(pinValue.Id + "|" + pinValue.description,"", pinValue.IsPinHigh()); + } + client.println(""); client.println("
"); client.println("

Trochta.net:

"); + client.println("
"); + client.stop(); } -int main() +void loop() { - setup(); - while (true) + // DebugLog::log("Called: Loop"); + WebServerData data = webServer.getWebServerData(); + if (!data.IsEmpty) { - loop(); + WebServerEvent(data); } - return 0; -} \ No newline at end of file + + if (data.Client.available()) + { + GenerateHtml(data); + data.Client.stop(); + } +}