I have a state machine…In the header file I have a simple #define TEST. If this is in the state machine sends print to the COMM port…If this is remarked out I send print to Publish. You can see from the post that the prints are pretty much the same. The issue is Publish will print Cycle 1 and Cycle 2 then start back over, never printing Cycle 3, however the Comm will print Cycle 1, Cycle 2 and then Cycle 3. You can see on the first print line the ternary logic it is IDENTICAL. Furthermore I show the state machine logic prior to the PUBLISH calls and you can see it is nothing but an #ifdef. Also I am careful to place a 1 second delay in the WEB_PUBLISH state so as not to overwhelm publishing. Can someone tell me why Cycle 3 does NOT work in the WEB_PUBLISH state??? The only call to either state is made in the READING state which I posted. The final point to note is readCycle exists nowhere else.
case READING:
for (current = 0; current < 4; current++){
DAC_Load_Value(dacValues[current]);
float* pPublish = &SensorDataPerCyclePublish.Vbias[0];
for (uint8_t i = 0; i < NUMBER_SAMPLES; i++){
ReadingArray[0][i] = analogRead(Vbias);
ReadingArray[1][i] = analogRead(SiPM_current);
ReadingArray[2][i] = analogRead(LED1_current);
ReadingArray[3][i] = analogRead(LED2_current);
}
SensorDataPerCyclePublish.w_temp[current] = ReadWaterTemp();
SensorDataPerCyclePublish.bd_temp[current] = ReadIntTemp();
for (uint8_t arr = 0; arr < NUMBER_SENSORS; arr++){
float k = GetAverage((&ReadingArray[arr][0]), NUMBER_SAMPLES);
*(pPublish + current + 4*arr) = k; //stuff struct t_PublishData
}
}
readCycle++;
sm = SOLENOID_POWER;
break;
case SOLENOID_POWER:
if (readCycle < 3){
if (!msmntFlush.isActive()){
msmntFlush.start();
#ifdef TEST
sm = COMM_PUBLISH;
#else
sm = WEB_PUBLISH;
#endif
}
if (enables.expiry_waterFlush){
msmntFlush.stop();
enables.expiry_waterFlush = false;
printFlag = false;
sm = READING;
}
break;
}
else{
readCycle = 0;
printFlag = false;
enables.m_waitPeriod = false;
#ifdef TEST
sm = COMM_PUBLISH;
#else
sm = WEB_PUBLISH;
#endif
}
case COMM_PUBLISH:
for (current = 0; current < 4; current++){
Serial.printlnf("CYCLE %d ------------------------- CURRENT %0.1f mA", ((readCycle > 0) ? readCycle : 3), DAC_C[current]);
Serial.printlnf("Vbias %0.2f", SensorDataPerCyclePublish.Vbias[current]);
Serial.printlnf("SiPM %0.2f", SensorDataPerCyclePublish.SiPMCurrent[current]);
Serial.printlnf("LED1 %0.2f", SensorDataPerCyclePublish.LED1Current[current]);
Serial.printlnf("LED2 %0.2f", SensorDataPerCyclePublish.LED2Current[current]);
Serial.printlnf("WaterT %0.2f", SensorDataPerCyclePublish.w_temp[current]);
Serial.printlnf("BoardT %0.2f", SensorDataPerCyclePublish.bd_temp[current]);
}
if (readCycle != 0)
sm = SOLENOID_POWER;
else{
Serial.printlnf("--------EVENT FINISHED------------");
Serial.printlnf("----------------------------------");
sm = SOLENOID_NOPWR;
}
break;
case WEB_PUBLISH:
for (current = 0; current < 4; current++){
Particle.publish("---Cycle/Current/Time----", String::format("%d, %0.1f, %lu", ((readCycle > 0) ? readCycle : 3), DAC_C[current], millis()));
Particle.publish("Vbias/SiPM/LED1/LED2/Tw/Tbd",String::format("%0.2f, %0.2f, %0.2f, %0.2f, %0.1f, %0.1f", SensorDataPerCyclePublish.Vbias[current], \
SensorDataPerCyclePublish.SiPMCurrent[current], SensorDataPerCyclePublish.LED1Current[current], SensorDataPerCyclePublish.LED2Current[current], \
SensorDataPerCyclePublish.w_temp[current],SensorDataPerCyclePublish.bd_temp[current]));
delay(1000);
}
if (readCycle != 0)
sm = SOLENOID_POWER;
else{
sm = SOLENOID_NOPWR;
}