Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Mac address format to hexadecimal

    Scheduled Pinned Locked Moved MicroPython
    mac addresslopy lora modelorabytes
    4 Posts 2 Posters 2.3k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      timeb
      last edited by

      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?

      0_1493210203929_SRC_ADDR.PNG

      1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh
        last edited by

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

        T 1 Reply Last reply Reply Quote 1
        • T Offline
          timeb @robert-hh
          last edited by

          @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.

          robert-hhR 1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @timeb
            last edited by

            @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.

            1 Reply Last reply Reply Quote 1

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • 1 / 1
            • First post
              Last post

            Pycom on Twitter

            Pycom