Newbie question on altering code downloaded with upip

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
stagbeetle
Posts: 1
Joined: Wed Jan 08, 2020 10:34 pm

Newbie question on altering code downloaded with upip

Post by stagbeetle » Wed Jan 08, 2020 10:58 pm

Hi,

I am not sure how to accurately phrase this question, and it may be really obvious, so I'll just so what is confusing me and hope someone can point it out...

On an esp8266 I've downloaded umqtt simple and robust using upip. They both work fine. However I wanted to add some 'print' statements into 'robust.py' but I can't... after a few days of trying everything I've started from scratch to show what I mean:

This is a function in the /lib/umqtt/robust.py:

Code: Select all

    def delay(self, i):
        utime.sleep(self.DELAY)
I added a print line:

Code: Select all

    def delay(self, i):
        print("delaying...")
        utime.sleep(self.DELAY)      
        

When I call it on repl the 'delaying...' is never printed:

Code: Select all

MicroPython v1.12 on 2019-12-20; ESP module with ESP8266
Type "help()" for more information.
>>>
>>> from umqtt.robust import MQTTClient
>>> x=MQTTClient('1','2')
>>> x.delay(1)
>>>
Thinking the print is redirected somewhere else I've tried too many ways of trying to understand this simple problem, but I can't make any sense of it.

The following is another change I made which I guess is related but I can't figure out:

If I copy the delay function and create a duplicate called 'delaytest':

Code: Select all

    def delay(self, i):                                                                                                                                                         
        print("delaying...")
        utime.sleep(self.DELAY)
        
    def delaytest(self, i):
        print("delaying...")                                                                                                                                                    
        utime.sleep(self.DELAY) 
And then list the functions, it doesn't appear...

Code: Select all

>>> from umqtt.robust import MQTTClient
>>> dir(MQTTClient)
['__class__', '__init__', '__module__', '__name__', '__qualname__', '__bases__', 'connect', 'disconnect', 'log', 'DEBUG', 'delay', '_send_str', '_recv_len', 'set_callback', 'set_last_will', 'ping', 'publish', 'subscribe', 'wait_msg', 'check_msg', 'DELAY', 'reconnect']
Where can I look to understand what is going on?

Thanks

User avatar
pythoncoder
Posts: 3867
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Newbie question on altering code downloaded with upip

Post by pythoncoder » Thu Jan 09, 2020 6:19 pm

If you're using a release build, the reason is that these modules are frozen as part of the build. By default MicroPython finds frozen versions before versions on the filesystem, so your changes are ignored. To temporarily change the search order, issue:

Code: Select all

import sys
sys.path.append(sys.path.pop(0))
Peter Hinch

Post Reply