Code: Select all
#include <SPI.h>
#include <MySensor.h>
#define CHILD_ID_STATUS 0
#define CHILD_ID_TEMP 1
MySensor gw;
MyMessage statusmsg(CHILD_ID_STATUS, V_STATUS);
MyMessage tempmsg(CHILD_ID_TEMP, V_TEMP);
void setup() {
gw.begin(incomingMessage);
gw.sendSketchInfo("TEST01","1.0");
gw.present(CHILD_ID_STATUS, S_BINARY);
gw.present(CHILD_ID_TEMP, S_TEMP);
pinMode(2, INPUT_PULLUP);//interrupt = 0;
}
void loop() {
gw.process();
gw.send(statusmsg.set(0));
gw.send(tempmsg.set(45));
gw.request(CHILD_ID_TEMP, V_TEMP,0);
gw.request(CHILD_ID_STATUS, V_STATUS,0);
gw.wait(5000);
gw.sleep(0,FALLING);
}
void incomingMessage(const MyMessage &message) {
if (message.type == V_TEMP) {
Serial.println("TEMP");
}
if (message.type == V_STATUS) {
Serial.println("STATUS");
}
}
Code: Select all
send: 14-14-0-0 s=0,c=1,t=2,pt=2,l=2,sg=0,st=ok:0
send: 14-14-0-0 s=1,c=1,t=0,pt=2,l=2,sg=0,st=ok:45
send: 14-14-0-0 s=1,c=2,t=0,pt=0,l=0,sg=0,st=ok:
send: 14-14-0-0 s=0,c=2,t=2,pt=0,l=0,sg=0,st=ok:
read: 0-0-14 s=0,c=2,t=2,pt=0,l=1,sg=0:0
STATUS
EDIT
Solved it after replacing "V_TEMP" by "V_VAR1". Still don't understand why but it's working now.