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

    Console output messed up using Pymkr plugin "Run"

    Scheduled Pinned Locked Moved Issues & Bugs
    consolethread
    9 Posts 3 Posters 2.6k Views 3 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.
    • A Offline
      Andrea Filippini
      last edited by livius

      Hi all, I'm using a few threads in my script but I have a problem with the console. The first thread that I start is used to manage the WiFi connection as described in the tutorials like this:
      [REMOVED AS OF EDIT2]

      The problem is that at first boot (at power up) I only get this thread's output. Any other "print" gets lost.
      The only way to be able to see the output is to stop and restart the script (i'm using Atom plugin) so the WiFi stays connected an the output is brief.

      How can I solve this? I'm facing serious problems developing

      EDIT:
      Thanks to @Innocenzo I can say for sure that the issue is with the Pymkr plugin for Atom. If I use "execfile('main.py')" all the output is printed (even inside the Atom console); this means that there's a bug in the "Run" command

      EDIT 2:
      Use this code to reproduce the problem (change wifi credential to a valid one). Using the "Run" command the output stops after successfully connecting to the WiFi network.
      If you use "execfile()" the output keeps being printed

      import _thread
      import time
      import machine
      from network import WLAN
      
      
      def th_wifi_mng(delay):
          try:
              wlan = WLAN()
              found = 0
              while True:
                  if not wlan.isconnected():
                      nets = wlan.scan()
                      for net in nets:
                          if net.ssid == "yourSSID":
                              wlan.connect(net.ssid, auth=(net.sec,"yourPsw"), timeout=5000)
                              found = 1
                      if found == 1:
                          while not wlan.isconnected():
                              machine.idle() # save power while waiting
                  wifi_connected = wlan.isconnected()
                  time.sleep(delay)
          except Exception as e:
              print('th_wifi_mng', e)
      
      
      # WiFi initialization
      wlan = WLAN()
      if(wlan.mode() != WLAN.STA):
          wlan = WLAN(mode=WLAN.STA)
      
      # spawn threads
      _thread.start_new_thread(th_wifi_mng, (2,))
      
      while True:
          print("main loop")
          time.sleep(.1)
      
      I 1 Reply Last reply Reply Quote 1
      • I Offline
        Innocenzo @Andrea Filippini
        last edited by

        @Andrea-Filippini Try to execute your code on Terminal like Tera Term or Termite. Sometimes the Atom plugins does not print me everything.

        A 1 Reply Last reply Reply Quote 0
        • A Offline
          Andrea Filippini @Innocenzo
          last edited by

          @Innocenzo I can connect to the REPL console via USB cable, but I don't exactly know how to run a python script from there :/

          I 1 Reply Last reply Reply Quote 1
          • I Offline
            Innocenzo @Andrea Filippini
            last edited by

            @Andrea-Filippini Use Filezilla or ampy to put your script on board. After, from REPL, use

            execfile("myscript.py")
            
            1 Reply Last reply Reply Quote 1
            • R Offline
              Ralph
              last edited by

              hi @Andrea-Filippini can you post your code, or a simplified version of it, so I can try to replicate the problem? The quick usage example from the docs seems to be working for me.

              A 1 Reply Last reply Reply Quote 0
              • A Offline
                Andrea Filippini @Ralph
                last edited by

                @Ralph See edit 2

                R 1 Reply Last reply Reply Quote 0
                • R Offline
                  Ralph @Andrea Filippini
                  last edited by

                  @Andrea-Filippini Thanks for posting your code. Using it I got the same issue and found the bug that was causing it. It's been solved in the latest commit on the develop branch on github. It'll be included in the next release. Until then, feel free to manually install the plugin from the develop branch

                  A 2 Replies Last reply Reply Quote 0
                  • A Offline
                    Andrea Filippini @Ralph
                    last edited by

                    @Ralph Thank you! I confirm the bug is fixed

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      Andrea Filippini @Ralph
                      last edited by Andrea Filippini

                      @Ralph It seems there's a new bug. (almost) Every time I click the "Sync" button all the files get uploaded. Also I notice something that looks like a piece of checksum being printed like this:

                      >>> Syncing project (main folder)...
                      
                      >>>
                      >>> [1/12] Writing file communication.py
                      c8474829a403c5fefb5e339b"]]
                      [2/12] Writing file config.py
                      [3/12] Writing file globals.py
                         [...etc...]
                      [12/12] Writing file utils.py
                      Synchronizing done, resetting board...
                      

                      EDIT:
                      Also, "Run" command on a file doesn't update the file on the flash, resulting in a strange behaviour if the current file is also present in the flash.
                      Editing the script and running it seems to use the classes from the file on the flash memory, and the "top level" instructions from the editor file :/

                      EDIT2:
                      Now the "Sync" end with an error. I rebooted the board, the PC and updated the firmware....

                      >>> Syncing project (main folder)...
                       
                      >>>
                      >>> [1/13] Writing file communication.py
                      [2/13] Writing file config.py
                      Synchronizing failed: Write failed. Please reboot your device manually.   
                      

                      EDIT3:
                      Fixed with the new release

                      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