ESP-Now support for ESP32 (and ESP8266)
Re: ESP-Now support for ESP32 (and ESP8266)
Hi,
I have 2 ESP8266 communicate with ESP-NOW. I need to generate a random number on one side and send it to the other ESP.
When I write:
import random
nb=random.randint(0.9)
I have the error message: AttributeError: 'module' object has no attribute 'randint'
Where is my mistake?
Thanks.
I have 2 ESP8266 communicate with ESP-NOW. I need to generate a random number on one side and send it to the other ESP.
When I write:
import random
nb=random.randint(0.9)
I have the error message: AttributeError: 'module' object has no attribute 'randint'
Where is my mistake?
Thanks.
Re: ESP-Now support for ESP32 (and ESP8266)
I tested :
import urandom
nb=urandom.randint(0,9)
And I have the same error message
import urandom
nb=urandom.randint(0,9)
And I have the same error message
Re: ESP-Now support for ESP32 (and ESP8266)
uos.randint() is not supported. You can use uos.urandom(n), which return n random bytes. Or you use the module urandom with urandom.getrandbits(n), n <= 32m, which returns a random number of n bits size. urandom.getrandbots() returns a pseudo random number, whereas uos.urandom() returns a true random number.
You can use both methods to create a randint() function, if needed.
You can use both methods to create a randint() function, if needed.
Re: ESP-Now support for ESP32 (and ESP8266)
Thanks for your help
Re: ESP-Now support for ESP32 (and ESP8266)
An update on the status of the ESPNow module:
I haven't released any new espnow images for the 1.19 micropython release as I have been focussed on implementing requested changes to the module API before merging into micropython master branch. You can see the requested list of changes and my responses and progress at: https://github.com/micropython/micropyt ... 1128522735.
I wanted to provide a heads-up to users of the current espnow module that these API changes are in the pipeline. I plan to provide some backward compatibility support in a new espnowio module (will possibly be renamed) that I hope will be accepted into the micropython main branch. If it is not accepted I will distribute it separately on github. You can see the espnowio.py module at: espnowio.py
You can see the documentation for the new API at readthedocs
Usage would be:
If you have any questions, comments or criticisms (constructive - I hope ) feel free to respond here.
PS. I plan to provide updated images soon based on the previous API (I don't want to release mages based on the new API which is still in flux - additional changes may be requested prior to merging).
PPS. Oh - and I thought I would mention that it has been challenging to implement a clean API which maximises compatibility between the ESP32 and ESP8266 interfaces while meeting the very tight code size restrictions of the ESP8266.
I haven't released any new espnow images for the 1.19 micropython release as I have been focussed on implementing requested changes to the module API before merging into micropython master branch. You can see the requested list of changes and my responses and progress at: https://github.com/micropython/micropyt ... 1128522735.
I wanted to provide a heads-up to users of the current espnow module that these API changes are in the pipeline. I plan to provide some backward compatibility support in a new espnowio module (will possibly be renamed) that I hope will be accepted into the micropython main branch. If it is not accepted I will distribute it separately on github. You can see the espnowio.py module at: espnowio.py
You can see the documentation for the new API at readthedocs
Usage would be:
Code: Select all
# from esp import espnow
import espnowio as espnow
e = espnow.ESPNow()
...
PS. I plan to provide updated images soon based on the previous API (I don't want to release mages based on the new API which is still in flux - additional changes may be requested prior to merging).
PPS. Oh - and I thought I would mention that it has been challenging to implement a clean API which maximises compatibility between the ESP32 and ESP8266 interfaces while meeting the very tight code size restrictions of the ESP8266.
Re: ESP-Now support for ESP32 (and ESP8266)
Thanks much for your work!
Looking forward for the module to be accepted into the main branch - would be a great step forward, and expected one, for esp-now on micropython community
I compiled your latest 1.18 branch for generic ESP32 and included some of my scripts to be frozen.
For some reason I cannot connect to repl ... I must have done something wrong
Tried also without any of my scripts, same issue
I am compiling using the standard instructions, nothing special
Any suggestions?
Looking forward for the module to be accepted into the main branch - would be a great step forward, and expected one, for esp-now on micropython community
I compiled your latest 1.18 branch for generic ESP32 and included some of my scripts to be frozen.
For some reason I cannot connect to repl ... I must have done something wrong
Tried also without any of my scripts, same issue
I am compiling using the standard instructions, nothing special
Any suggestions?
Re: ESP-Now support for ESP32 (and ESP8266)
One more thing, switching to your yesterday's branch, 1.19.1 I see I can connect to repl however, the prompt say "MicroPython v1.13-1968-g537248958 on 2022-07-07".
Why 1.13? What am I doing wrong?
Why 1.13? What am I doing wrong?
Re: ESP-Now support for ESP32 (and ESP8266)
New espnow-enabed micropython images for release v1.19.1:
Slight change of plan from my intentions stated above. These new images are based on the latest version of my espnow-g20 branch. In the end, the impact on the user API is not so great. As I flagged, the C module code-base has been simplified and streamlined and this is now wrapped in a python module on the esp32 and esp8266 devices. This also makes it easier to support more compatibility between the esp32 and esp8266 devices.
The top-level espnow module is now imported with:
instead of:
Usage would be:
I have tested images on esp32: GENERIC, GENERIC_S2, UM_FEATHERS2, UM_FEATHERS3, UM_TINYS2 and esp8266: GENERIC, GENERIC_1M. Other images are untested as I don't have compatible devices.
I have uploaded new espnow-enabled micropython images to: https://github.com/glenn20/micropython-espnow-images.
Slight change of plan from my intentions stated above. These new images are based on the latest version of my espnow-g20 branch. In the end, the impact on the user API is not so great. As I flagged, the C module code-base has been simplified and streamlined and this is now wrapped in a python module on the esp32 and esp8266 devices. This also makes it easier to support more compatibility between the esp32 and esp8266 devices.
The top-level espnow module is now imported with:
Code: Select all
import espnow
Code: Select all
# from esp import espnow
Code: Select all
# from esp import espnow
import espnow
e = espnow.ESPNow()
...
Re: ESP-Now support for ESP32 (and ESP8266)
I have encountered similar issues in the past myself. Sometimes it is due to a bug I have introduced or some incompatibility with the IDF version I am using (most common).mekanixms wrote: ↑Thu Jul 07, 2022 7:29 amI compiled your latest 1.18 branch for generic ESP32 and included some of my scripts to be frozen.
For some reason I cannot connect to repl ... I must have done something wrong
Tried also without any of my scripts, same issue
I am compiling using the standard instructions, nothing special
Any suggestions?
A good starting point is to compile a vanilla micropython image without the espnow patches applied and check success with that. Also, check the version of the IDF you are using. It is notable that the micropython CI scripts always use v4.0.2 for ESP32 flavours (and v4.4 for s2/s3/2/c3 variants). See the ci_esp32_*() functions in tools/ci.sh for a reproducible procedure to setup a build environment. (However, I *believe* the released versions use IDF v4.2, instead of v4.0.2).
Good luck...
Re: ESP-Now support for ESP32 (and ESP8266)
That is odd. The image should be tagged with the output of the "git describe" command. You could try running that command in your clone of the espnow-g20-v1.19.1 branch. It should identify the HEAD with respect to the most recent git tag.
Also, try:
Code: Select all
import sys; sys.version
Also - check you have flashed the correct image into the device and you are talking to the right device (rookie mistakes - but I've made them before .
BTW. I have released compiled images based on v1.19.1. You could try them as well.