User manual
As an example, even though a node has no graphics display, it can sll 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 definion:
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
addional code to instead save the data to a text file or a database, or even to include other GUI libraries for
your own custom visualizaons.
Remember you can invoke functions remotely
Wring modular code is always a good idea. As an added bonus, if you are able to break your overall script into
mulple funcon definions, you can remotely invoke the individual rounes to assist with unit tesng them.
This can help in determining where any problem lies.
Be careful using multicast RPC invocation
Realize that if you mulcast an RPC call to funcon “foo”, all nodes in that mulcast group that have a foo()
funcon will execute theirs, even if their foo() funcon does something different from what your target node’s
foo() funcon is expected to do. To put it another way, give your SNAPpy funcons disnct 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 mulcast 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 mulcast requests to assist in overcoming this. You can also enable Carrier
Sense (NV 16) and Collision Detecon (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 applicaon-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 funcon 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 funcons for you (from the GUI), it automacally converts funcon names to
funcon 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 Operang System