Global event for all nodes

Started by jorgmuskens, July 23, 2016, 05:19:42 AM

jorgmuskens

Hi,
I am looking for a way to have a global scheduled event that sends a message to all my nodes.
Currently i am using an event on each node which works but maintaining them is a pain.
So i was wondering as the event that i am send is the same for each node on how to get in fired without adding it to a node.
I did some digging in the gateway.js file where i see the schedular is maintained but i am not clear how to add a schedular that will run in the background.
For example i have a event that a node has te report it status when i request it. I have a button on the home page which sends a message with nodeid:255 so all nodes report in. This works perfectly but now i want schedule it from my home page. so this action is automated on the time i set.
I looked in some node packages like node-cron but i was wondering if i could add it in the standard code of the pi gateway.
Hope someone can help me running a schedular that sends out a time message to all my devices.
Thanks
Jorg Muskens
The best way to get something done is to begin

Felix

Hi Jorg,
This would be some kind of global event rather than node event.
Should not be too difficult to add to the main page, in a similar way it is added to the node. The difference is you have to keep the definitions separately from the metrics.js events and save the scheduled ones to the DB in a different collection.
To send a broadcast message to all nodes just have the event call sendMessageToNode(node) and set the node.nodeId=255, that makes the gateway Moteino message that is sent out be received by all listening Moteino nodes.