Skip to content

Commit

Permalink
wait until stm init finished
Browse files Browse the repository at this point in the history
  • Loading branch information
SurfGargano committed Jan 18, 2024
1 parent 256e1d1 commit 264ad97
Show file tree
Hide file tree
Showing 8 changed files with 2,205 additions and 2,181 deletions.
5 changes: 3 additions & 2 deletions software_esp32/include/stmApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ class CStmApp
bool matchSensorRequest;
EEP_STATE eepState;
bool waitEEPFinished;

bool oneWireAllRead;

private:
void appHandler();
void app_comm_machine();
Expand Down Expand Up @@ -209,7 +210,7 @@ class CStmApp
uint8_t checkTempsCount;
uint8_t tempsPrivCount;
String cmd_buffer;

char buffer[1200];
char sendbuffer[50];
char *bufptr;
Expand Down
4 changes: 2 additions & 2 deletions software_esp32/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
; https://docs.platformio.org/page/projectconf.html

[common]
firmware_version = '"1.3.3"'
firmware_version_dev = '"1.3.3_Dev"'
firmware_version = '"1.3.4"'
firmware_version_dev = '"1.3.4_Dev"'

[env]
platform = espressif32
Expand Down
107 changes: 55 additions & 52 deletions software_esp32/src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,30 +692,31 @@ void CMqtt::publish_valves () {
lastValveValues[x].meanCurrent=StmApp.actuators[x].meancurrent;
}
// temperature 1st sensor
if (StmApp.actuators[x].tIdx1>0) {
if ((lastValveValues[x].temp1!=StmApp.actuators[x].temp1) || forcePublish || lastValveValues[x].publishTimeOut) {
topicstr[len] = '\0';
strncat(topicstr, "/temp1",sizeof(topicstr) - strlen (topicstr) - 1);
if (StmApp.actuators[x].temp1>-500) {
s = String(((float)StmApp.actuators[x].temp1)/10,1);
} else s="failed";
publishValue(topicstr, (char*) &s);
lastValveValues[x].temp1=StmApp.actuators[x].temp1;
if ((StmApp.stmInitState==STM_INIT_FINISHED) && StmApp.oneWireAllRead) {
if (StmApp.actuators[x].tIdx1>0) {
if ((lastValveValues[x].temp1!=StmApp.actuators[x].temp1) || forcePublish || lastValveValues[x].publishTimeOut) {
topicstr[len] = '\0';
strncat(topicstr, "/temp1",sizeof(topicstr) - strlen (topicstr) - 1);
if (StmApp.actuators[x].temp1>-500) {
s = String(((float)StmApp.actuators[x].temp1)/10,1);
} else s="failed";
publishValue(topicstr, (char*) &s);
lastValveValues[x].temp1=StmApp.actuators[x].temp1;
}
}
}
// temperature 2nd sensor
if (StmApp.actuators[x].tIdx2>0) {
if ((lastValveValues[x].temp2!=StmApp.actuators[x].temp2) || forcePublish || lastValveValues[x].publishTimeOut) {
topicstr[len] = '\0';
strncat(topicstr, "/temp2",sizeof(topicstr) - strlen (topicstr) - 1);
if (StmApp.actuators[x].temp2>-500) {
s = String(((float)StmApp.actuators[x].temp2)/10,1);
} else s="failed";
publishValue(topicstr, (char*) &s);
lastValveValues[x].temp2=StmApp.actuators[x].temp2;
// temperature 2nd sensor
if (StmApp.actuators[x].tIdx2>0) {
if ((lastValveValues[x].temp2!=StmApp.actuators[x].temp2) || forcePublish || lastValveValues[x].publishTimeOut) {
topicstr[len] = '\0';
strncat(topicstr, "/temp2",sizeof(topicstr) - strlen (topicstr) - 1);
if (StmApp.actuators[x].temp2>-500) {
s = String(((float)StmApp.actuators[x].temp2)/10,1);
} else s="failed";
publishValue(topicstr, (char*) &s);
lastValveValues[x].temp2=StmApp.actuators[x].temp2;
}
}
}

lastValveValues[x].publishNow=false;
lastValveValues[x].publishTimeOut=false;
lastValveValues[x].ts=millis();
Expand All @@ -731,41 +732,43 @@ void CMqtt::publish_temps()
int8_t tempIdx;
uint8_t len;
String s;

for (uint8_t x = 0;x<StmApp.tempsCount;x++) {
if (lastTempValues[x].publishNow || forcePublish) {
tempIdx=StmApp.findTempID(StmApp.temps[x].id);
if (tempIdx>=0) {
if (VdmConfig.configFlash.tempsConfig.tempConfig[tempIdx].active) {
if ((StmApp.findTempIdxInValve (tempIdx)<0) || VdmConfig.configFlash.protConfig.protocolFlags.publishAllTemps) {
memset(topicstr,0x0,sizeof(topicstr));
memset(nrstr,0x0,sizeof(nrstr));
itoa((x+1), nrstr, 10);
if (strlen(VdmConfig.configFlash.tempsConfig.tempConfig[tempIdx].name)>0)
strncpy(nrstr,VdmConfig.configFlash.tempsConfig.tempConfig[tempIdx].name,sizeof(nrstr));
// prepare prefix
strncat(topicstr, mqtt_tempsTopic,sizeof(topicstr) - strlen (topicstr) - 1);
strncat(topicstr, nrstr,sizeof(topicstr) - strlen (topicstr) - 1);
len = strlen(topicstr);
// id
strncat(topicstr, "/id",sizeof(topicstr) - strlen (topicstr) - 1);
publishValue(topicstr, StmApp.temps[x].id);
// actual value
topicstr[len] = '\0';
strncat(topicstr, "/value",sizeof(topicstr) - strlen (topicstr) - 1);

if (StmApp.temps[x].temperature<=-500) {
s = "failed";
} else {
s = String(((float)StmApp.temps[x].temperature)/10,1);

if ((StmApp.stmInitState==STM_INIT_FINISHED) && StmApp.oneWireAllRead) {
for (uint8_t x = 0;x<StmApp.tempsCount;x++) {
if (lastTempValues[x].publishNow || forcePublish) {
tempIdx=StmApp.findTempID(StmApp.temps[x].id);
if (tempIdx>=0) {
if (VdmConfig.configFlash.tempsConfig.tempConfig[tempIdx].active) {
if ((StmApp.findTempIdxInValve (tempIdx)<0) || VdmConfig.configFlash.protConfig.protocolFlags.publishAllTemps) {
memset(topicstr,0x0,sizeof(topicstr));
memset(nrstr,0x0,sizeof(nrstr));
itoa((x+1), nrstr, 10);
if (strlen(VdmConfig.configFlash.tempsConfig.tempConfig[tempIdx].name)>0)
strncpy(nrstr,VdmConfig.configFlash.tempsConfig.tempConfig[tempIdx].name,sizeof(nrstr));
// prepare prefix
strncat(topicstr, mqtt_tempsTopic,sizeof(topicstr) - strlen (topicstr) - 1);
strncat(topicstr, nrstr,sizeof(topicstr) - strlen (topicstr) - 1);
len = strlen(topicstr);
// id
strncat(topicstr, "/id",sizeof(topicstr) - strlen (topicstr) - 1);
publishValue(topicstr, StmApp.temps[x].id);
// actual value
topicstr[len] = '\0';
strncat(topicstr, "/value",sizeof(topicstr) - strlen (topicstr) - 1);

if (StmApp.temps[x].temperature<=-500) {
s = "failed";
} else {
s = String(((float)StmApp.temps[x].temperature)/10,1);
}
publishValue(topicstr, (char*) &s);
}
publishValue(topicstr, (char*) &s);
}
}
lastTempValues[x].temperature=StmApp.temps[x].temperature;
lastTempValues[x].publishNow=false;
lastTempValues[x].ts=millis();
}
lastTempValues[x].temperature=StmApp.temps[x].temperature;
lastTempValues[x].publishNow=false;
lastTempValues[x].ts=millis();
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion software_esp32/src/stmApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ CStmApp::CStmApp()
waitEEPFinished=false;
stmInitState=STM_INIT_NOT_STARTED;
fastGetOneWire=false;
oneWireAllRead=false;

}

Expand Down Expand Up @@ -626,7 +627,10 @@ void CStmApp::app_check_data()
}
tempsCount=tempsPrivCount;
}
if (tempsPrivCount==0) fastGetOneWire=false;
if (tempsPrivCount==0) {
fastGetOneWire=false;
oneWireAllRead=true;
}
appState=APP_IDLE;
}

Expand All @@ -649,6 +653,7 @@ void CStmApp::app_check_data()
if (tempIndex>=tempsCount) { // all temp sensors read
tempIndex=0;
fastGetOneWire=false;
oneWireAllRead=true;
}
#ifdef AppDebug
UART_DBG.println("read onwire "+String(tempIndex)+":"+String(fastGetOneWire));
Expand All @@ -663,6 +668,7 @@ void CStmApp::app_check_data()
if (tempIndex>=tempsCount) { // all temp sensors read
tempIndex=0;
fastGetOneWire=false;
oneWireAllRead=true;
}
}
appState=APP_IDLE;
Expand Down
Loading

0 comments on commit 264ad97

Please sign in to comment.