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

    FiPy | ubinascii | base64 decode

    Scheduled Pinned Locked Moved FiPy
    2 Posts 2 Posters 46 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.
    • B Offline
      bitvijays
      last edited by bitvijays

      Hello Pycom Team,

      I am trying to convert a base64 string received from Raspberry Pi to FiPY using UART using the below code. The Message size is approx 55000 bytes and transfer fine over uart.

      The below code works perfectly fine for small payloads. However for a bigger payload, it give Unicode error for the line uart_messages[counter] = msg.decode('utf-8') that is probably because the base64 string in msg = ubinascii.a2b_base64(temp[1]) is not decoded correctly. Have also attached a screenshot of print msg. As we can see, it converted it half and then failed. Any suggestions to resolve this would be appreciated.

                  for counter, item in enumerate(uart_messages):
                      # Message should be in format of :ML:70,base64string\n
                      if item.startswith(":ML:"):
                          temp = item.split(",", 1)
                          msg = ubinascii.a2b_base64(temp[1])
                          print(msg)
                          try:
                              uart_messages[counter] = msg.decode('utf-8')
                          except Exception as e:
                              print(e)
      
                  return uart_messages
      

      2298390e-c752-465f-bfac-33684322453b-image.png

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jcaron @bitvijays
        last edited by

        @bitvijays can you also print the base64 text before it is decoded?

        It seems to be the base64 text must have been missing a character, which then resulted in the the garbled output. If you look at the output, you’ll see it repeats every 15 characters, like the original text. I haven’t checked if that actually matches the binary day shifted by a few bits, but it’s most likely.

        UARTs can miss characters, especially at higher speeds. You need to add some way to ensure data is correct (a checksum or CRC), and either ignore bad data if that’s appropriate for your workflow, or add a way to retransmit bad data.

        1 Reply Last reply Reply Quote 0

        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