View Full Version : rpc(rpcSourceAddr(),...) help needed
martinnossel
12-01-2008, 01:35 AM
If the nodes send
rpc("\x00\x00\x01","sleep_status")
in the code below is in potal
def sleep_status():
...global can_sleep
...rpc("\x00\x38\xe1", "sleep_state", can_sleep)
this works .. but how to I do this for a large amout of nodes. with new ones being added all the time.
...#rpc(rpcSourceAddr(), "sleep_state", can_sleep)
this should work (from examples)... but does'nt
The nodes also have this routine
Martin
def sleep_state(status): # sleep status from portal
....global can_sleep_flag, rpcEvent_flag
....rpcEvent_flag = True #to check for new answer
....can_sleep_flag = status
....tellSensorState_call()
For interest.
the nodes stay awake, and re-request the information if the
rpcEvent_flag = True, (in the 100ms routine every 2 seconds)
kbanks
12-01-2008, 08:43 AM
...#rpc(rpcSourceAddr(), "sleep_state", can_sleep)
In Portal scripts, you use variable remoteAddr, not function rpcSourceAddr() to get the same effect.
One of the "pushes" for the 2.2 release will be making the APIs more consistent between Portal scripts and SNAPpy scripts.
vijayaraj
05-19-2009, 07:41 AM
Hi,
Each time master receives the data from a node after broadcasting sendSensorData() to all the nodes present in the network using mcastRpc,Master should know from which node data is received.
Thanks,
kbanks
05-19-2009, 08:08 AM
That depends on who (which node) is invoking sendSensorData().
Let's call the node that contains the sendSensorData() function Node "A".
If some other node "B" uses an RPC to invoke sendSensorData() in "A", then sendSensorData() is correct as written. By using the rpcSourceAddr() function, the sendSensorData() code will make a sensorData() report back to the original caller.
If instead of what I described above, the node ("A") containing the sendSensorData() routine calls sendSensorData() (in other words, he calls himself), then the code as written will not do anything useful.
If you look at the description for rpcSourceAddr() in the SNAP Reference Manual, it says:
If you call this function when a RPC is not in progress, it just returns None
Built-in rpcSourceAddr() is only meaningful while you are actually processing a Remote Procedure Call.
vijayaraj
05-20-2009, 08:24 AM
Thanks for the reply.I tried using rpcSourceAddr().When i tried reading the address using print statement,the device address appears to be in junk format in the hyper terminal display.So i tried converting the address to string using str(object),then read still appeared to be in junk format.Can i have some suggestions from you how to display the address in the readable format in the hyper terminal.
mgenti
05-20-2009, 08:28 AM
All of the SNAP network addresses can contain non-printable characters which will show up as "junk" when being "printed". For example a lot of the network addresses start with 0x00 which in ASCII is a null character. You'll need to write a function that converts these non-printable characters into something that is in the ASCII printable characters range.
msellers
05-20-2009, 09:52 AM
Look at the dumpHex function in the hexsupport.py file found in the Synapse folder of sample scripts.
mac = loadNvParam(2)
dumpHex(mac[5:8])
kbanks
05-20-2009, 12:42 PM
or dumpHex(rpcSourceAddr()) in your specific case...
vijayaraj
05-21-2009, 09:40 AM
Hi,
Node B is invoked by Node A.
My query is,In the rpc function of the Node B,the destination address is replaced by the rpcSourceAddr().Since destination address can be any and also packet to reach the correct destination,will the packet transmitted containing the data will search each and every node for the 'sensorData' function?
Jheath
05-21-2009, 10:31 AM
My query is,In the rpc function of the Node B,the destination address is replaced by the rpcSourceAddr().Since destination address can be any and also packet to reach the correct destination,will the packet transmitted containing the data will search each and every node for the 'sensorData' function?
rpcSourceAddr() is used to substitute the address of the node that made the function call.
In this case, the RPC will use the rpcSourceAddr() function to determine the unicast destination address. It will attempt to call 'sensorData()' on ONLY the node that made the original call into 'sendSensorData()'.
In other words, if node A called into node B, then the RPC will look like this:
rpc( '\xFF\xF3\x2C', "sensorData",adcValue)
If several nodes call the 'sendSensorData()' function on node B, then node B will respond to each of them individually ( by calling 'sensorData()' ).
If you would like for node B to communicate with multiple nodes ( ie search out sensorData() ) you can use the mcastRpc(...) functionality and implement the function 'sensorData()' on only the nodes you would like to process the command.
vBulletin® v3.8.0, Copyright ©2000-2012, Jelsoft Enterprises Ltd.