Network discovery sequence ?
I'm about to write my own controller as a personal eduction purpose project.
I read the serial api doc, but I can't find a description how the communication / protocol is organised and more specifically the discovery of all sensors / new sensor occure.
When starting the gateway, is there a broadcast packet sent so that all sensors can answer and notify there online presence ?
How new sensor are discovered ? or notify the gateway ?
Actually, is there a kind of flowchart explaining the communication?
The sensors will always present themselves (to the controller) when they start. You shouldn't really need to care about how the actual gateway/sensors communicate between each other.
The serial protocol could probably need more documentations, so please let me know is anything is unclear.
ok so that means the gateway must be online before the sensors start.
You shouldn't really need to care about how the actual gateway/sensors communicate between each other.
I absolutely agree.
Few points I don't really understand are :
- In the communication examples the msg
12;6;0;0;3;My Light\nis, as described, node id=12, sensor id=6, message-type =presentation, for a sub-type=S_LIGHT. But how the 12 and 6 are set ? From the doc I can see that there is I_ID_REQUEST sub-type, so I'm guessing that the controller provide the gateway with a node-id to set on sensor. So before the presentation msg, is there a kind of setup between the sensor and the gateway (In this process the GW may send internal msg w/ a subtype I_ID_REQUEST) ?
- Still with the
12;6;0;0;3;My Light\nexample, is the 6 provided by the GW ?
Is the My Light hard coded on the sensor management program ?
- How can we detect if a sensor is not on the grid anymore ? Has the GW got a routine so it periodically check if all kown nodes / sensors are still available ?
- In the communication examples the msg
I'm currently working on a OH2 Binding and I'm at the same point like you.
A sensor has no node id if the node id is not defined in the sketch itself (default in the examples) and the sensors hasn't received an id. The sensor stores its id in the EEPROM.
If it has no id, it will ask the network for an id:
The request is received by the gateway, so yes, a gateway is needed at this time. The gateway hands the request to the controller and responds with something like:
Where <id> is the new id. For this example it is:
Now the sensor starts to represent itself to the gateway. My test-sensor sends something like:
172;255;0;0;18;1.4.1 172;255;3;0;6;0 172;255;3;0;11;Humidity + Temp + Relay 172;255;3;0;12;1.0 172;0;0;0;7;1.4.1 172;1;0;0;6;1.4.1 172;2;0;0;38;1.4.1 172;3;0;0;3;1.4.1
This sequence shows the version of the mysensors lib (1.4.1), a description of the node (Humidity + Temp + Relay) and the version of the sketch (1.0) given in the sketch.
After that it represents its childs with the child ids defined in the sketch:
7 for S_HUM
6 for S_TEMP
38 for S_VOLTAGE
3 for S_LIGHT
There is no way to detect if a sensor is part of the grid, because it may be dead or it may be sleeping. For the sensors I need that information from I send a keep alive message every now and then.
To clarify, if the node id is not defined, the remote sensor node does have an id! All though it is not a fixed one, it is id 255. This is also the reason why a id response is send to 255.
This means also that if sensors are added to the network without a fixed pre-defined id you can only add one sensor node at a time.
[EDIT]Like TimO says, the id will eventually be the id which is send back.
What you can do is send a reboot command to this new id and if both the new id assignment message and the reboot message are received the sensor will come up again and with the new id.
If the remote node does not come up again, restart the node manually to see if node id 255 does or does not re-appear. If it re-appears the message has failed. If the new node id comes up the id assignment message has been received and applied.
Also as far as i have seen a node id assignment always gives a failed response in the gateway meaning it is not a guaranteed message.
Someone correct me if i'm wrong
Thx TimO, John, great answers !
Can you shed some light on these msg please
172;255;3;0;11;Humidity + Temp + Relay //<< is the controller that define the 'Humidity + Temp + Relay' ?
172;255;3;0;6;0 //Seems to be an internal::I_CONFIG but why 0 is sent ? shouldn't be I or M ?
172;0;0;0;7;1.4.1 172;1;0;0;6;1.4.1 172;2;0;0;38;1.4.1 172;3;0;0;3;1.4.1 //these are presentation msg but Is the '1.4.1' define in your sketch ? Same as this example 12;6;0;0;3;My Light I don't really understand where the 'My Light' come from
The first one is the presentation name of the sketch on the remote node
With the second one the 0 is just an arbitrary character as I_CONFIG is just a request to the controller to send back imperial or metric
The last one are the version numbers of the library on the remote node.
Take a look at: http://www.mysensors.org/download/serial_api_14 it all is explained there