Skip to content

Commit 4ba682d

Browse files
committed
new stimawifi release 20251125; added calibration RPC and removed autocalibration for SCD
1 parent 6aefaf7 commit 4ba682d

File tree

11 files changed

+87
-9
lines changed

11 files changed

+87
-9
lines changed

platformio/libraries/SensorDriver/SensorDriver.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ void SensorDriver::setup(){
142142
void SensorDriver::prepare(bool is_test){
143143
}
144144

145+
bool SensorDriver::setForcedRecalibrationFactor(uint16_t value) {
146+
return false;
147+
}
148+
145149
void SensorDriver::get(int32_t *values, uint8_t length, bool is_test){
146150
}
147151

@@ -4923,7 +4927,7 @@ void SensorDriverScd::setup() {
49234927
//LOGE(F("SCD setup... [ %s ]"), ERROR_STRING);
49244928
return;
49254929
}
4926-
if (!_scd30.setAutoSelfCalibration(true)) { //Enable auto-self-calibration
4930+
if (!_scd30.setAutoSelfCalibration(false)) { //Enable auto-self-calibration
49274931
_error_count++;
49284932
LOGE(F("SCD setAutoSelfCalibration error"));
49294933
//LOGE(F("SCD setup... [ %s ]"), ERROR_STRING);
@@ -4936,6 +4940,10 @@ void SensorDriverScd::setup() {
49364940
}
49374941
}
49384942

4943+
bool SensorDriverScd::setForcedRecalibrationFactor(uint16_t value) {
4944+
return _scd30.setForcedRecalibrationFactor(value);
4945+
}
4946+
49394947
void SensorDriverScd::prepare(bool is_test) {
49404948
SensorDriver::printInfo();
49414949

platformio/libraries/SensorDriver/SensorDriver.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ class SensorDriver {
136136
*/
137137
virtual void get(int32_t *values, uint8_t length, bool is_test=false);
138138

139+
/*!
140+
\fn bool setForcedRecalibrationFactor(uint16_t value)
141+
\brief Set the forced recalibration factor.
142+
\param[in] value true value of the actual measure
143+
\return return code (0 OK).
144+
*/
145+
virtual bool setForcedRecalibrationFactor(uint16_t value);
146+
139147
#if (USE_JSON)
140148
/*!
141149
\fn void getJson(int32_t *values, uint8_t length, char *json_buffer, size_t json_buffer_length = JSON_BUFFER_LENGTH)
@@ -894,6 +902,10 @@ class SensorDriverScd : public SensorDriver {
894902
void prepare(bool is_test = false);
895903
void get(int32_t *values, uint8_t length, bool is_test=false);
896904

905+
//Set the forced recalibration factor.
906+
//The reference CO2 concentration has to be within the range 400 ppm ≤ cref(CO2) ≤ 2000 ppm.
907+
bool setForcedRecalibrationFactor(uint16_t concentration);
908+
897909
#if (USE_JSON)
898910
void getJson(int32_t *values, uint8_t length, char *json_buffer, size_t json_buffer_length = JSON_BUFFER_LENGTH, bool is_test=false);
899911
#endif

platformio/libraries/SensorManager/SensorManager.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include <SensorDriver.h>
33
#include <ArduinoLog.h>
44

5-
#define I2C_BUS_CLOCK (50000L)
65
#define SENSOR_RETRY_COUNT_MAX (3)
76
#define SENSOR_RETRY_DELAY_MS (50)
87
#define SENSOR_ERROR_COUNT_MAX (10)
@@ -30,6 +29,7 @@ class sensorManage {
3029

3130
int32_t values[VALUES_TO_READ_FROM_SENSOR_COUNT];
3231
char json_values[JSON_BUFFER_LENGTH];
32+
SensorDriver* sensor;
3333

3434
private:
3535

@@ -55,8 +55,6 @@ class sensorManage {
5555
bool is_test;
5656
bool is_reading;
5757
bool is_data_ready;
58-
59-
SensorDriver* sensor;
6058
};
6159

6260
#endif
1.55 KB
Binary file not shown.

platformio/stima_v3/stimawifi/include/stimawifi_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#define STIMAWIFI_CONFIG_H_
33

44
// increment on change
5-
#define SOFTWARE_VERSION "2025-10-30T00:00" // date and time iso format
6-
#define MAJOR_VERSION "20251030" // date YYYYMMDD
5+
#define SOFTWARE_VERSION "2025-11-25T00:00" // date and time iso format
6+
#define MAJOR_VERSION "20251125" // date YYYYMMDD
77
#define MINOR_VERSION "0" // time HHMM without leading 0
88

99
// SSID and password of WiFi for setup

platformio/stima_v3/stimawifi/src/measure_thread.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,21 @@ void measureThread::doMeasure() {
250250
}
251251

252252
data->i2cmutex->Lock(); // use the same mutex for i2c for access summary data
253+
254+
// check queue for rpc calibrate
255+
rpcCalibrate_t rpccalibrate;
256+
if(data->calibratequeue->Dequeue(&rpccalibrate, pdMS_TO_TICKS( 0 ))){
257+
for (uint8_t i = 0; i < data->sensors_count; i++) {
258+
if ( strcmp(rpccalibrate.type,sensorm[i].getSensorDriver()->getType())==0) {
259+
uint8_t rc = sensorm[i].sensor->setForcedRecalibrationFactor(rpccalibrate.value);
260+
data->logger->notice(F("measure setForcedRecalibrationFactor: %s-%s:%d rc %d"),
261+
sensorm[i].getSensorDriver()->getDriver(),
262+
sensorm[i].getSensorDriver()->getType(),
263+
rpccalibrate.value, rc);
264+
}
265+
}
266+
}
267+
253268
update_summary_data();
254269
data->i2cmutex->Unlock();
255270

platformio/stima_v3/stimawifi/src/measure_thread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct measure_data_t { // thread communication data
1313
summarydata_t* summarydata;
1414
MutexStandard* i2cmutex;
1515
georef_t* georef;
16+
BinaryQueue* calibratequeue;
1617
sensor_t sensors[SENSORS_MAX];
1718
uint8_t sensors_count;
1819
};

platformio/stima_v3/stimawifi/src/publish_thread.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ void publishThread::Run() {
7070
global_jsonrpc.registerMethod("pinout", &pinOutRpc);
7171
global_jsonrpc.registerMethod("recovery", &recoveryDataRpc);
7272
global_jsonrpc.registerMethod("reboot", &rebootRpc);
73-
73+
global_jsonrpc.registerMethod("calibrate", &calibrateRpc);
74+
7475
for(;;){
7576

7677
// if there are no enough space left on the mqtt queue send it to the DB
@@ -670,6 +671,35 @@ int rebootRpc(JsonObject params, JsonObject result) {
670671
return 0;
671672
}
672673

674+
675+
/*
676+
RPC calibrate
677+
678+
Richiede la calibrazioen del sensore facendo corrispondere le misure attuali al valore fornito
679+
esempi:
680+
{"jsonrpc": "2.0", "method": "calibrate", "params": {"type":"sdc30","value":430, "id": 0}
681+
*/
682+
683+
int calibrateRpc(JsonObject params, JsonObject result) {
684+
rpcCalibrate_t rpccalibrate;
685+
686+
if (params.containsKey("type") && params.containsKey("value")){
687+
const char* type = params["type"];
688+
strncpy(rpccalibrate.type,type,4);
689+
rpccalibrate.value = params["value"];
690+
691+
if(publishThread::global_data->calibratequeue->Enqueue(&rpccalibrate)){
692+
publishThread::global_data->logger->notice(F("enqueue rpc calibrate : %s ; %d"), rpccalibrate.type, rpccalibrate.value);
693+
result[F("state")] = F("done");
694+
return 0;
695+
}
696+
}
697+
698+
publishThread::global_data->logger->error(F("enqueue rpc calibrate"));
699+
result[F("state")] = F("error");
700+
return 1;
701+
}
702+
673703
/*
674704
RPC recovery
675705

platformio/stima_v3/stimawifi/src/publish_thread.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ void mqttRxCallback(MQTT::MessageData &md);
1111
int rebootRpc(JsonObject params, JsonObject result);
1212
int recoveryDataRpc(JsonObject params, JsonObject result);
1313
int pinOutRpc(JsonObject params, JsonObject result);
14+
int calibrateRpc(JsonObject params, JsonObject result);
1415

1516
// thread exchange data struct
1617
struct publish_data_t {
@@ -19,6 +20,7 @@ struct publish_data_t {
1920
Queue* mqttqueue;
2021
Queue* dbqueue;
2122
BinaryQueue* recoveryqueue;
23+
BinaryQueue* calibratequeue;
2224
stimawifiStatus_t* status;
2325
station_t* station;
2426
};

platformio/stima_v3/stimawifi/src/stimawifi.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ gpsThread threadGps(&gps_data);
9797
Queue dbQueue(DB_QUEUE_LEN,sizeof(mqttMessage_t)); // ~ 1 minutes queue
9898
Queue mqttQueue(MQTT_QUEUE_LEN,sizeof(mqttMessage_t)); // ~ 1.5 minutes queue
9999
BinaryQueue recoveryQueue(sizeof(rpcRecovery_t));
100+
BinaryQueue calibrateQueue(sizeof(rpcCalibrate_t));
100101
BinarySemaphore recoverySemaphore(false);
101102
#if (ENABLE_SDCARD_LOGGING)
102103
db_data_t db_data={1,&frtosLog,&dbQueue,&mqttQueue,&recoverySemaphore,&recoveryQueue,&stimawifiStatus.db,&station,&logFile};
@@ -106,10 +107,10 @@ db_data_t db_data={1,&frtosLog,&dbQueue,&mqttQueue,&recoverySemaphore,&recoveryQ
106107

107108
dbThread threadDb(&db_data);
108109

109-
measure_data_t measure_data={1,&frtosLog,&mqttQueue,&dbQueue,&stimawifiStatus.measure,&station,&summarydata,&i2cmutex,&georef};
110+
measure_data_t measure_data={1,&frtosLog,&mqttQueue,&dbQueue,&stimawifiStatus.measure,&station,&summarydata,&i2cmutex,&georef,&calibrateQueue};
110111
measureThread threadMeasure(&measure_data);
111112

112-
publish_data_t publish_data={1,&frtosLog,&mqttQueue,&dbQueue,&recoveryQueue,&stimawifiStatus,&station};
113+
publish_data_t publish_data={1,&frtosLog,&mqttQueue,&dbQueue,&recoveryQueue,&calibrateQueue,&stimawifiStatus,&station};
113114
publishThread threadPublish(&publish_data);
114115

115116
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, LED_PIN, NEO_GRB + NEO_KHZ800);

0 commit comments

Comments
 (0)