Skip to content

Commit

Permalink
working on esp32 stimawifi
Browse files Browse the repository at this point in the history
  • Loading branch information
pat1 committed Jan 29, 2024
1 parent f0e81fc commit 30b6421
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 62 deletions.
21 changes: 16 additions & 5 deletions platformio/stima_v3/stimawifi/src/measure_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,51 @@ void display_values(const char* values,measure_data_t &data) {

DeserializationError error = deserializeJson(doc,values);
if (!error) {
data.logger->notice(F("display_values OK"));
JsonObject obj = doc.as<JsonObject>();
for (JsonPair pair : obj) {

if (pair.value().isNull()) continue;
float val=pair.value().as<float>();

u8g2.setCursor(0, (displaypos++)*CH);

if (strcmp(pair.key().c_str(),"B12101")==0){
data.logger->notice(F("Temperature: %D"),val);
u8g2.setCursor(0, (displaypos++)*CH);
u8g2.print(F("T : "));
u8g2.print(round((val-27315)/10.)/10,1);
u8g2.print(F(" C"));
}
if (strcmp(pair.key().c_str(),"B13003")==0){
data.logger->notice(F("Humidity: %D"),val);
u8g2.setCursor(0, (displaypos++)*CH);
u8g2.print(F("U : "));
u8g2.print(round(val),0);
u8g2.print(F(" %"));
}
if (strcmp(pair.key().c_str(),"B15198")==0){
data.logger->notice(F("PM2: %D"),val);
u8g2.setCursor(0, (displaypos++)*CH);
u8g2.print(F("PM2 : "));
u8g2.print(round(val/10.),0);
u8g2.print(F(" ug/m3"));
}
if (strcmp(pair.key().c_str(),"B15195")==0){
data.logger->notice(F("PM10: %D"),val);
u8g2.setCursor(0, (displaypos++)*CH);
u8g2.print(F("PM10: "));
u8g2.print(round(val/10.),0);
u8g2.print(F(" ug/m3"));
}
if (strcmp(pair.key().c_str(),"B15242")==0){
data.logger->notice(F("CO2: %D"),val);
u8g2.setCursor(0, (displaypos++)*CH);
u8g2.print(F("CO2 : "));
u8g2.print(round(val/1.8),0);
u8g2.print(F(" ppm"));
}
}
}
}else{
data.logger->error(F("display_values deserialization ERROR"));
}
}

void enqueueMqttMessage(const char* values, const char* timerange, const char* level, measure_data_t& data ) {
Expand All @@ -67,6 +71,7 @@ void enqueueMqttMessage(const char* values, const char* timerange, const char* l
}
for (JsonPair pair : doc.as<JsonObject>()) {
if (pair.value().isNull()){
data.logger->error(F("novalue error"));
data.status->novalue=error;
continue;
}
Expand Down Expand Up @@ -110,7 +115,6 @@ void doMeasure( measure_data_t &data ) {
// long values[MAX_VALUES_FOR_SENSOR];
// size_t lenvalues=MAX_VALUES_FOR_SENSOR;

data.status->novalue=unknown;
data.status->sensor=unknown;

// prepare sensors to measure
Expand Down Expand Up @@ -150,6 +154,9 @@ void doMeasure( measure_data_t &data ) {
u8g2.clearBuffer();
u8g2.sendBuffer();
}

data.status->novalue=unknown;

for (int i = 0; i < SENSORS_LEN; i++) {
if (!sd[i] == 0){
data.logger->notice(F("getJson sd %d"),i);
Expand All @@ -172,6 +179,10 @@ void doMeasure( measure_data_t &data ) {
}
}
}

if(data.status->novalue==unknown) data.status->novalue=ok;
if(data.status->sensor==unknown) data.status->sensor=ok;

if (oledpresent) u8g2.sendBuffer();
}

Expand Down
4 changes: 0 additions & 4 deletions platformio/stima_v3/stimawifi/src/publish_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ bool publish_maint(publish_data_t& data) {
if (!mqttclient.publish(mainttopic,(uint8_t*)"{\"v\":\"conn\",\"s\":" MAJOR_VERSION ",\"m\":" MINOR_VERSION "} ", 34,1)){ //padded 3 blank char for time
//if (!mqttclient.publish(mainttopic,(uint8_t*)"{\"v\":\"conn\"}", 12,1)){
data.logger->error(F("MQTT maint not published"));
data.status->publish=error;
mqttclient.disconnect();
return false;
}
Expand Down Expand Up @@ -94,17 +93,14 @@ bool publish_constantdata(publish_data_t& data) {
if (!mqttclient.publish(topic, payload)){
data.logger->error(F("MQTT data not published"));
mqttclient.disconnect();
data.status->publish=error;
return false;
}
data.logger->notice(F("MQTT data published"));
data.status->publish=ok;
}
}
}
} else {
data.logger->error(F("error parsing array: %s"),deerror.c_str());
data.status->publish=error;
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion platformio/stima_v3/stimawifi/src/stimawifi-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@
#define SENSORDRIVER_META_LEN 30
#define MAX_VALUES_FOR_SENSOR 9

#define CH 9 // character height px for display
#define CH 8 // character height px for display

#endif
Loading

0 comments on commit 30b6421

Please sign in to comment.