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

    Can't connect to device when main.py is running

    Scheduled Pinned Locked Moved WiPy 2&3
    wipy 2.0replftpserialconnection
    10 Posts 3 Posters 2.8k Views 4 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.
    • C Offline
      ccarducci
      last edited by

      I'm not sure if this is by design (I hope not) or if I'm running into a strange issue. I have a simple boot.py file that starts up a UART serial and connects my wipy to my home network, and that seems to work fine. I have a main.py file that, once uploaded, seems to mostly work in terms of the buttons that it's supposed to interact with, but whenever main.py is running, I cannot make any connections to the board via FTP, SSH, OR serial-over-USB. I overrided main.py by pulling g28 to 3v3, connecting to FTP, and then deleting main.py. Now on restart I can connect again, but even if I try only to "Run" my script from atom/pymakr, I immediately lose the ability to connect to the device by any means.

      I can post my code if you think it'll help but wanted to check to see if this is known or if other people were having similar issues.

      1 Reply Last reply Reply Quote 0
      • D Offline
        DenDeze
        last edited by

        I would be happy to see your code,

        did you use the correct IP adres? Are you in a different subnet? Is your uart baud rate set in the main.py? you could alternatively try to rename your main.py to main1.py and execute after uploading and connectiong true uart with:

        execfile('main1.py')

        C 1 Reply Last reply Reply Quote 0
        • C Offline
          ccarducci
          last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • D Offline
            DenDeze
            last edited by

            You just posted your code and removed it...

            C 1 Reply Last reply Reply Quote 0
            • C Offline
              ccarducci @DenDeze
              last edited by

              @dendeze
              I will post the code below.
              I used the correct IP address. The MAC for my Wipy is reserved on my router. I haven't changed the IP in filezilla or atom. I get ping responses even when I cannot connect, and the pings stop when I unpower the wipy. When I override boot.py and main.py, I can connect to that same IP. My network is completely flat. I'm at x.x.x.110/24, the device is at x.x.x.115/24

              UART baud, for me, is set in boot.py at 115200.

              I can try to rename and execfile() when I get home.

              from machine import RTC
              import utime
              import pycom
              from machine import Pin
              
              
              def isDST(day, month, dow):
                  """
                  DST Checker.
                  
                  This checks if the current day is DST
                  """
                  # dow in this implementation is mon-sun, not sun-sat
                  if dow == 6:
                      dow = 0
                  else:
                      dow = dow + 1
                  # January, february, and december are out.
                  previousSunday = day - dow
                  if (month < 3 or month > 11):
                      return False
                  # April to October are in
                  elif (month > 3 and month < 11):
                          return True
                  # In march, we are DST if our previous sunday was on or after the 8th.
                  elif (month == 3):
                      return previousSunday >= 8
                  # In november we must be before the first sunday to be dst.
                  # That means the previous sunday must be before the 1st.
                  else:
                      return previousSunday <= 0
              
              def currentTime():
                  # return a dict with all of the day selections?
              
                  global cycleday
                  curtime = utime.gmtime(utime.time())
                  now = {"year":curtime[0], "month":curtime[1], "day":curtime[2], "hour":curtime[3],
                  "minute":curtime[4], "second":curtime[5], "dow":curtime[6], "doy":curtime[7]}
                  return now
              
              
              def setTimeZone():
                  """
                  Time Zone Setter.
                  
                  This function sets the current time zone depending on the day and
                  whether or not it's DST
                  """
                  now = currentTime()
                  if isDST(now["day"], now["month"], now["dow"]):
                      utime.timezone(dst)
                  else:
                      utime.timezone(est)
              
              
              def isNewDay():
                  global cycleday, taken, logged
                  now = currentTime()
                  if (int(now["day"]) > int(cycleday)) or (cycleday == 100):
                      cycleday = int(now["day"])
                      logged = False
                      taken = False
                      pycom.rgbled(0xFF0000)
              
              
              def logButton():
                  global logged
                  pycom.rgbled(0x001100)
                  logged = True
                  # do something to log in Google drive or somewhere
              
              
              def pin_handler(arg):
                  global taken
                  taken = True
              
              
              def mainloop():
                  """
                  The main loop of the program.
                  
                  Cycles through updating the LED if meds have been taken, as well as
                  checking to make sure that the day hasn't changed. If the day has changed,
                  then mainloop will change the LED back to red, and start the next day's
                  cycle.
                  """
                  global taken, logged
                  if (taken == True) and (logged == False):
                      logButton()
                  isNewDay()
              
              
              dst = -14400
              est = -18000
              taken = False
              logged = False
              cycleday = 100
              p_in = Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP)
              p_in.callback(Pin.IRQ_FALLING, pin_handler, arg=None)
              pycom.heartbeat(False)
              pycom.rgbled(0x000011)
              rtc = RTC()
              server = "pool.ntp.org"
              rtc.ntp_sync(server)
              setTimeZone()
              isNewDay()
              
              while True:
                  mainloop()
              
              D 1 Reply Last reply Reply Quote 0
              • C Offline
                ccarducci @DenDeze
                last edited by

                @dendeze
                Yes, sorry, the format of this forum is weirding me out. The way it was displayed it looked like I was responding to myself, not you, so I tried to delete and re-respond. I've re-posted now, not that I think it looks any better. also I can't post more than every 10 minutes because I'm a new user, which is really irritating when you're trying to actively reply in a thread. I also changed the formatting of my post to be three backticks instead of a four-space indent on each line, not that it makes much of a difference after it's already posted...

                1 Reply Last reply Reply Quote 1
                • D Offline
                  DenDeze @ccarducci
                  last edited by

                  @ccarducci looks like legit code. How is the renaming working out?

                  C 1 Reply Last reply Reply Quote 0
                  • C Offline
                    ccarducci @DenDeze
                    last edited by

                    @dendeze

                    It was interesting. At this point I'm assuming the issues are actually with the Pymakr plugin for Atom, and not the board itself. When I came back home I plugged the board back in and tried to reconnect. As I was renaming the file and getting ready to try to override main.py and re-upload my newly named file, I decided to try once more to kill off main.py from a connection. Despite the fact that the REPL prompt in atom/pymakr never showed that I actually connected, I think it was. At first ctrl+C wasn't working at all, but in my frustration I decided to just keep hitting it for a while, and after a few repeated keystrokes the board finally terminated main.py. Once I got that done, I was continuously able to replicate just by being patient and by repeatedly hitting ctrl+c after hitting the "Connect" button until it decided to take the keypress.

                    After that I had to make a few tweaks to code where I was doing stupid things, and now it's all running smoothly. I'm going to stick mostly to putty/filezilla until the plugin feels a bit more 'baked' than it is.

                    J D 2 Replies Last reply Reply Quote 0
                    • J Offline
                      jcaron @ccarducci
                      last edited by

                      @ccarducci there are currently a few calls that are actually not interrupted by Ctrl-C, so you have to wait until that call has ended for it to take effect.

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        DenDeze @ccarducci
                        last edited by

                        @ccarducci you could enable a for loop running every second, this way you can interrupt your program every second.

                        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