🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Text encoding like iconv from UTF-8 to CP858 for Printer

    Scheduled Pinned Locked Moved UIFlow
    1 Posts 1 Posters 3.0k Views
    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.
    • S Offline
      schmid01
      last edited by

      Hello Community

      I have an M5Stack Ink Core that receives JSON Data via MQTT. Sofar thats running. Then it prints the Data over UART to an ESC/Pos Serial Printer. That runs too, but Text has to be encoded.
      The JSON Data seams to be UTF-8, the Printer needs CP858. I solved this in Node-blue like this:

      $str = "Encoded Text: ".iconv ("UTF-8" , "CP858" , $text).chr(0x0a); // Print Text and Line Feed

      Since I'm new to M5Stack / UiFLow, I tried it in Blocky:
      0_1639302700866_d6dda90b-1402-4a37-9324-3bb5a18cddb3-grafik.png
      But I couldn't make any Settings to the "decoding" Block, so I switched to the "Python" Tab and edited as following:

      uart2.write(str('Encoded Text').decode('utf-8').encode('cp858')+"\r\n")

      Since I'm also not familiar with Python I found those Guides:
      https://stackoverflow.com/questions/30662112/is-there-any-function-like-iconv-in-python

      I also found this Forumpost: https://forum.m5stack.com/topic/1897/ui-flow-text-encode-decode wich brings me to: https://docs.python.org/3/howto/unicode.html

      Is there someone who can help me, with even posting the Code I have to insert.
      Is it even possible to solve just within Blockly without changing to Python View?

      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
      • First post
        Last post