-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
W600 and ESP8266 MemoryError #62
Comments
Hello @sabeehalam Could you please to add this code below before you run the import gc
print('run gc.collec now.')
gc.collect()
print('Mem info before load ModBus lib: mem_alloc: {} | mem_free: {}'.format(gc.mem_alloc(), gc.mem_free())) @brainelectronics I did a test with my RTU Slave example (just part of print mem info): print('run gc.collec now.')
gc.collect()
print('Mem info before load ModBus lib: mem_alloc: {} | mem_free: {}'.format(gc.mem_alloc(), gc.mem_free()))
from umodbus import version
print('Running ModBus version: {}'.format(version.__version__))
# import modbus client classes
from umodbus.serial import ModbusRTU
# All RTU example code here
print('Mem info after ModBus lib loaded: mem_alloc: {} | mem_free: {}'.format(gc.mem_alloc(), gc.mem_free()))
print('run gc.collec now.')
gc.collect()
print('Mem info after gc.collect(): mem_alloc: {} | mem_free: {}'.format(gc.mem_alloc(), gc.mem_free()))
while True:
result = client.process() Output: $ mpremote run rtu_client_example_with_callback.py
Clock running at: 240000000
run gc.collec now.
Mem info before load ModBus lib: mem_alloc: 4944 | mem_free: 163760
Running ModBus version: 2.3.1-rc26.dev53
Mem info after ModBus lib loaded: mem_alloc: 113904 | mem_free: 54800
run gc.collec now.
Mem info after gc.collect(): mem_alloc: 36640 | mem_free: 132064 Some points:
Thank you in advance! |
I think it definitely would result in a slight memory increase since the TCP and RTU classes are separated, so importing one should not also load the other. They use common parts so the increase should be very little, but it will most likely increase nonetheless.
Since the uasyncio version extends the synchronous versions of the library to avoid code duplication, the additional raw code itself should be very minimal. I don't know how much memory the entire thing consumes when running, though, since I don't have a board to test on myself. In the Ubuntu version it results in an increase from the base |
@GimmickNG Thanks for reply. I have board with |
@beyonlo Here is the output you asked for |
@sabeehalam The problem is that ModBus lib are allocating more memory than your microcontroller has free memory. Please, try do call the import gc
gc.threshold(4000) That will trigger the |
You could also try recompiling along with package freezing to reduce the memory footprint of the library - see this link |
relates to brainelectronics/micropython-nextion#18 @sabeehalam I've ordered the boards you have to be able to test and improve the code. I also plan a always on hardware test framework to verify all changes on PRs so everybody can test and verify their changes like the async implementation #56 by @GimmickNG |
Can you provide the mpy file for the esp8266? |
@brainelectronics add instructions for using mpy-cross to README to resolve this issue. |
Description
So I am using Thonny and installed this library and ran the slave code with Wemos d1 mini esp8266, Wemos W600-pico and the Raspberry Pi PICO. The code ran fine with the Raspberry Pi Pico. However, both the Wemos W600-PICO and ESP8266 ran into trouble with memory allocation.
Reproduction steps
1.Install the umodbus library on Micropython via the manage packages in Thonny
2. Copy/ paste the RTU slave code in it.
3.Run the code
...
MicroPython version
v1.19.1-870-gb9300ac5b-dirty
MicroPython board
other
Relevant log output
User code
No response
Additional informations
No response
The text was updated successfully, but these errors were encountered: