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



  • 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.



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



  • @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.



  • @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.



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



  • @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...



  • @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()
    


  • You just posted your code and removed it...



  • This post is deleted!


  • 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')



Pycom on Twitter