SonyCSL / OpenECHO

Owada : Java Implementation of ECHONET Lite
GNU General Public License v3.0
36 stars 15 forks source link

How to get Echonet Lite node value when it change #11

Open CuongNXV opened 4 years ago

CuongNXV commented 4 years ago

I only get device value one time when it registers with Home Gateway, after that i do not receive any packet from it. I want to know whether value of a node changed, can you show me how to do that.

sowd commented 4 years ago

Spontaneous notification of value change is mandatory for very few important properties in Echonet Lite to support low power device/narrow network bandwidth (though not prohibited.) Please check the latest appendix sheet.

https://echonet.jp/spec_object_rl_en/

Currently, only 3 properties in the super class require announcement, while air conditioner has 2 additions.

CuongNXV commented 4 years ago

Because I want to get value of device continuously. So I use While(true) to loop for requesting and then receiving the message from devices. But I must create a lot of separate threads for each device. How can I request and get device information continuously without using while(true)? Because I want to use a single thread for one class code device. image

sowd commented 4 years ago

Because of the protocol spec, the only way to trace value change of non-announcing properties is to use 'polling' technique. It is essentially the same as your while(true) loop. You have to send requests multiple times and check the responses (as frequent as you want, but don't put too much pressure on low-power devices.)

Using multiple threads is a good idea, but be careful not to send many packets to one device at once, because it causes packet loss (because you are using UDP) or overwork of devices with small network capacity.