Mac address format to hexadecimal

  • I wanted to take the last four bytes of the mac address of the lopy as shown in the code. I just tried to print it as hexadecimal value but it keeps giving me an error. What could possibly be the problem?


  • @timeb The data returned by lora.mac() is a 8 byte binary quantity in a bytes object. These bytes may not be printable chars. And it is also not an integer, and can therefore not be printed with the %x specifier. If you want to print it in a ASCII-Hex representation, you have to convert that with ubinascii.hexlify, like you did, and print it with the %s specifier. The results is a string. How you further proceed with the data, is up to you. You could use the binary object or the string.

  • @robert-hh So, it means I can only use the address as a %s format not as hexadecimal value. Because my intention was to use it like a device id where by I send a message to a particular node with a specific mac address.

  • You converte SRC_MAC_ADDR to a string in line 31, so you have to use %s a format specifier in line 34.

Pycom on Twitter