Hi developers.
I did a little debugging job, as you will see, missing \0 terminator is causing troubles.
So, I used slightly modified incomingMessage() DimmableLight example (little bit more logging is here):
void incomingMessage(const MyMessage &message)
{
if (message.type == V_LIGHT) {
Serial.print( "V_LIGHT command received. Value is " );
Serial.println( message.data );
int lstate= atoi( message.data );
Serial.print( "V_LIGHT new state: " );
Serial.println( lstate );
if ((lstate<0)||(lstate>1)) {
Serial.println( "V_LIGHT data invalid (should be 0/1)" );
return;
}
LastLightState=lstate;
gw.saveState(EPROM_LIGHT_STATE, LastLightState);
if ((LastLightState==LIGHT_ON)&&(LastDimValue==0)) {
//In the case that the Light State = On, but the dimmer value is zero,
//then something (probably the controller) did something wrong,
//for the Dim value to 100%
LastDimValue=100;
gw.saveState(EPROM_DIMMER_LEVEL, LastDimValue);
}
//When receiving a V_LIGHT command we switch the light between OFF and the last received dimmer value
//This means if you previously set the lights dimmer value to 50%, and turn the light ON
//it will do so at 50%
}
else if (message.type == V_DIMMER) {
Serial.print( "V_DIMMER command received. Value is " );
Serial.println( message.data );
int dimvalue= atoi( message.data );
Serial.print( "V_DIMMER new state: " );
Serial.println( dimvalue );
if ((dimvalue<0)||(dimvalue>100)) {
Serial.println( "V_DIMMER data invalid (should be 0..100)" );
return;
}
if (dimvalue==0) {
LastLightState=LIGHT_OFF;
}
else {
LastLightState=LIGHT_ON;
LastDimValue=dimvalue;
gw.saveState(EPROM_DIMMER_LEVEL, LastDimValue);
}
}
else {
Serial.println( "Invalid command received..." );
return;
}
I sent messages 34%, 100%, 49% and 0% to the node.
The log is here:
send: 31-31-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0
send: 31-31-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.3
send: 31-31-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
read: 0-0-31 s=255,c=3,t=6,pt=0,l=1,sg=0:M
send: 31-31-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0
send: 31-31-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.3
send: 31-31-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
sensor started, id=31, parent=0, distance=1
send: 31-31-0-0 s=255,c=3,t=11,pt=0,l=13,sg=0,st=ok:Dimable Light
send: 31-31-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
send: 31-31-0-0 s=1,c=0,t=4,pt=0,l=0,sg=0,st=ok:
Light state: OFF
send: 31-31-0-0 s=1,c=1,t=3,pt=2,l=2,sg=0,st=ok:0
Node ready to receive messages...
read: 0-0-31 s=1,c=1,t=3,pt=0,l=2,sg=0:34
V_DIMMER command received. Value is 340able Light
V_DIMMER new state: 340
V_DIMMER data invalid (should be 0..100)
read: 0-0-31 s=1,c=1,t=3,pt=0,l=3,sg=0:100
V_DIMMER command received. Value is 100able Light
V_DIMMER new state: 100
Light state: ON, Level: 100
send: 31-31-0-0 s=1,c=1,t=3,pt=2,l=2,sg=0,st=ok:100
read: 0-0-31 s=1,c=1,t=3,pt=0,l=2,sg=0:49
V_DIMMER command received. Value is 490able Light
V_DIMMER new state: 490
V_DIMMER data invalid (should be 0..100)
read: 0-0-31 s=1,c=1,t=3,pt=0,l=1,sg=0:0
V_DIMMER command received. Value is 090able Light
V_DIMMER new state: 90
Light state: ON, Level: 90
send: 31-31-0-0 s=1,c=1,t=3,pt=2,l=2,sg=0,st=ok:90
Look for "V_DIMMER command received. Value is ..." lines. Makes a sense?
I am not ready to update my 1.5 gateway now, sorry. If this is a problem, I can do it in a few weeks.
HB