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

    Serial to UART POST JSON

    Scheduled Pinned Locked Moved Expansion Board
    uart1jsonpost
    5 Posts 2 Posters 1.2k 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.
    • J Offline
      jimpower
      last edited by

      Hi All,

      I have a weigh station transmitting weight data via RS232, I have connected this to UART1 pins 3 & 4 pins via TTL and I can receive ASCII string and print this using the

      print("Weight POST Successful - " + str(uart1.readall()) + " g")

      however when i use the same to print into a JSON payload it prints none.

      Here is the code

      while True:

      res = urequests.post('https://My_URL', json={'Weight': str(uart1.readall())})
      res.close()
      if (res.status_code - 200) < 100: # check that response code is in the 200 range
          print("Weight POST Successful     - " + str(uart1.readall()) + " g")
      else:
          print('there was some error')
      
      gc.collect()
      pycom.heartbeat(False)
      
      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @jimpower
        last edited by livius

        @jimpower
        Do you mean that

        print("Weight POST Successful     - " + str(uart1.readall()) + " g")
        

        does not print anything

        or

        res = urequests.post('https://My_URL', json={'Weight': str(uart1.readall())})
        

        does not send anything? or both?

        You must know that uart1.readall() clear buffer and second uart1.readall() read nothing (or new incomming data)
        you must store data into var to use it in second print

        e.g.

        tmp = uart1.readall()
        

        think about people first, then computers

        J 1 Reply Last reply Reply Quote 0
        • J Offline
          jimpower @livius
          last edited by

          @livius

          res = urequests.post('https://My_URL', json={'Weight': str(uart1.readall())})

          sends none

          print("Weight POST Successful - " + str(uart1.readall()) + " g")

          prints as expected

          the second print is only to see what is coming through in terminal I can remove it as its not required.

          If I were to use it as you suggest would it look like this?

          while True:

          tmp = uart1.readall()

          res = urequests.post('https://My_URL', json={'Weight': str(tmp())})
          res.close()
          if (res.status_code - 200) < 100: # check that response code is in the 200 range
          print("Weight POST Successful - " + str(tmp()) + " g")
          else:
          print('there was some error')

          gc.collect()
          pycom.heartbeat(False)

          L 1 Reply Last reply Reply Quote 0
          • L Offline
            livius @jimpower
            last edited by

            @jimpower said in Serial to UART POST JSON:

            tmp()

            without parenthesis

            think about people first, then computers

            1 Reply Last reply Reply Quote 0
            • J Offline
              jimpower
              last edited by

              @livius

              I added tmp = uart1.readall() and it works thanks again I managed to do this before your reply thanks again you are always very helpful

              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