MySensors gw.request()

Moderator: leecollings

Post Reply
HarryDutch
Posts: 8
Joined: Sunday 03 January 2016 11:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

MySensors gw.request()

Post by HarryDutch »

I'm trying to find out what's possible and what's not with Domoticz and MySensors. I have a simple sketch that's writing a value to 2 sensors (S_BINARY and S_TEMP). So far so good. But when I want to read these values back by using gw.request() only gw.request(CHILD_ID_STATUS, V_STATUS,0) seems to work. I never get a value back when I use gw.request(CHILD_ID_TEMP, V_TEMP,0). This is the sketch:

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");
  }

}
This is the output from the serial monitor:

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
I'm sure that I'm missing something, but I have no idea what.


EDIT
Solved it after replacing "V_TEMP" by "V_VAR1". Still don't understand why but it's working now.
Last edited by HarryDutch on Monday 04 January 2016 8:37, edited 1 time in total.
User avatar
gizmocuz
Posts: 2488
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: MySensors gw.request() [SOLVED]

Post by gizmocuz »

I was just going to say.... only setting/reading values is supported wth V_VAR1 till V_VAR5
Quality outlives Quantity!
HarryDutch
Posts: 8
Joined: Sunday 03 January 2016 11:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MySensors gw.request()

Post by HarryDutch »

Using latest beta Domoticz
MySensors 1.5

I still have problems with gw.request(). Started all over again. Removed the MySensors serial gateway. Added a new one and runned this sketch:

Code: Select all

#include <SPI.h>
#include <MySensor.h>
#define ID_VAR1   1
#define ID_STATUS 2
MySensor gw;
MyMessage msgvar1(ID_VAR1, V_TEMP);
MyMessage msgstatus(ID_STATUS, V_STATUS);

void setup() {  
  gw.begin(incomingMessage);
  gw.sendSketchInfo("TEST02","2.0");
  gw.present(ID_VAR1, S_TEMP);
  gw.present(ID_STATUS, S_BINARY);  
  pinMode(2, INPUT_PULLUP);
}

void loop() { 
  gw.process();
  gw.send(msgvar1.set(40));
  gw.wait(2000);  
  gw.send(msgstatus.set(1));
  gw.wait(2000); 
  gw.request(ID_VAR1, V_VAR1);
  gw.wait(2000); 
  gw.request(ID_STATUS, V_STATUS);
  gw.wait(5000);    
  gw.sleep(0,FALLING);
}

void incomingMessage(const MyMessage &message) {
  if (message.type == V_VAR1) {
    Serial.print("TEMP = ");Serial.println(message.getInt());
  }
  if (message.type == V_STATUS) {
    Serial.print("STATUS = ");Serial.println(message.getInt());
  }
}
The value of S_TEMP is set to 40 and the value of S_BINARY is set to 1 ("on"). They both show the right value in Domoticz and this is the serial ouput from the node:

Code: Select all

send: 5-5-0-0 s=1,c=1,t=0,pt=2,l=2,sg=0,st=ok:40
send: 5-5-0-0 s=2,c=1,t=2,pt=2,l=2,sg=0,st=ok:1
send: 5-5-0-0 s=1,c=2,t=24,pt=0,l=0,sg=0,st=ok:
read: 0-0-5 s=1,c=2,t=24,pt=0,l=2,sg=0:40
TEMP = 40
send: 5-5-0-0 s=2,c=2,t=2,pt=0,l=0,sg=0,st=ok:
read: 0-0-5 s=2,c=2,t=2,pt=0,l=1,sg=0:1
STATUS = 1
In the sketch I then changed the value of V_TEMP from 1 to 0 ("off") and V_VAR1 from 40 to 60 and runned the sketch again. In Domoticz I can see that both values have changed but when I checked the serial output I get this:

Code: Select all

send: 5-5-0-0 s=1,c=1,t=0,pt=2,l=2,sg=0,st=ok:60
send: 5-5-0-0 s=2,c=1,t=2,pt=2,l=2,sg=0,st=ok:0
send: 5-5-0-0 s=1,c=2,t=24,pt=0,l=0,sg=0,st=ok:
read: 0-0-5 s=1,c=2,t=24,pt=0,l=2,sg=0:40
TEMP = 40
send: 5-5-0-0 s=2,c=2,t=2,pt=0,l=0,sg=0,st=ok:
read: 0-0-5 s=2,c=2,t=2,pt=0,l=1,sg=0:0
STATUS = 0
The value of STATUS has changed but the value of TEMP has not. I have restarted the controller (Pi) but the value of TEMP keeps on showing 40 instead of 60. Any idea?
User avatar
gizmocuz
Posts: 2488
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: MySensors gw.request()

Post by gizmocuz »

You can only request V_VAR messages, and in the top of your code i see you try to request a V_TEMP

MyMessage msgvar1(ID_VAR1, V_TEMP);

this will not work, if you change it to

MyMessage msgvar1(ID_VAR1, V_VAR1);

it should
Quality outlives Quantity!
HarryDutch
Posts: 8
Joined: Sunday 03 January 2016 11:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MySensors gw.request()

Post by HarryDutch »

Ok, it's working now. Thanks.
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: MySensors gw.request()

Post by Flopp »

gizmocuz wrote:You can only request V_VAR messages, and in the top of your code i see you try to request a V_TEMP

MyMessage msgvar1(ID_VAR1, V_TEMP);

this will not work, if you change it to

MyMessage msgvar1(ID_VAR1, V_VAR1);

it should
How can I change VAR1 in Domoticz interface?
I don't want to open Domoticz.db.
User avatar
gizmocuz
Posts: 2488
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: MySensors gw.request()

Post by gizmocuz »

you can not
from your mysensors node, you can set a V_VAR

and you can read a V_VAR from your mysensors node

can be used to store a counter value for example (see the watermeter sketch)
Quality outlives Quantity!
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: MySensors gw.request()

Post by Flopp »

gizmocuz wrote:you can not
from your mysensors node, you can set a V_VAR

and you can read a V_VAR from your mysensors node

can be used to store a counter value for example (see the watermeter sketch)
Thank you
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest