Compare commits
No commits in common. "446c7a5807cd5440f7c40ec4e6d2b7eb1cf0b2bb" and "d2b9851bc1ec6fa75bcd9ca5d7cb2f964b0a609d" have entirely different histories.
446c7a5807
...
d2b9851bc1
3 changed files with 75 additions and 111 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,4 +4,3 @@ firmware/.DS_Store
|
||||||
schematics/#auto_saved_files#
|
schematics/#auto_saved_files#
|
||||||
schematics/_autosave-oko-weatherstation.sch
|
schematics/_autosave-oko-weatherstation.sch
|
||||||
firmware.ino.bin
|
firmware.ino.bin
|
||||||
firmware/extract me in arduino libraries folder.zip
|
|
||||||
|
|
|
@ -30,6 +30,16 @@ const uint8_t VALUES = 8; // see constants.h file - count of number of SENSOR_ d
|
||||||
float currentSensorData[VALUES] = { nanf("no value"), nanf("no value"), nanf("no value"),
|
float currentSensorData[VALUES] = { nanf("no value"), nanf("no value"), nanf("no value"),
|
||||||
nanf("no value"), nanf("no value"), nanf("no value"),
|
nanf("no value"), nanf("no value"), nanf("no value"),
|
||||||
nanf("no value"), nanf("no value") };
|
nanf("no value"), nanf("no value") };
|
||||||
|
float (*sensors[VALUES])() = {};
|
||||||
|
|
||||||
|
uint8_t sensor_value[] = { SENSOR_TEMPERATURE,
|
||||||
|
SENSOR_HUMIDITY,
|
||||||
|
SENSOR_LIGHT,
|
||||||
|
SENSOR_WINDSPEED,
|
||||||
|
SENSOR_PRESSURE,
|
||||||
|
SENSOR_BAT_VOLTAGE,
|
||||||
|
SENSOR_ESAVEMODE,
|
||||||
|
SENSOR_BATCHARGESTATE };
|
||||||
|
|
||||||
uint32_t update_sensor_cnt = 0;
|
uint32_t update_sensor_cnt = 0;
|
||||||
uint32_t update_webserver_cnt = 0;
|
uint32_t update_webserver_cnt = 0;
|
||||||
|
@ -46,8 +56,6 @@ uint8_t sensor_cnt = 0;
|
||||||
|
|
||||||
boolean validData = false;
|
boolean validData = false;
|
||||||
|
|
||||||
boolean do_not_read_windsensor = false;
|
|
||||||
|
|
||||||
//*************************************************************************//
|
//*************************************************************************//
|
||||||
|
|
||||||
void debug(String x)
|
void debug(String x)
|
||||||
|
@ -139,84 +147,35 @@ void initSensors()
|
||||||
{
|
{
|
||||||
// Initialize and configure the sensors
|
// Initialize and configure the sensors
|
||||||
#ifdef SENSOR_APDS9930
|
#ifdef SENSOR_APDS9930
|
||||||
if (sensor_apds9930_begin();
|
if (sensor_apds9930_begin()) {
|
||||||
|
sensors[SENSOR_LIGHT] = &apds9930_light;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SENSOR_APDS9960
|
#ifdef SENSOR_APDS9960
|
||||||
sensor_apds9960_begin();
|
if (sensor_apds9960_begin()) {
|
||||||
|
sensors[SENSOR_LIGHT] = &apds9960_light;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SENSOR_BME280
|
#ifdef SENSOR_BME280
|
||||||
//Temperature + pressure
|
//Temperature + pressure
|
||||||
sensor_bme280_begin(BME_ADDRESS);
|
if (sensor_bme280_begin(BME_ADDRESS)) {
|
||||||
#endif
|
sensors[SENSOR_TEMPERATURE] = &bme280_temperature;
|
||||||
|
sensors[SENSOR_HUMIDITY] = &bme280_humidity;
|
||||||
|
sensors[SENSOR_PRESSURE] = &bme280_pressure;
|
||||||
}
|
}
|
||||||
|
|
||||||
float readSensors(uint8_t s)
|
|
||||||
{
|
|
||||||
float ret = nan("no value");
|
|
||||||
|
|
||||||
switch(s)
|
|
||||||
{
|
|
||||||
case SENSOR_LIGHT: // Initialize and configure the sensors
|
|
||||||
#ifdef SENSOR_APDS9930
|
|
||||||
ret = apds9930_light();
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef SENSOR_APDS9960
|
|
||||||
ret = apds9960_light();
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SENSOR_TEMPERATURE:
|
|
||||||
#ifdef SENSOR_BME280
|
|
||||||
ret = bme280_temperature();
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SENSOR_HUMIDITY:
|
|
||||||
#ifdef SENSOR_BME280
|
|
||||||
ret = bme280_humidity();
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SENSOR_PRESSURE:
|
|
||||||
#ifdef SENSOR_BME280
|
|
||||||
ret = bme280_pressure();
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SENSOR_WINDSPEED:
|
|
||||||
#ifdef SENSOR_WIND
|
#ifdef SENSOR_WIND
|
||||||
if (do_not_read_windsensor == false)
|
sensors[SENSOR_WINDSPEED] = &wind_speed;
|
||||||
{
|
|
||||||
ret = wind_speed();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
break;
|
|
||||||
|
|
||||||
case SENSOR_BAT_VOLTAGE:
|
|
||||||
#ifdef SENSOR_BATTERY
|
#ifdef SENSOR_BATTERY
|
||||||
ret = battery_voltage();
|
sensors[SENSOR_BAT_VOLTAGE] = &battery_voltage;
|
||||||
|
sensors[SENSOR_BATCHARGESTATE] = &battery_charging;
|
||||||
|
sensors[SENSOR_ESAVEMODE] = &isEnergySavingMode;
|
||||||
#endif
|
#endif
|
||||||
break;
|
|
||||||
|
|
||||||
case SENSOR_ESAVEMODE:
|
|
||||||
#ifdef SENSOR_BATTERY
|
|
||||||
ret = battery_charging();
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SENSOR_BATCHARGESTATE:
|
|
||||||
#ifdef SENSOR_BATTERY
|
|
||||||
ret = isEnergySavingMode();
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************//
|
//*************************************************************************//
|
||||||
|
@ -335,7 +294,7 @@ void _loop()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FSM_STATE_WSE:
|
case FSM_STATE_WSE:
|
||||||
//debug("wind speed exceeded check if required");
|
debug("wind speed exceeded check if required");
|
||||||
#ifdef HTTP_CALL_ON_WINDSPEED_EXCEED
|
#ifdef HTTP_CALL_ON_WINDSPEED_EXCEED
|
||||||
if ((update_windspeed_exceed_cnt + (HTTP_CALL_ON_WINDSPEED_INTERVAL_S * 1000)) <= millis())
|
if ((update_windspeed_exceed_cnt + (HTTP_CALL_ON_WINDSPEED_INTERVAL_S * 1000)) <= millis())
|
||||||
{
|
{
|
||||||
|
@ -373,14 +332,11 @@ void _loop()
|
||||||
#ifdef defined(BATTERY_POWERED) && defined(SENSOR_WIND)
|
#ifdef defined(BATTERY_POWERED) && defined(SENSOR_WIND)
|
||||||
if (energySavingMode() == 1) {
|
if (energySavingMode() == 1) {
|
||||||
// Disable expensive tasks
|
// Disable expensive tasks
|
||||||
//sensors[SENSOR_WINDSPEED] = 0;
|
sensors[SENSOR_WINDSPEED] = 0;
|
||||||
//debug("read of wind sensor because of low battery disabled");
|
//debug("read of wind sensor because of low battery disabled");
|
||||||
do_not_read_windsensor = true;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//sensors[SENSOR_WINDSPEED] = &wind_speed;
|
sensors[SENSOR_WINDSPEED] = &wind_speed;
|
||||||
//debug("read of wind sensor because of high battery enabled");
|
//debug("read of wind sensor because of high battery enabled");
|
||||||
do_not_read_windsensor = false;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
sensor_cnt = 0;
|
sensor_cnt = 0;
|
||||||
|
@ -392,30 +348,35 @@ void _loop()
|
||||||
if ((update_sensor_cnt + (UPDATE_SENSOR_INTERVAL_S * 1000)) <= millis())
|
if ((update_sensor_cnt + (UPDATE_SENSOR_INTERVAL_S * 1000)) <= millis())
|
||||||
{
|
{
|
||||||
debug("read sensor data " + String(sensor_cnt));
|
debug("read sensor data " + String(sensor_cnt));
|
||||||
|
if (sensors[sensor_cnt])
|
||||||
|
{
|
||||||
|
debug("sensors[sensor_value[" + String(sensor_cnt) + " ]]=" + String((int)sensors[sensor_value[sensor_cnt]]) + ":" + String(sensor_value[sensor_cnt]));
|
||||||
|
currentSensorData[sensor_cnt] = sensors[sensor_value[sensor_cnt]]();
|
||||||
|
//currentSensorData[sensor_cnt] = sensor_cnt;
|
||||||
|
|
||||||
currentSensorData[sensor_cnt] = readSensors(sensor_cnt);
|
} else {
|
||||||
|
|
||||||
|
debug("sensors[sensor_value[" + String(sensor_cnt) + "]]=nan");
|
||||||
|
currentSensorData[sensor_cnt] = nan("no value");
|
||||||
|
}
|
||||||
|
|
||||||
if (sensor_cnt < VALUES)
|
if (sensor_cnt < VALUES)
|
||||||
{
|
{
|
||||||
sensor_cnt++;
|
sensor_cnt++;
|
||||||
fsm_state = FSM_STATE_US; // jump to same state again, more sensors to read
|
fsm_state = FSM_STATE_US; // jump to same state again, more sensors to read
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
update_sensor_cnt = millis();
|
update_sensor_cnt = millis();
|
||||||
sensor_cnt = 0;
|
sensor_cnt = 0;
|
||||||
fsm_state = FSM_STATE_SC; // next state
|
fsm_state = FSM_STATE_SC; // next state
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
debug("skip read sensor data");
|
||||||
//debug("skip read sensor data");
|
|
||||||
fsm_state = FSM_STATE_WU; // no new data, reset FSM
|
fsm_state = FSM_STATE_WU; // no new data, reset FSM
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FSM_STATE_SC:
|
case FSM_STATE_SC:
|
||||||
//debug("log to serial if required");
|
debug("log to serial if required");
|
||||||
#ifdef SERIAL_FEATURE
|
#ifdef SERIAL_FEATURE
|
||||||
logToSerial(currentSensorData);
|
logToSerial(currentSensorData);
|
||||||
#endif
|
#endif
|
||||||
|
@ -423,7 +384,7 @@ void _loop()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FSM_STATE_ID:
|
case FSM_STATE_ID:
|
||||||
//debug("send data to influxdb if required");
|
debug("send data to influxdb if required");
|
||||||
#ifdef INFLUXDB_FEATURE
|
#ifdef INFLUXDB_FEATURE
|
||||||
for (uint8_t i = 0; i < 5 and validData == false; i++)
|
for (uint8_t i = 0; i < 5 and validData == false; i++)
|
||||||
{
|
{
|
||||||
|
@ -443,7 +404,7 @@ void _loop()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FSM_STATE_SD:
|
case FSM_STATE_SD:
|
||||||
//debug("set sensor data in webupdater if required");
|
debug("set sensor data in webupdater if required");
|
||||||
#ifdef WEBUPDATER_FEATURE
|
#ifdef WEBUPDATER_FEATURE
|
||||||
setSensorData(currentSensorData);
|
setSensorData(currentSensorData);
|
||||||
#endif
|
#endif
|
||||||
|
@ -469,10 +430,11 @@ void _loop()
|
||||||
|
|
||||||
void readWindSpeedExceed()
|
void readWindSpeedExceed()
|
||||||
{
|
{
|
||||||
|
if (sensors[SENSOR_WINDSPEED])
|
||||||
|
{
|
||||||
// read from windspeed sensorSTATUS_LED_PIN
|
// read from windspeed sensorSTATUS_LED_PIN
|
||||||
digitalWrite(STATUS_LED_PIN, HIGH);
|
digitalWrite(STATUS_LED_PIN, HIGH);
|
||||||
currentSensorData[SENSOR_WINDSPEED] = readSensors(SENSOR_WINDSPEED);
|
currentSensorData[SENSOR_WINDSPEED] = sensors[SENSOR_WINDSPEED]();
|
||||||
digitalWrite(STATUS_LED_PIN, LOW);
|
digitalWrite(STATUS_LED_PIN, LOW);
|
||||||
|
|
||||||
if (currentSensorData[SENSOR_WINDSPEED] >= HTTP_CALL_ON_WINDSPEED_EXCEED_MPS)
|
if (currentSensorData[SENSOR_WINDSPEED] >= HTTP_CALL_ON_WINDSPEED_EXCEED_MPS)
|
||||||
|
@ -502,6 +464,9 @@ void readWindSpeedExceed()
|
||||||
setSensorData(currentSensorData);
|
setSensorData(currentSensorData);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
} else {
|
||||||
|
currentSensorData[SENSOR_WINDSPEED] = nan("no value");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************//
|
//*************************************************************************//
|
||||||
|
|
|
@ -210,7 +210,7 @@ void measureWindspeed()
|
||||||
|
|
||||||
#ifdef USE_LOGGER
|
#ifdef USE_LOGGER
|
||||||
|
|
||||||
#define LOGFILE_SIZE 25
|
#define LOGFILE_SIZE 20
|
||||||
|
|
||||||
String logfile[LOGFILE_SIZE];
|
String logfile[LOGFILE_SIZE];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue