The complement [P013] (ultrasonic sensor sr04) hangs in the state = "HI" working on "state mode" when the sensor ping timeout (NO_ECHO). I think this behavior is not correct since the state remains in "hi" when there is no longer any object in front of the sensor.
I think this will be better understood by looking at the plugin code:
at line 255 of mega/src/_P013_HCSR04.ino
Code: Select all
case PLUGIN_TEN_PER_SECOND: // If we select state mode, do more frequent checks and send only state changes
{
int16_t operatingMode = PCONFIG(0);
int16_t threshold = PCONFIG(1);
if (operatingMode == OPMODE_STATE) {
uint8_t state = 0;
float value = Plugin_013_read(event->TaskIndex);
if (value != NO_ECHO) {
if (value < threshold) state = 1;
if (state != switchstate[event->TaskIndex])
{
if (loglevelActiveFor(LOG_LEVEL_INFO)) {log...}
switchstate[event->TaskIndex] = state;
UserVar[event->BaseVarIndex] = state;
event->sensorType = Sensor_VType::SENSOR_TYPE_SWITCH;
sendData(event);
}
}
else {
if (loglevelActiveFor(LOG_LEVEL_INFO)) {log...}
}
}
success = true;
break;
}
Code: Select all
if (value != NO_ECHO) {
if (value < threshold) state = 1;
Code: Select all
if (value != NO_ECHO) {...
...
if (state != switchstate[event->TaskIndex]) {
.....
.....
switchstate[event->TaskIndex] = state; //---<---here
UserVar[event->BaseVarIndex] = state; //---<--------
Code: Select all
// src/_P013_HCSR04.ino @line 255
case PLUGIN_TEN_PER_SECOND: // If we select state mode, do more frequent checks and send only state changes
{
int16_t operatingMode = PCONFIG(0);
int16_t threshold = PCONFIG(1);
if (operatingMode == OPMODE_STATE)
{
uint8_t state = 0;
float value = Plugin_013_read(event->TaskIndex);
//if (value != NO_ECHO) //---no more
//{
if ( (value < threshold) && (value != NO_ECHO) ) //---add condition
state = 1;
if (state != switchstate[event->TaskIndex])
{
if (loglevelActiveFor(LOG_LEVEL_INFO) && (value != NO_ECHO)) {//---add condition
String log = F("ULTRASONIC : TaskNr: ");
log += event->TaskIndex +1;
log += F(" state: ");
log += state;
addLog(LOG_LEVEL_INFO,log);
}
switchstate[event->TaskIndex] = state;
UserVar[event->BaseVarIndex] = state;
event->sensorType = Sensor_VType::SENSOR_TYPE_SWITCH;
sendData(event);
}
//}
if (value == NO_ECHO) { //---add condicion
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
String log = F("ULTRASONIC : TaskNr: ");
log += event->TaskIndex +1;
log += F(" Error: ");
log += Plugin_013_getErrorStatusString(event->TaskIndex);
addLog(LOG_LEVEL_INFO,log);
}
}
}
success = true;
break;
}
When NO-ECHO, is it necessary to log "Error:" 10 times per second?
I'm trying to compile these changes into a copy of the Master branch with the Arduino IDE, but I'm having a headache with libraries. I still couldn't taste the change. I am interested in your opinion about it, thank you very much.