Announcement

Collapse
No announcement yet.

rpc address and callback

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

  • rpc address and callback

    I would like to send a response back to the node that requested information previously. I have the value of the address in the string as follows...

    ::\x03\xea\x5a::OK_TO_START::

    I am trying to pull the node address from the string of serial data and send a response. When printed I see \x03\xea\x5a as expected. However when incerted in to the rpc() it doesn't work. Any help would be appreciated.

    def sendResponse(pf):
    print "sendResponse", pf ;

    #process for the address

    tagaddress = pf[2:14]
    response = pf[14:32]

    #tagaddress = '\x03\xea\x5a'

    rpc(tagaddress, 'tellLCD', response)

  • #2
    Node addresses are 3-character strings. What you have here is a 12-character string, so of course it doesn't work as a node address. It's in the same format that you'd use to write a hard-coded address in the source code, but there's no built-in function to interpret this format at runtime. A converter could be written, but it would be better to simply never convert the address into this inappropriate format in the first place.

    Comment


    • #3
      rpc('\x03\xea\x5a', 'tellLCD', response) works

      rpc('03ea5a', 'tellLCD', response) doesn't

      tagaddress = '\x03\xea\x5a'
      rpc(tagaddress, 'tellLCD', response) doesn't

      tagaddress = '03ea5a'
      rpc(tagaddress, 'tellLCD', response) doesn't


      What am I missing? What should I make tagaddress equal to have it function as the node address?

      Comment


      • #4
        '\x03\xea\x5a' is a Python string literal containing 3 characters (each given as a hexadecimal escape sequence).

        '03ea5a' is a Python string literal containing 6 characters. They can be interpreted as a 3-byte hexadecimal value, but nothing is going to do that interpretation unless you explicitly write it.

        Your 1st and 3rd examples should be doing exactly the same thing, if one isn't working then there must be some other difference in your actual code.

        Comment


        • #5
          Thanks for the support. Now I understand. Even though I could type in the address like this...

          rpc('\x03\xea\x5a', 'tellLCD', response)


          ...forwarding the string like this:

          ::\x03\xea\x5a::OK_TO_START::

          def sendResponse(pf):
          print "sendResponse", pf ;
          #process for the address
          tagaddress = pf[2:14]
          response = pf[14:32]
          #tagaddress = '\x03\xea\x5a'
          rpc(tagaddress, 'tellLCD', response)

          ...won't work because it needs the actual 3-character string --> [.?

          I was under the impression that the rpc(tagaddress, 'tellLCD', response) call would interpret tagaddress as \x03\xea\x5a like it does when it is hard coded. Which it does, but it doesn't handle it the same way. I found a hex converter to bring the six character 03ea5a tag address to the 3 character string which works.

          http://forums.synapse-wireless.com/s...onvert+str+hex

          Comment


          • #6
            You might also look into the rpcSourceAddr() function. This will allow you to respond to the correct node every time.

            BoB

            Comment


            • #7
              Originally posted by mlorio View Post
              I was under the impression that the rpc(tagaddress, 'tellLCD', response) call would interpret tagaddress as \x03\xea\x5a like it does when it is hard coded. Which it does, but it doesn't handle it the same way. I found a hex converter to bring the six character 03ea5a tag address to the 3 character string which works.
              @mlorio it boils down to the difference between ASCII and HEX characters.

              When does '3' = 3 and '3' = 51?

              When you create a static string like "\x03\xea\x5a" the underlying Python knows you are actually specifying a Hex String of 0x03EA5A (ie a 3-byte sting '0x0'+'0x3'+...+'0xA'). However, if you simply provide a string to elements expecting ASCII characters, it has no choice but to take you literally and think you are giving it a string of valid characters. That means '3' is an ASCII value of 51 decimal or 0x33 hex.

              Here is a link to a chart related the characters:
              http://www.cdrummond.qc.ca/cegep/inf...iles/ascii.htm
              Originally posted by mlorio View Post
              I found a hex converter to bring the six character 03ea5a tag address to the 3 character string which works.
              The utility you found does the math and bit manipulation to covert from a "3" to a "3" - but only for the 3-byte address format.

              As @rbelli points out, the quickest way to get the address of the SNAP node that called that particular RPC is to use rpcSourceAddr(). You can grab your own address using the function "localAddr()". More information can be found in the SNAP Reference manual.
              sigpic
              Proven Solutions for the Internet of Things
              www.synapse-wireless.com

              Comment

              X