Commit 0dad2457 authored by Eric Duminil's avatar Eric Duminil
Browse files

Timer

parent 32f8968b
......@@ -31,6 +31,17 @@ namespace sensor {
Serial.println(co2);
}
void setTimer(int32_t timestep) {
if (timestep >= 2 && timestep <= 1800) {
Serial.print(F("Setting Measurement Interval to : "));
Serial.print(timestep);
Serial.println("s.");
sensor::scd30.setMeasurementInterval(timestep);
config::measurement_timestep = timestep;
led_effects::showKITTWheel(color::green, 1);
}
}
void initialize() {
#if defined(ESP8266)
Wire.begin(12, 14); // ESP8266 - D6, D5;
......@@ -76,6 +87,7 @@ namespace sensor {
Serial.println(config::auto_calibrate_sensor ? "ON." : "OFF.");
sensor_commands::defineCallback("co2", setCO2forDebugging);
sensor_commands::defineCallback("timer", setTimer);
}
//NOTE: should timer deviation be used to adjust measurement_timestep?
......
......@@ -55,20 +55,6 @@ namespace mqtt {
}
}
//TODO: Move all those setters to a separate class, which could be used by Serial/MQTT/WebServer
void setTimer(String messageString) {
messageString.replace("timer ", "");
int timestep = messageString.toInt();
if (timestep >= 2 && timestep <= 1800) {
Serial.print(F("Setting Measurement Interval to : "));
Serial.print(timestep);
Serial.println("s.");
sensor::scd30.setMeasurementInterval(messageString.toInt());
config::measurement_timestep = messageString.toInt();
led_effects::showKITTWheel(color::green, 1);
}
}
void setMQTTinterval(String messageString) {
messageString.replace("mqtt ", "");
config::sending_interval = messageString.toInt();
......@@ -101,13 +87,6 @@ namespace mqtt {
}
}
void setCO2forDebugging(String messageString) {
Serial.print(F("DEBUG. Setting CO2 to "));
messageString.replace("co2 ", "");
sensor::co2 = messageString.toInt();
Serial.println(sensor::co2);
}
void sendInfoAboutLocalNetwork() {
char info_topic[60]; // Should be enough for "CO2sensors/ESPd03cc5/info"
snprintf(info_topic, sizeof(info_topic), "%s/info", publish_topic.c_str());
......@@ -146,11 +125,7 @@ namespace mqtt {
//TODO: Move this logic to a separate class, which could be used by Serial/MQTT/WebServer
if (messageString.startsWith("co2 ")) {
setCO2forDebugging(messageString);
} else if (messageString.startsWith("timer ")) {
setTimer(messageString);
} else if (messageString == "calibrate") {
if (messageString == "calibrate") {
sensor::startCalibrationProcess();
} else if (messageString.startsWith("calibrate ")) {
calibrateSensorToSpecificPPM(messageString);
......
......@@ -5,8 +5,6 @@ namespace sensor_commands {
const uint8_t MAX_COMMAND_SIZE = 30;
uint8_t callbacks_count = 0;
// A callback contains both a function and a pointer to arbitrary data
// that will be passed as argument to the function.
struct Callback {
Callback(const char *s = 0, void (*f)(int32_t) = 0) :
name(s), function(f) {
......
......@@ -7,5 +7,6 @@
namespace sensor_commands {
void run(const char *command);
//TODO: Add defineIntCallback?
void defineCallback(const char *command, void (*f)(int32_t));
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment