Anonymise temp getter function
This commit is contained in:
parent
cfd5f4e11f
commit
6e1b1db76e
|
@ -10,6 +10,7 @@
|
||||||
[env:esp12e]
|
[env:esp12e]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = esp12e
|
board = esp12e
|
||||||
|
board_build.filesystem = littlefs
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps =
|
lib_deps =
|
||||||
adafruit/Adafruit MAX31855 library
|
adafruit/Adafruit MAX31855 library
|
||||||
|
@ -18,3 +19,4 @@ lib_deps =
|
||||||
ESPAsyncTCP
|
ESPAsyncTCP
|
||||||
zeed/ESP Async WebServer
|
zeed/ESP Async WebServer
|
||||||
Arduino_JSON
|
Arduino_JSON
|
||||||
|
monitor_filters = esp8266_exception_decoder, colorize
|
||||||
|
|
73
src/main.cpp
73
src/main.cpp
|
@ -3,6 +3,7 @@
|
||||||
#include <Arduino_JSON.h>
|
#include <Arduino_JSON.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
|
#include <LittleFS.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <pinout.h>
|
#include <pinout.h>
|
||||||
|
|
||||||
|
@ -18,42 +19,25 @@ JSONVar readings;
|
||||||
|
|
||||||
unsigned long int lastTime = 0;
|
unsigned long int lastTime = 0;
|
||||||
unsigned long int timerDelay = 3000;
|
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() {
|
String getSensorReadings() {
|
||||||
if (isnan(thermocoupleA.readCelsius()) | isnan(thermocoupleB.readCelsius())) {
|
readings["tempA"] = checkSensor(thermocoupleA);
|
||||||
uint8_t eA = thermocoupleA.readError();
|
readings["tempB"] = checkSensor(thermocoupleB);
|
||||||
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["time"] = String(lastTime);
|
readings["time"] = String(lastTime);
|
||||||
}
|
|
||||||
String jsonString = JSON.stringify(readings);
|
String jsonString = JSON.stringify(readings);
|
||||||
return jsonString;
|
return jsonString;
|
||||||
}
|
}
|
||||||
|
@ -63,13 +47,13 @@ void notifyClients(String sensorReadings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleWebSocketMessage(void *arg, uint8_t *data, size_t len) {
|
void handleWebSocketMessage(void *arg, uint8_t *data, size_t len) {
|
||||||
AwsFrameInfo *info = (AwsFrameInfo*)arg;
|
AwsFrameInfo *info = (AwsFrameInfo *)arg;
|
||||||
if (info->final && info->index == 0 && info->len == len && info->opcode == WS_TEXT) {
|
if (info->final && info->index == 0 && info->len == len && info->opcode == WS_TEXT) {
|
||||||
//data[len] = 0;
|
// data[len] = 0;
|
||||||
//String message = (char*)data;
|
// String message = (char*)data;
|
||||||
// Check if the message is "getReadings"
|
// Check if the message is "getReadings"
|
||||||
//if (strcmp((char*)data, "getReadings") == 0) {
|
// if (strcmp((char*)data, "getReadings") == 0) {
|
||||||
//if it is, send current sensor readings
|
// if it is, send current sensor readings
|
||||||
String sensorReadings = getSensorReadings();
|
String sensorReadings = getSensorReadings();
|
||||||
Serial.print(sensorReadings);
|
Serial.print(sensorReadings);
|
||||||
notifyClients(sensorReadings);
|
notifyClients(sensorReadings);
|
||||||
|
@ -104,10 +88,8 @@ void setup() {
|
||||||
while (!Serial) delay(1);
|
while (!Serial) delay(1);
|
||||||
delay(5000); // prevent garbage on serial output
|
delay(5000); // prevent garbage on serial output
|
||||||
Serial.println("serial init");
|
Serial.println("serial init");
|
||||||
if(!SPIFFS.begin()) {
|
LittleFS.begin();
|
||||||
delay(500);
|
Serial.printf("LittleFS init\n");
|
||||||
}
|
|
||||||
Serial.printf("SPIFFS init\n");
|
|
||||||
SPI.begin();
|
SPI.begin();
|
||||||
Serial.println("SPI init");
|
Serial.println("SPI init");
|
||||||
Serial.println("MAX31855 test");
|
Serial.println("MAX31855 test");
|
||||||
|
@ -132,17 +114,16 @@ void setup() {
|
||||||
initWebSocket();
|
initWebSocket();
|
||||||
|
|
||||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
|
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
request->send(SPIFFS, "/index.html", "text/html");
|
request->send(LittleFS, "/index.html", "text/html");
|
||||||
});
|
});
|
||||||
|
|
||||||
server.onNotFound([](AsyncWebServerRequest *request) {
|
server.onNotFound([](AsyncWebServerRequest *request) {
|
||||||
request->send(404, "text/plain", "404 Not Found");
|
request->send(404, "text/plain", "404 Not Found");
|
||||||
});
|
});
|
||||||
|
|
||||||
server.serveStatic("/", SPIFFS, "/");
|
server.serveStatic("/", LittleFS, "/");
|
||||||
server.begin();
|
server.begin();
|
||||||
Serial.printf("webserver init\n");
|
Serial.printf("webserver init\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
Loading…
Reference in a new issue