Announcement

Collapse
No announcement yet.

mcastRpc can it pass arguments to a calling function

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • mcastRpc can it pass arguments to a calling function

    I wanted to know if the following function in my snappy script

    Code:
    mcastRpc(group, ttl, function, args...)
    can pass an argument to a RPC function for instance if the function has a definition as this

    Code:
    Node A (group 0x0001)
    def mcast_in(txt):
         print txt               --->Will this print "Hello" ?
    
    Node B (group 0x0001)
    mcastRpc(0x0001,5,'mcasr_in',"hello")
    My question is will the above work ? I am not sure since it uses args... and I read that snappy scripts do not support optional/default parameters

  • #2
    Yes, once you fix the typo in the calling function where the function name has an r instead of a t for mcast_in.

    Function names of the remote nodes functions need to be in single or double quotes like you have it and arguments can be strings in single or double quotes or numbers. Each argument you wish to send should be separated by a comma in the call. So in this case you are only passing one argument a string to the function, but you can pass many more.

    Code:
    # function with more than one argument
    def multiArgFunc(value, string, state):
        if state == True:
            print string
        print "my value is: ",
        print value
    Now from remote node

    Code:
    mcastRpc(1,5,'multiArgFunc', 1, "testing string", True)
    Just a side node that mcastRpc can be used or rpc that is routed to the node can be used where you specify the address rather than group and hop count.

    Comment


    • #3
      Originally posted by rob_hood View Post
      I wanted to know if the following function in my snappy script

      Code:
      mcastRpc(group, ttl, function, args...)
      can pass an argument to a RPC function for instance if the function has a definition as this

      Code:
      Node A (group 0x0001)
      def mcast_in(txt):
           print txt               --->Will this print "Hello" ?
      
      Node B (group 0x0001)
      mcastRpc(0x0001,5,'mcasr_in',"hello")
      My question is will the above work
      Yes, this is exactly what RPCs and McastRPCs are meant to do.

      and I read that snappy scripts do not support optional/default parameters
      Correct SNAP does not support default parameter overloading. You must specify all defined parameters.

      Do you mean having a parameter automatically filled in if it isn't specified?
      Ex. you'd expect the following to set "savedVal" to 70.

      Code:
      def func1():
           savedVal = doSomething()
      
      
      def doSomething(plusThis= 10):
            return data = 60 + plusThis

      If so you could do something like the following:

      Code:
      defaultVal = 10
      
      def func1():
           savedVal = doSomething(None)
      
      def doSomething(param1):
            if param1 == None:
                  plusThis= defaultVal 
            else:
                  plusThis= param1
            return data = 60 + defaultParamVal
      sigpic
      Proven Solutions for the Internet of Things
      www.synapse-wireless.com

      Comment


      • #4
        @Jamos. Thanks for the help. I'll test this out and post back if I have any questions. Thanks.

        Comment

        Working...
        X