How can gateway and node talk to each other?

Started by Clemens, June 24, 2015, 07:20:52 PM

Clemens

Normally the node is sending data and the gateway is receiving it. In the Moteino example sketches the only way back is an Ack to say "all ok, I got it!" But how can I establish a kind of communication? E.g. the node is sending data but from time to time it needs a fresh time stamp. So the node shoud ask for "time" and the gateway should respond with "1435187851"

Is there an example file for such a use case like this: I'm sending time based (let's say every 15 minutes) data to the node but once a day or triggered by an event the node should get a timestamp or other information. So the node should sent "time" but now the gateway should not return an Ack but the current timestamp from the network. Or the node can ask for a new time interval for logging "new interval" so the gateway can answer "nothing new" or "30 minutes".

Felix

There are plenty of examples like that. I don't need to point further than the classic Gateway and Node examples. Each listening radio can receive any packet and do whatever it decides with it - respond to a command, send only an ACK, do nothing and ignore it etc. Example nodes that take action based on a packet from the gateway are GarageMote and SwitchMote. They always listen for commands and respond back to commands by sending ACKs and also status packets afterwards.

FWIW Other than temporary storage of timestamped packets I don't really understand how a timestamp would be useful to a node which just reports it back. When a node packet is received at the gateway it knows the time it was received. If stored packets are transmitted periodically then yes a timestamp would be useful.

Clemens

The node should do some things only at day or at a dedicated time during the course of the day. So I need time information on the node.

Felix

That's easy. Have the node ask the gateway for a timestamp, then the node can keep track of time approximately while it's sleeping. Or it can ask for time again when it wakes up.

TomWS

#4
Quote from: Felix on June 27, 2015, 08:42:44 AM
That's easy. Have the node ask the gateway for a timestamp, then the node can keep track of time approximately while it's sleeping. Or it can ask for time again when it wakes up.
As Felix suggested, your node can ask for the current time from the Gateway (or that can simply be a standard part of the Ack from the Gateway without requiring a specific 'ask').  When the Gateway responds, the time value will certainly be within the resolution of a unix timestamp.  Then you can calculate when you need to wake up again (bearing in mind that the timestamp is in seconds, not milliseconds).  I'd use the Sleep_n0m1 library to set the next wakeup time exactly.

As in:
#include <Sleep_n0m1.h>
...
    radio.sleep();
    sleep.pwrDownMode();   //set sleep mode
    sleep.sleepDelay(sleepTime); //sleep for: sleepTime

Tom

Clemens

Btw. how long should be a time slot for a node to wait for response data, e.g.

Node: "send me this and that"
Gateway: "here you are: that and this"

I found in some example sketches
#define ACK_TIME      30 // max # of ms to wait for an ack

How fast is a response normally and how long should waiting time be in case I want save power and send a device in sleepmode and do this also in case a package did not receive by accident. So wait and waste power not for eternity.

Felix

It depends on the packet length. If you want a precise measure use a scope or logic analyzer to look at the SPI traffic and watch for a specific packet length. Otherwise 30ms should be plenty for a 66byte packet.