Is there a way to check presence of a MySensors network, and proceed without if not found ?
-
I have a question I could not answer based on the documentation:
Is there a way to check presence of a MySensors network, and proceed without if not found ?
I would like to make a device that connects to a MySensors network if there is one, but can go into "standalone" mode if no network is present.
Right now it seems the node keeps trying to connect and never reaches the setup() function. It does pass the before() function.
-
#define MY_TRANSPORT_WAIT_READY_MS 5000
-
Can a node still do node to node communication of the gateway connection fails?
-
There was a russian user who make a couple of sketches where nodes could talk directly without gateway, but if I remember well they were not using gw at all. I don't think normal nodes can talk directly without a gw or a repeater in the middle.
-
@dbemowsk Search for node to node communication, you will find e.g.
https://forum.mysensors.org/topic/8716/direct-pairing-of-two-nodes-implementation
https://forum.mysensors.org/topic/826/node-to-node-communication and maybe some more.
-
@heizelmann I just asked because I figured that was where the OP was going with the question. Good to know though.
-
I'm now using this define MY_TRANSPORT_WAIT_READY_MS to get a "timeout" and I also use isTransportReady() to check if my device needs to work in stand-alone mode or if it is connected to the MySensors network once I exit the setup() fase.
I do not need to do node to node signalling without GW, but the info provided is nice to know
-
@gertsanders Can you show your script on this with the define MY_TRANSPORT_WAIT_READY_MS to get a "timeout" and using the TransportReady() ?
I would like to do the same with my BBQ-temp node since it has it's own display (node is for convenience to check temps on iPhone but not always needed).
-
just put " if TransportReady()" condition at beginning of loop and then execute code you want executed only if node is connected
-
As @gohan mentioned, you need to add the test in the loop. But you can also add it to the setup() function. I did find that sometimes the link with the network is not yet active at the start of setup(). But by the end of the setup() (in my case I need to start several objects), it is usually OK.
The define is just so that a timout is limited. I found 5 seconds a bit long, so I set it to 2 seconds
#define MY_TRANSPORT_WAIT_READY_MS 2000
and then in code I test:
void loop() { if (isTransportReady()) { // do stuff with network in place } else { // do stuff without network in place } } // end of loop()
-
@GertSanders The define was sufficient in my case:
#define MY_TRANSPORT_WAIT_READY_MS 2000
The sketch continues on startup when not able to connect (my BBQ-temp node is working stand alone) but will keep on trying to connect. When the gateway is found it will connect and the data is available on iPhone.
Thanks!
-
@gertsanders said in Is there a way to check presence of a MySensors network, and proceed without if not found ?:
I have a question I could not answer based on the documentation:
Is there a way to check presence of a MySensors network, and proceed without if not found ?
I would like to make a device that connects to a MySensors network if there is one, but can go into "standalone" mode if no network is present.
Right now it seems the node keeps trying to connect and never reaches the setup() function. It does pass the before() function.
This should be the default behavior IMHO. Otherwise, your node just hangs and is a nightmare to troubleshoot for new users.
-
@neverdie by "this", do you mean the current MySensors behavior, or the behavior suggested by gertsanders?
-
I'm not sure if the current default behaviour of MySensors is to wait for 5 seconds before giving up and moving on. I was under the impression that a node would try to find a network until my hair grows back.
When the define is included in the sketch, it clearly does it's job.
@NeverDie probably meant that we should not need to set the define, unless we want to change the default 5sec wait time, or if we explicitly want to have the node hang until a network is found.
So the question is, is the default behaviour to keep looking for a network, or does the library stop after 5sec and move on with the setup() ?
-
@gertsanders according to the documentation, the default value is 0 which means to wait forever.
Where did you get the 5 seconds from?
-
@mfalkvidd from an example where it mentioned
#define MY_TRANSPORT_WAIT_READY_MS 5000
I would expect this to be the default, and not '0'
-
@gertsanders I see. To me, providing an example that sets the value to its default value would make little sense since setting it would not change anything. But everyone interprets things based on prior experiences, and everyone's experiences are different.
I am unable to find an example that sets MY_TRANSPORT_WAIT_READY_MS in the MySensors git repo. Do you remember where you saw it?
-
@mfalkvidd said in Is there a way to check presence of a MySensors network, and proceed without if not found ?:
the behavior suggested by gertsanders
the behavior suggested by gertsanders
-
@mfalkvidd
Nope, I probably got this from a forum message somewhere. Iâm not sure where I got the suggestion to use the define.
The thing is, it is very nice to have this #define, but as @Neverdie said, it would be nice to avoid that a node âhangsâ if the gateway is unavailable. As far as I can see, there is no DEBUG message if the network is not reachable. And for a new MySensors user a hanging node is really confusing (it is sometimes for me as well). So this #define will now be part of me âdefaultâ template until the standard behaviour is adapted.
-
@gertsanders I think people have posted debug messages like this that indicate that the transport is not ready:
!TSP:SEND:TNR
But that probably only happens when the node is trying to send. If the node is not trying to send, there is no way to determine if transport is available.
-
I think it is logical to have sensors try indefinitely since this is the concept of sensors in a network.
Otherwise you would not know (when not debugging) all is ok in your network.
A network sensor not being one in an usual way, just for convenience (like my BBQ-temp sensor), has to be defined otherwise.
-
If you configure the controller to send notifications when nodes don't report anything after 1 or 2 hours, you know that something is wrong without draining the battery in the process.