make sampling periode configurable
This commit is contained in:
parent
7b1d9ae63e
commit
7cac6f89f1
@ -16,12 +16,12 @@
|
||||
generic_33v_300s_28d
|
||||
*/
|
||||
const uint8_t bsec_config_iaq[] = {
|
||||
#if CONFIG_SAMPLING_PERIODE_MS == 3000
|
||||
#if CONFIG_SAMPLING_PERIOD_MS == 3000
|
||||
#include "config/generic_33v_3s_4d/bsec_iaq.txt"
|
||||
#elif CONFIG_SAMPLING_PERIODE_MS == 300000
|
||||
#elif CONFIG_SAMPLING_PERIOD_MS == 300000
|
||||
#include "config/generic_33v_300s_4d/bsec_iaq.txt"
|
||||
#else
|
||||
#error "Unsupport CONFIG_SAMPLING_PERIODE_MS (3000 and 300000 are supported)"
|
||||
#error "Unsupport CONFIG_SAMPLING_PERIOD_MS (3000 and 300000 are supported)"
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -17,6 +17,7 @@ typedef struct productConfig_t {
|
||||
uint32_t dns2;
|
||||
uint8_t channel;
|
||||
char *bssid;
|
||||
uint32_t samplingPeriod;
|
||||
|
||||
} productConfig;
|
||||
|
||||
|
@ -24,7 +24,7 @@ int EepromSaveConfig(productConfig &config) {
|
||||
+ String(config.ip_mode) + ";"
|
||||
+ config.ip + ";" + config.gw + ";" + config.mask + ";"
|
||||
+ config.dns + ";" + config.dns2 + ";" + config.channel + ";"
|
||||
+ config.bssid + ";";
|
||||
+ config.bssid + ";" + config.samplingPeriod + ";";
|
||||
|
||||
if (eeprom.length() > CONFIG_EEPROM_SIZE )
|
||||
return -EMSGSIZE;
|
||||
@ -104,6 +104,8 @@ void EepromReadConfig(productConfig &config) {
|
||||
readConfElement(&tmpString, i);
|
||||
config.channel = atoi(tmpString);
|
||||
readConfElement(&config.bssid, i);
|
||||
readConfElement(&tmpString, i);
|
||||
config.samplingPeriod = atoi(tmpString);
|
||||
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ void WebHandleRoot() {
|
||||
}
|
||||
|
||||
server.send(200, "text/html",
|
||||
"<head><meta http-equiv=\"refresh\" content=\"" + String(CONFIG_SAMPLING_PERIODE_MS / 1000) + "\" ></head>"
|
||||
"<head><meta http-equiv=\"refresh\" content=\"" + String(CONFIG_SAMPLING_PERIOD_MS / 1000) + "\" ></head>"
|
||||
"<h1>You are connected to " + String(conf.host) + "</h1>"
|
||||
"<fieldset>"
|
||||
"<legend>Sensors</legend>"
|
||||
@ -129,6 +129,10 @@ void WebHandleSetup() {
|
||||
"<div><label for=\"mqttPasswd\">Password :</label><br/><input type=\"password\" name=\"mqttPasswd\" style=\"border-color:red\" value=\"" + String(conf.mqttPasswd) + "\" /> </div>"
|
||||
"<div><label for=\"mqttPort\">Port :</label><br/><input type=\"text\" name=\"mqttPort\" value=\"" + String(conf.mqttPort) + "\" /> (8883 for secure Mqtts) </div>"
|
||||
"</fieldset>"
|
||||
"<fieldset>"
|
||||
"<legend>Sensor:</legend>"
|
||||
"<div><label for=\"samplingPeriod\">Sampling Period (ms): </label><br/><input type=\"text\" name=\"samplingPeriod\" value=\"" + String(conf.samplingPeriod) + "\" /> </div>"
|
||||
"</fieldset>"
|
||||
"<div class=\"button\"> <button type=\"submit\">Save</button></div>"
|
||||
"</form>");
|
||||
}
|
||||
@ -172,7 +176,7 @@ void WebHandleSave() {
|
||||
|| !server.hasArg("mqttServer") || !server.hasArg("mqttUser") || !server.hasArg("mqttPasswd")
|
||||
|| !server.hasArg("mqttPort") || !server.hasArg("ip_config") || !server.hasArg("ip")
|
||||
|| !server.hasArg("gw") || !server.hasArg("mask") || !server.hasArg("dns")
|
||||
|| !server.hasArg("dns2") || !server.hasArg("channel") || ! server.hasArg("bssid")) {
|
||||
|| !server.hasArg("dns2") || !server.hasArg("channel") || !server.hasArg("bssid") || !server.hasArg("samplingPeriod")) {
|
||||
server.send(500, "text/plain", "Bad arguments\r\n");
|
||||
return;
|
||||
}
|
||||
@ -187,16 +191,28 @@ void WebHandleSave() {
|
||||
}
|
||||
}
|
||||
|
||||
productConfig newConf = {BOOTMODE_NORMAL, strdup(server.arg("ssid").c_str()), strdup(server.arg("password").c_str()),
|
||||
strdup(server.arg("host").c_str()), strdup(server.arg("mqttServer").c_str()), strdup(server.arg("mqttUser").c_str()),
|
||||
strdup(server.arg("mqttPasswd").c_str()), server.arg("mqttPort").toInt(),
|
||||
server.arg("ip_config").toInt(), static_cast<uint32_t>(ip), static_cast<uint32_t>(gw),
|
||||
static_cast<uint32_t>(mask), static_cast<uint32_t>(dns), static_cast<uint32_t>(dns2), static_cast<uint8_t>(server.arg("channel").toInt()), strdup(server.arg("bssid").c_str())
|
||||
};
|
||||
productConfig newConf = {BOOTMODE_NORMAL,
|
||||
strdup(server.arg("ssid").c_str()),
|
||||
strdup(server.arg("password").c_str()),
|
||||
strdup(server.arg("host").c_str()),
|
||||
strdup(server.arg("mqttServer").c_str()),
|
||||
strdup(server.arg("mqttUser").c_str()),
|
||||
strdup(server.arg("mqttPasswd").c_str()),
|
||||
server.arg("mqttPort").toInt(),
|
||||
server.arg("ip_config").toInt(),
|
||||
static_cast<uint32_t>(ip),
|
||||
static_cast<uint32_t>(gw),
|
||||
static_cast<uint32_t>(mask),
|
||||
static_cast<uint32_t>(dns),
|
||||
static_cast<uint32_t>(dns2),
|
||||
static_cast<uint8_t>(server.arg("channel").toInt()),
|
||||
strdup(server.arg("bssid").c_str()),
|
||||
static_cast<uint32_t>(server.arg("samplingPeriod").toInt())};
|
||||
if (EepromSaveConfig(newConf) < 0) {
|
||||
WebSendError("Cannot Save Credentials (Too long ?Contains \";\"?)\r\n");
|
||||
WebSendError("Cannot Save configuration ( Credentials too long ?Contains \";\"?)\r\n");
|
||||
return;
|
||||
}
|
||||
samplingPeriod = newConf.samplingPeriod;
|
||||
if (WiFi.softAPIP() != IPAddress((uint32_t)0)) {
|
||||
//In STA mode, we can test the AP connection
|
||||
WiFi.begin(server.arg("ssid").c_str(), server.arg("password").c_str());
|
||||
|
@ -69,12 +69,14 @@ float bme680BSECT, bme680BSECP, bme680BSECH, bme680BSECIaq, bme680BSECIaqAcc;
|
||||
int dryness;
|
||||
uint8_t mode;
|
||||
int reconfig = 0;
|
||||
productConfig conf = {BOOTMODE_SETUP, NULL, NULL, NULL, NULL, NULL, NULL, 1883, 0, 0, 0, 0, 0, 0, 0, NULL};
|
||||
productConfig conf = {BOOTMODE_SETUP, NULL, NULL, NULL, NULL, NULL, NULL, 1883, 0, 0, 0, 0, 0, 0, 0, NULL, CONFIG_SAMPLING_PERIOD_MS};
|
||||
// Should have less that MAXSUBSCRIPTIONS elements
|
||||
// MAXSUBSCRIPTIONS is defined is Adafruit_mqtt.h
|
||||
const int gpioControlled[] = CONFIG_CONTROLLED_GPIO;
|
||||
const int gpioObserved[] = CONFIG_OBSERVED_GPIO;
|
||||
const int pwmControlled[] = CONFIG_CONTROLLED_PWM;
|
||||
uint samplingPeriod = CONFIG_SAMPLING_PERIOD_MS;
|
||||
uint nbCycle = UINT_MAX - 1;
|
||||
|
||||
/* Set these to your desired credentials. */
|
||||
const char *ssid = CONFIG_SSID_NAME;
|
||||
@ -291,12 +293,12 @@ void setup()
|
||||
}
|
||||
WebSetupServer(mode);
|
||||
}
|
||||
samplingPeriod = conf.samplingPeriod;
|
||||
#ifdef CONFIG_ENABLE_POWER_SAVE
|
||||
wifi_set_sleep_type(LIGHT_SLEEP_T);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint nbCycle = CONFIG_SAMPLING_PERIODE_MS / CONFIG_WEB_DELAY_MS;
|
||||
void loop() {
|
||||
if (mode == BOOTMODE_OTA) {
|
||||
ArduinoOTA.handle();
|
||||
@ -309,7 +311,7 @@ void loop() {
|
||||
delay(CONFIG_WEB_DELAY_MS);
|
||||
|
||||
nbCycle++;
|
||||
if (nbCycle > CONFIG_SAMPLING_PERIODE_MS / CONFIG_WEB_DELAY_MS) {
|
||||
if (nbCycle > samplingPeriod / CONFIG_WEB_DELAY_MS) {
|
||||
std::vector<struct mqttInfo> batchInfo;
|
||||
if (!BMP180GetTempAndPressure(temp, pressure)) {
|
||||
SKETCH_DEBUG_PRINTF("Current %f°C Pressure %fmB\n", temp, pressure);
|
||||
|
@ -9,8 +9,8 @@
|
||||
#define CONFIG_WEB_DELAY_MS 100
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SAMPLING_PERIODE_MS
|
||||
#define CONFIG_SAMPLING_PERIODE_MS 60000
|
||||
#ifndef CONFIG_SAMPLING_PERIOD_MS
|
||||
#define CONFIG_SAMPLING_PERIOD_MS 60000
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_ENABLE_BME680) && defined(CONFIG_BME680_BSEC_ENABLE)
|
||||
|
@ -55,7 +55,7 @@
|
||||
//#define CONFIG_WEB_DELAY_MS 100
|
||||
|
||||
// Get sensors value every X ms
|
||||
#define CONFIG_SAMPLING_PERIODE_MS 30000
|
||||
#define CONFIG_SAMPLING_PERIOD_MS 3000
|
||||
|
||||
// Name of the SSID when in AP mode for configuration
|
||||
#define CONFIG_SSID_NAME "ESPConfiguratorBureau"
|
||||
|
Loading…
Reference in New Issue
Block a user