User manual

As an example, even though a node has no graphics display, it can sll generate a plot of link quality over me,
by using a code snippet like the following:
rpc("\x00\x00\x01", "plotlq", localAddr(), getLq())
For this to do anything useful, Portal must also have loaded a script containing the following definion:
def plotlq(who, lq):
logData(who, lq, 256)
The node will report the data, and Portal will plot the data on its Data Logger pane. It wouldn’t take much
addional code to instead save the data to a text file or a database, or even to include other GUI libraries for
your own custom visualizaons.
Remember you can invoke functions remotely
Wring modular code is always a good idea. As an added bonus, if you are able to break your overall script into
mulple funcon definions, you can remotely invoke the individual rounes to assist with unit tesng them.
This can help in determining where any problem lies.
Be careful using multicast RPC invocation
Realize that if you mulcast an RPC call to funcon “foo”, all nodes in that mulcast group that have a foo()
funcon will execute theirs, even if their foo() funcon does something different from what your target node’s
foo() funcon is expected to do. To put it another way, give your SNAPpy funcons disnct and meaningful
names.
If all nodes hear the question at the same time, they will all answer at the same time
If you have more than a few nodes, you will need to coordinate their responses (using a SNAPpy script) if you
poll them via a mulcast RPC call.
SNAP includes a Collision Avoidance feature (controlled by NV parameter 18) that inserts some random delay
(up to 20 ms) when responding to mulcast requests to assist in overcoming this. You can also enable Carrier
Sense (NV 16) and Collision Detecon (NV 17) to help ensure you do not have too many nodes talking at the
same me. But none of these will be as reliable as an applicaon-level control of when your node responds to a
request.
If you want to call a built-in function by name, the called node needs a script loaded, even if the script
is empty
SNAP Nodes without scripts loaded only support funcon calls by number. The “name lookup table” that lets
nodes support “call by name” is part of what gets sent with each SNAPpy Image.
When Portal invokes built-in funcons for you (from the GUI), it automacally converts funcon names to
funcon numbers. Standalone SNAP nodes don’t know how to do this conversion.
So, if you don’t have any real script to put into a node that you want to control from something besides Portal,
upload an empty one.
48 SNAP® Network Operang System