diff --git a/sensor/src/sensor.ino b/sensor/src/sensor.cpp similarity index 99% rename from sensor/src/sensor.ino rename to sensor/src/sensor.cpp index 91d7d8a..c671b1e 100644 --- a/sensor/src/sensor.ino +++ b/sensor/src/sensor.cpp @@ -154,6 +154,31 @@ ArduinoQueue sendBuffer(10); // TODO: might be better bigger for large unsigned long msgStartTime; unsigned long timeSinceMsgStart; +String result = ""; +String lastRaw = ""; +String lastRaw2 = ""; +String lastRaw3 = ""; +String lastRaw4 = ""; +String lastRaw5 = ""; +String lastRaw6 = ""; +String lastFB = ""; +String lastJSON = ""; +uint32_t lastUptime = 0; +String timeString = ""; +int msgLength = 0; +boolean panelDetected = false; +const unsigned long readBytesTimeout = 2500; // Timeout in microseconds (2.5 ms) + +#include "telnet.h" +#include "webstatus.h" + +byte nibble(char c); +void hexCharacterStringToBytes(byte* byteArray, const char* hexString); +void handleMessage(size_t len, uint8_t buf[]); +String HexString2TimeString(String hexstring); +String HexString2ASCIIString(String hexstring); +void sendCommand(); + void clearRXbuffer(void) { // clear the rx buffer #if defined(ESP32) || defined(RSC3) @@ -522,20 +547,6 @@ void setup() { digitalWrite(LED_BUILTIN, LOW); } -String result = ""; -String lastRaw = ""; -String lastRaw2 = ""; -String lastRaw3 = ""; -String lastRaw4 = ""; -String lastRaw5 = ""; -String lastRaw6 = ""; -String lastFB = ""; -String lastJSON = ""; -uint32_t lastUptime = 0; -String timeString = ""; -int msgLength = 0; -boolean panelDetected = false; -const unsigned long readBytesTimeout = 2500; // Timeout in microseconds (2.5 ms) /* * waitforGLBytes checks the first byte in the serial buffer @@ -1002,10 +1013,7 @@ void hexCharacterStringToBytes(byte* byteArray, const char* hexString) { byte nibble(char c) { if (c >= '0' && c <= '9') return c - '0'; - if (c >= 'a' && c <= 'f') return c - 'a' + 10; - if (c >= 'A' && c <= 'F') return c - 'A' + 10; - return 0; // Not a valid hexadecimal character } diff --git a/sensor/src/telnet.ino b/sensor/src/telnet.h similarity index 100% rename from sensor/src/telnet.ino rename to sensor/src/telnet.h diff --git a/sensor/src/webserver.ino b/sensor/src/webstatus.h similarity index 99% rename from sensor/src/webserver.ino rename to sensor/src/webstatus.h index 6481686..2caccc2 100644 --- a/sensor/src/webserver.ino +++ b/sensor/src/webstatus.h @@ -15,6 +15,10 @@ void handleSend() { sendBuffer.enqueue(message); } +String getStatusJSON() { + return "{\"type\": \"status\", \"data\" : { \"temp\": \"" + String(tubTemp,1) + "\", \"heater\": " + (heaterState ? "true" : "false") + ", \"light\": " + (lightState ? "true" : "false") + ", \"mode\": \""+tubMode.getCurrentState()+"\", \"uptime\": " + lastUptime + ", \"state\": \"" + state + "\" } }"; +} + void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) { switch (type) { @@ -44,6 +48,3 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length } -String getStatusJSON() { - return "{\"type\": \"status\", \"data\" : { \"temp\": \"" + String(tubTemp,1) + "\", \"heater\": " + (heaterState ? "true" : "false") + ", \"light\": " + (lightState ? "true" : "false") + ", \"mode\": \""+tubMode.getCurrentState()+"\", \"uptime\": " + lastUptime + ", \"state\": \"" + state + "\" } }"; -}