Commit 579440cb authored by Eric Duminil's avatar Eric Duminil
Browse files

More commands

parent c65e5fcf
...@@ -75,7 +75,11 @@ namespace sensor { ...@@ -75,7 +75,11 @@ namespace sensor {
sensor_commands::defineIntCallback("timer", setTimer, " 30 (Sets measurement interval, in s)"); sensor_commands::defineIntCallback("timer", setTimer, " 30 (Sets measurement interval, in s)");
sensor_commands::defineIntCallback("calibrate", calibrateSensorToSpecificPPM, sensor_commands::defineIntCallback("calibrate", calibrateSensorToSpecificPPM,
" 600 (Starts calibration process, to given ppm)"); " 600 (Starts calibration process, to given ppm)");
sensor_commands::defineIntCallback("calibrate!", calibrateSensorRightNow, " 600 (Calibrates right now, to given ppm)"); sensor_commands::defineIntCallback("calibrate!", calibrateSensorRightNow,
" 600 (Calibrates right now, to given ppm)");
sensor_commands::defineCallback("reset", []() {
ESP.restart();
}, " (Restarts the sensor)");
} }
//NOTE: should timer deviation be used to adjust measurement_timestep? //NOTE: should timer deviation be used to adjust measurement_timestep?
......
...@@ -127,7 +127,7 @@ namespace csv_writer { ...@@ -127,7 +127,7 @@ namespace csv_writer {
sensor_commands::defineCallback("hello", []() { sensor_commands::defineCallback("hello", []() {
Serial.println("SAY HELLO"); Serial.println("SAY HELLO");
}, " (Say Hello;)"); }, " (Say Hello;)");
sensor_commands::defineCallback("format_filesystem", formatFilesystem, " (Deletes the whole filesystem.)"); sensor_commands::defineCallback("format_filesystem", formatFilesystem, " (Deletes the whole filesystem)");
} }
File openOrCreate() { File openOrCreate() {
......
...@@ -37,10 +37,8 @@ namespace mqtt { ...@@ -37,10 +37,8 @@ namespace mqtt {
mqttClient.setServer(config::mqtt_server, config::mqtt_port); mqttClient.setServer(config::mqtt_server, config::mqtt_port);
sensor_commands::defineIntCallback("mqtt", setMQTTinterval, " 60 (Sets MQTT sending interval, in s)"); sensor_commands::defineIntCallback("mqtt", setMQTTinterval, " 60 (Sets MQTT sending interval, in s)");
sensor_commands::defineCallback("publish", []() { sensor_commands::defineCallback("local_ip", sendInfoAboutLocalNetwork,
Serial.println(F("Forcing MQTT publish now.")); " (Sends local IP and SSID via MQTT. Can be useful to find sensor)");
last_sent_at = -config::sending_interval;
}, " (Force publish now)");
} }
void publish(const String &timestamp, int16_t co2, float temperature, float humidity) { void publish(const String &timestamp, int16_t co2, float temperature, float humidity) {
...@@ -61,17 +59,6 @@ namespace mqtt { ...@@ -61,17 +59,6 @@ namespace mqtt {
} }
} }
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());
char payload[75]; // Should be enough for info json...
const char *json_info_format = PSTR("{\"local_ip\":\"%s\", \"ssid\":\"%s\"}");
snprintf(payload, sizeof(payload), json_info_format, WiFi.localIP().toString().c_str(), WiFi.SSID().c_str());
mqttClient.publish(info_topic, payload);
}
/** /**
* Allows sensor to be controlled by commands over MQTT * Allows sensor to be controlled by commands over MQTT
* *
...@@ -103,10 +90,6 @@ namespace mqtt { ...@@ -103,10 +90,6 @@ namespace mqtt {
if (messageString == "night_mode") { if (messageString == "night_mode") {
led_effects::toggleNightMode(); led_effects::toggleNightMode();
} else if (messageString == "local_ip") {
sendInfoAboutLocalNetwork();
} else if (messageString == "reset") {
ESP.restart(); // softer than ESP.reset()
} }
} }
...@@ -174,4 +157,18 @@ namespace mqtt { ...@@ -174,4 +157,18 @@ namespace mqtt {
Serial.println("s."); Serial.println("s.");
led_effects::showKITTWheel(color::green, 1); led_effects::showKITTWheel(color::green, 1);
} }
// It can be hard to find the local IP of a sensor if it isn't connected to Serial port, and if mDNS is disabled.
// If the sensor can be reach by MQTT, it can answer with info about local_ip and ssid.
// The sensor will send the info to "CO2sensors/ESP123456/info".
void sendInfoAboutLocalNetwork() {
char info_topic[60]; // Should be enough for "CO2sensors/ESP123456/info"
snprintf(info_topic, sizeof(info_topic), "%s/info", publish_topic.c_str());
char payload[75]; // Should be enough for info json...
const char *json_info_format = PSTR("{\"local_ip\":\"%s\", \"ssid\":\"%s\"}");
snprintf(payload, sizeof(payload), json_info_format, WiFi.localIP().toString().c_str(), WiFi.SSID().c_str());
mqttClient.publish(info_topic, payload);
}
} }
...@@ -18,5 +18,6 @@ namespace mqtt { ...@@ -18,5 +18,6 @@ namespace mqtt {
void publishIfTimeHasCome(const String &timeStamp, const int16_t &co2, const float &temp, const float &hum); void publishIfTimeHasCome(const String &timeStamp, const int16_t &co2, const float &temp, const float &hum);
void setMQTTinterval(int32_t sending_interval); void setMQTTinterval(int32_t sending_interval);
void sendInfoAboutLocalNetwork();
} }
#endif #endif
...@@ -282,9 +282,9 @@ namespace web_server { ...@@ -282,9 +282,9 @@ namespace web_server {
if (!shouldBeAllowed()) { if (!shouldBeAllowed()) {
return http.requestAuthentication(DIGEST_AUTH); return http.requestAuthentication(DIGEST_AUTH);
} }
sensor_commands::run(http.arg("send").c_str());
http.sendHeader("Location", "/"); http.sendHeader("Location", "/");
http.send(303); http.send(303);
sensor_commands::run(http.arg("send").c_str());
} }
void handlePageNotFound() { void handlePageNotFound() {
......
Markdown is supported
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