Skip to content

Commit

Permalink
Merge pull request #70 from netmindz/cpp
Browse files Browse the repository at this point in the history
CPP not INO
  • Loading branch information
netmindz authored Dec 8, 2023
2 parents 0ef3352 + d134fb4 commit 4cb7c6c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
42 changes: 25 additions & 17 deletions sensor/src/sensor.ino → sensor/src/sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,31 @@ ArduinoQueue<String> 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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
File renamed without changes.
7 changes: 4 additions & 3 deletions sensor/src/webserver.ino → sensor/src/webstatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 + "\" } }";
}

0 comments on commit 4cb7c6c

Please sign in to comment.