Building an IoT device: minizing module import time to conserve battery

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
User avatar
liudr
Posts: 211
Joined: Tue Oct 17, 2017 5:18 am

Re: Building an IoT device: minizing module import time to conserve battery

Post by liudr » Wed Nov 10, 2021 10:21 pm

scruss wrote:
Wed Nov 10, 2021 9:31 pm
One other thing about mpy files: they have to match the version of the MicroPython interpreter you're running.
Thanks. I read that if the 0-5 version values matches then it would be compatible, such as version 5 works for MP version 1.12 and up:

https://docs.micropython.org/en/latest/ ... #mpy-files

The mpy-cross I installed via pip says it's 1.16 but the pypi page says 1.17. So I have been running the bytecodes I compiled from it since, without compiling with native decorators. I just compiled with native decorators on all of my functions in one .py file and it did output a different file than without the decorators. I'll try to run it and make sure it runs before putting more decorators in other .py files and try.

I wonder if these native decorators affect the .py files when running on PC python or should I have an if-statement on the decorator.

User avatar
liudr
Posts: 211
Joined: Tue Oct 17, 2017 5:18 am

Re: Building an IoT device: minizing module import time to conserve battery

Post by liudr » Thu Nov 11, 2021 5:10 am

It seems that the decorator triggers errors when I try to run my code on PC python. I wonder if something can be done to say nullify them when I'm running my scripts on PC, which otherwise run perfectly.

User avatar
Minyiky
Posts: 32
Joined: Sat Oct 24, 2020 5:53 pm

Re: Building an IoT device: minizing module import time to conserve battery

Post by Minyiky » Thu Nov 11, 2021 8:33 am

Are you running on the linux port?

A while ago I ran some quick tests using the @micropython.native emmitter on the linux port. I didn't get any errors but I did get some very wierd results so something wasnt correct somewhere.

User avatar
liudr
Posts: 211
Joined: Tue Oct 17, 2017 5:18 am

Re: Building an IoT device: minizing module import time to conserve battery

Post by liudr » Thu Nov 11, 2021 1:33 pm

I'm running on ESP 32 and regular PC Python. My hardware has two variants, USB interface for PC, another using ESP 32. I import platform specific things with if platform=='esp32'

User avatar
Minyiky
Posts: 32
Joined: Sat Oct 24, 2020 5:53 pm

Re: Building an IoT device: minizing module import time to conserve battery

Post by Minyiky » Thu Nov 11, 2021 3:44 pm

I you are running standard python on your pc then the emmitters will through errors as they are specifically for micropython. If you run the unix or windows port of micropython you should be able to both complile and run the code correctly, although I cant comment of the relevancy of speed differences to use on an esp32

spiceagent11
Posts: 2
Joined: Tue May 18, 2021 4:34 pm

Re: Building an IoT device: minizing module import time to conserve battery

Post by spiceagent11 » Fri Nov 12, 2021 12:02 am

Build your config file in json format. You can read/convert to a dictionary, update it with standard python coding, save it as json.

Post Reply