User manual

a) When the target node does hear the rpc() call, the ACK packet is sent automacally (by the SNAP
firmware you do not send the ACK from your script).
b) If the target node does not hear the rpc() call, then it does not know to send the ACK packet. This means
the source node will not hear an ACK, and so it will meout and retry a configurable number of mes.
Going back two examples, instead of modifying the askSensorReading() funcon in node B’s script to take an
addional “who” parameter, and calling
mcastRpc(1, 1, "askSensorReading", address_of_node_B)
node A could simply call:
rpc(address_of_node_B, "askSensorReading")
Nodes C-Z would ignore the funcon call (although they may be helping route the funcon call to node B
without any addional configuraon required by the user).
The askSensorReading() funcon could also benefit from the use of rpc() instead of mcastRpc().
Instead of telling all nodes in group 1 and 1 hop away what the sensor reading is via:
mcastRpc(1, 1, "tellSensorReading", value)
the script could instead send the results back to the original requestor only via:
rpc(rpcSourceAddr(), "tellSensorReading", value)
Funcon rpcSourceAddr() is another built-in funcon that, when called from a funcon that was invoked
remotely, returns the SNAP Address of the calling node. (If you call rpcSourceAddr() locally at some arbitrary
point-in-me, such as within the HOOK_STARTUP or HOOK_GPIO handler, then it simply returns None.)
Note that the funcons being invoked, by either an rpc() call or an mcastRpc() call, could be built-in (such as
readPin(), readAdc(), random()) or could be user-defined (defined within the currently loaded SNAPpy script).
Callback(callback, remoteFunction, remoteFunctionArgs )
Both the previous methods allowed one node to ask another node to perform a funcon and then send the
result of that funcon back to the first node. In each case, the first node called the askSensorReading() funcon,
whose only purpose was to call a separate funcon (readSensor()) and then send back the value from that.
It turns out that SNAP has a built-in funcon to do just that, the callback funcon.
Going back to a previous example, and expanding on it a lile:
def readSensor():
return readAdc(0) * SENSOR_GAIN + SENSOR_OFFSET
def askSensorReading():
value = readSensor()
mcastRpc(1, 1, "tellSensorReading", value)
In a scenario like this, roune readSensor() is pulling its own weight it is encapsulang some of the sensor
complexity, thus hiding it from the rest of the system.
Somemes, however, the raw sensor readings are sufficient (or the calculaons are so complex that they need
to be offloaded to a bigger computer).
This results in the code being changed to something more like:
def readSensor():
SNAP® Network Operang System 35