Anonymise temp getter function

This commit is contained in:
huskee 2023-12-14 18:34:50 +02:00
parent cfd5f4e11f
commit 6e1b1db76e
2 changed files with 51 additions and 68 deletions

View file

@ -10,6 +10,7 @@
[env:esp12e]
platform = espressif8266
board = esp12e
board_build.filesystem = littlefs
framework = arduino
lib_deps =
adafruit/Adafruit MAX31855 library
@ -18,3 +19,4 @@ lib_deps =
ESPAsyncTCP
zeed/ESP Async WebServer
Arduino_JSON
monitor_filters = esp8266_exception_decoder, colorize

View file

@ -3,6 +3,7 @@
#include <Arduino_JSON.h>
#include <ESP8266WiFi.h>
#include <ESPAsyncWebServer.h>
#include <LittleFS.h>
#include <SPI.h>
#include <pinout.h>
@ -18,42 +19,25 @@ JSONVar readings;
unsigned long int lastTime = 0;
unsigned long int timerDelay = 3000;
String checkSensor(Adafruit_MAX31855 &sensor) {
if (isnan(sensor.readCelsius())) {
uint8_t err = sensor.readError();
if (err & MAX31855_FAULT_OPEN) {
return "FAULT: thermocouple open";
}
if (err & MAX31855_FAULT_SHORT_GND) {
return "FAULT: thermocouple short to GND";
}
if (err & MAX31855_FAULT_SHORT_VCC) {
return "FAULT: thermocouple short to VCC";
}
}
return String(sensor.readCelsius()) + "°C";
}
String getSensorReadings() {
if (isnan(thermocoupleA.readCelsius()) | isnan(thermocoupleB.readCelsius())) {
uint8_t eA = thermocoupleA.readError();
uint8_t eB = thermocoupleB.readError();
if (eA & MAX31855_FAULT_OPEN) {
Serial.println("FAULT: thermocouple A open");
readings["tempA"] = "FAULT: thermocouple A open";
}
if (eA & MAX31855_FAULT_SHORT_GND) {
Serial.println("FAULT: thermocouple A short to GND");
readings["tempA"] = "FAULT: thermocouple A short to GND";
}
if (eA & MAX31855_FAULT_SHORT_VCC) {
Serial.println("FAULT: thermocouple A short to VCC");
readings["tempA"] = "FAULT: thermocouple A short to VCC";
}
if (eB & MAX31855_FAULT_OPEN) {
Serial.println("FAULT: thermocouple B open");
readings["tempB"] = "FAULT: thermocouple B open";
}
if (eB & MAX31855_FAULT_SHORT_GND) {
Serial.println("FAULT: thermocouple B short to GND");
readings["tempB"] = "FAULT: thermocouple B short to GND";
}
if (eB & MAX31855_FAULT_SHORT_VCC) {
Serial.println("FAULT: thermocouple B short to VCC");
readings["tempB"] = "FAULT: thermocouple B short to VCC";
}
} else {
double tempA = thermocoupleA.readCelsius();
double tempB = thermocoupleB.readCelsius();
readings["tempA"] = String(tempA) + "°C";
readings["tempB"] = String(tempB) + "°C";
readings["tempA"] = checkSensor(thermocoupleA);
readings["tempB"] = checkSensor(thermocoupleB);
readings["time"] = String(lastTime);
}
String jsonString = JSON.stringify(readings);
return jsonString;
}
@ -104,10 +88,8 @@ void setup() {
while (!Serial) delay(1);
delay(5000); // prevent garbage on serial output
Serial.println("serial init");
if(!SPIFFS.begin()) {
delay(500);
}
Serial.printf("SPIFFS init\n");
LittleFS.begin();
Serial.printf("LittleFS init\n");
SPI.begin();
Serial.println("SPI init");
Serial.println("MAX31855 test");
@ -132,17 +114,16 @@ void setup() {
initWebSocket();
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(SPIFFS, "/index.html", "text/html");
request->send(LittleFS, "/index.html", "text/html");
});
server.onNotFound([](AsyncWebServerRequest *request) {
request->send(404, "text/plain", "404 Not Found");
});
server.serveStatic("/", SPIFFS, "/");
server.serveStatic("/", LittleFS, "/");
server.begin();
Serial.printf("webserver init\n");
}
void loop() {