how to see module contents?

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
KJM
Posts: 158
Joined: Sun Nov 18, 2018 10:53 pm
Location: Sydney AU

how to see module contents?

Post by KJM » Mon Apr 18, 2022 1:23 am

upythons builtin onewire module is throwing an error

Code: Select all

File "ds18x20.py", line 20, in convert_temp
TypeError: function takes 1 positional arguments but 2 were given
This module is either frozen or baked-in not in lib

Code: Select all

>>> os.listdir('lib')
['urequests.py']
I'd like to have a peek at ds18x20.py to try to figure out the problem but I can't work out how to do it in the repl? Can't seem to get past

Code: Select all

>>> dir(onewire)
['__class__', '__name__', '__file__', 'machine', 'time', 'OneWire', 'DS18X20']
>>> inspect.getsource(onewire)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'inspect' isn't defined
Thoughts on how to see what's in ds18x20.py anybody?

sweetcandysp
Posts: 1
Joined: Mon Apr 18, 2022 2:32 am

Re: how to see module contents?

Post by sweetcandysp » Mon Apr 18, 2022 2:35 am

Do you see them in a scan? I would have thought you would (as adv_type = 3). (If you see them in bluetoothctl then you should see them from MicroPython).
slope 2

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: how to see module contents?

Post by Roberthh » Mon Apr 18, 2022 5:48 am

No need to guess, since the source code is available: https://github.com/micropython/micropyt ... ds18x20.py

KJM
Posts: 158
Joined: Sun Nov 18, 2018 10:53 pm
Location: Sydney AU

Re: how to see module contents?

Post by KJM » Mon Apr 18, 2022 12:18 pm

Turns out Robert that old 2016 module ['__class__', '__name__', '__file__', 'machine', 'time', 'OneWire', 'DS18X20'] was in the ESP32 flash & was taking import precedence over the baked-in ['__class__', '__name__', '__file__', '_ow', 'OneWireError', 'OneWire'] version of onewire. Once I deleted it my temperature calling routine worked.

Interestingly (to me anyway) if the old 2016 module is in lib it doesn't take import precedence over the baked-in version.

So there is no way to catch a glimpse of baked in module code? Trawling google for examples of how to call something like onewire is tough going when there are multiple versions of onewire floating around, each requiring it's own matching calling routine.

Post Reply