0

I have a 64 bit address that i want to store in a sqlite db column. The column is of type VARCHAR. This is how i store the data to the db. The sql is done in python using the cursor object c.

c.execute("INSERT INTO SENSORS(XBEE_ID) VALUES('\x00\x13\xA2\x00\x40\xe9\x21\x9d')")

I want to then read that address from the database and pass it to a function that will then send the data to some xbees. I am using a xbee library that accepts the address in the form:

dest_addr = '\x00\x13\xa2\x00\x40\xe9\x21\x93'
xbee.tx(dest_addr_long = dest_addr ,data=newState)

when i use

repr(dest_addr) 

I get

 '\x00\x13\xa2\x00@\xe9!\x93'

also

type(dest_addr)

gives

<type 'str'>

But when I read the data from the database, and store to a variable,I get an error "the data provided for 'dest_addr_long' was not 8 bytes long.

 addr_long = c.fetchall()
 addr_long2 = addr_long([0][0])
 xbee.tx(dest_addr_long = addr_long2,data=newState)

when i read the data from the db it is of type unicode.

repr(send_addr[0][0])

which returns

u'\\x00\\x13\\xa2\\x00\\x40\\xe9\\x21\\x93'

and

<type 'unicode'>

, so i tried this - Convert a Unicode string to a string in Python (containing extra symbols) but it did not work.

I am basically looking for the opposite of this . Converting string into hex representation

**so my questions, is my method right for storing the data in the db?

how can I manipulate the data so that I can get it in the string type that is required for the function?**

Community
  • 1
  • 1
  • 1
    Show a concrete example (`repr()` format) of what you are currently receiving and what you actually want, like: got `u'\x00\x13\xA2\x00\x40\xe9\x21\x9d'` (a Unicode string) and want `'0013A20040e9219D'` (a byte string), or maybe `'\x00\x13\xA2\x00\x40\xe9\x21\x9d'` (a byte string). Also, what Python version are you using? – Mark Tolonen Feb 20 '16 at 02:13
  • SQL does not use backslash escapes. Is your first code SQL or Python? – CL. Feb 20 '16 at 12:03
  • Hey, I I am using python 2.7.3. – Matthew Emillio Feb 20 '16 at 15:07
  • Which XBee library are you using and what does the documentation say about the function signature (i.e. argument types) of `xbee.tx(dest_addr_long, data)`? – RootTwo Feb 21 '16 at 02:45
  • i am using this library https://pypi.python.org/pypi/XBee . In the library it specifies 8 bytes long for dest_addr_long – Matthew Emillio Feb 21 '16 at 14:42

1 Answers1

0

so after some research and help from a friend, you can simply use

send_addr[0][0].decode("string_escape")