Page 6 of 37
Re: ESP-Now support for ESP32 (and ESP8266)
Posted: Fri Jan 08, 2021 6:56 pm
by davef
Following on from your example if I then try to bring up the network interface:
Code: Select all
>>> sta_if = network.WLAN(network.STA_IF)
>>> sta_if.active(True)
True
>>> sta_if.ifconfig(('192.168.10.99', '255.255.255.0', '192.168.10.1', '8.8.8.8'))
>>> sta_if.isconnected()
False
>>>
I will now check the official image.
Re: ESP-Now support for ESP32 (and ESP8266)
Posted: Fri Jan 08, 2021 8:16 pm
by Roberthh
I do not see a call to sta_if.connect(). Without that, the module will not connect,
Re: ESP-Now support for ESP32 (and ESP8266)
Posted: Fri Jan 08, 2021 8:29 pm
by davef
Ah, let me focus a bit harder!
Sorry, my previous post was incorrect ... it did not reflect that I was actually doing a re-connect in the code I was testing. I have gone through the process as Peter suggested, line by line, and the re-connection works.
Also, my program now works at home-base, maybe because it is a different wireless router. I will re-check at the remote location.
Thank you for the support guys.
Dave
Re: ESP-Now support for ESP32 (and ESP8266)
Posted: Sat Jan 16, 2021 7:28 pm
by davef
As I get the odd init() and add_peer() errors I thought I would
put in some error-trapping, but it looks like the error test is not
even being run.
For example:
Code: Select all
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "local.py", line 21, in <module>
AttributeError: 'function' object has no attribute 'init'
Code: Select all
retval = e.init() # line 21
if (retval != None):
print('init() did NOT work')
machine.reset()
Any suggestions?
Re: ESP-Now support for ESP32 (and ESP8266)
Posted: Tue Jan 19, 2021 10:31 pm
by glenn20
It appears that 'e' is not an ESPNow object. The error message suggests it is a function object. This suggests there may be a bug in how you initialise 'e'.
Try just print(e) as a diagnostic.
For example, this would happen if you do:
instead of
(Just returned from 10 days out of phone range - at the beach
.
Re: ESP-Now support for ESP32 (and ESP8266)
Posted: Tue Jan 19, 2021 11:10 pm
by davef
Always:
I will try the print(e) statement and see if I can get it to fail. I always focussed on the line that the error occurred, looks like I need to step-backward to get a clearer picture.
Hope the shock of going back to work or whatever is not too big
Thanks.
Re: ESP-Now support for ESP32 (and ESP8266)
Posted: Tue Jan 19, 2021 11:39 pm
by davef
So, did a print(e) , after:
and when it failed I saw:
Code: Select all
>>> import local
b'$\n\xc4Yd\x88'
2021-1-
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "local.py", line 19, in <module>
AttributeError: 'str' object has no attribute 'init'
Looks like it is returning the date ??
Re: ESP-Now support for ESP32 (and ESP8266)
Posted: Mon Jan 25, 2021 1:25 am
by glenn20
davef wrote: ↑Tue Jan 19, 2021 11:39 pm
So, did a print(e) , after:
and when it failed I saw:
Code: Select all
>>> import local
b'$\n\xc4Yd\x88'
2021-1-
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "local.py", line 19, in <module>
AttributeError: 'str' object has no attribute 'init'
Looks like it is returning the date ??
Without seeing your code, it is difficult to help. For me:
Code: Select all
from esp import espnow
e = espnow.ESPNow()
print(e)
prints (on the ESP32):
and (on the esp8266):
The point is that 'e' is an ESPNow object which has 'init' as a bound method. It appears that in your case 'e' does not reference an ESPNow object.
Re: ESP-Now support for ESP32 (and ESP8266)
Posted: Mon Jan 25, 2021 3:14 am
by davef
Thanks.
I get the same when it runs properly.
It is the only place that <e> is used:
Code: Select all
import network
from esp import espnow
import utime
import machine
from machine import Pin
# import ubinascii
pin2 = Pin(2, Pin.OUT) # Discharge pump clamp pin
pin2.off() # enable discharge pump on re-boot
# A WLAN interface must be active to send()/recv()
w0 = network.WLAN(network.STA_IF)
w0.active(True)
#mac = w0.config('mac')
#print(mac)
#mac = ubinascii.hexlify(w0.config('mac'),':').decode()
#print(mac)
e = espnow.ESPNow()
retval = e.init()
if (retval != None):
print('init() did NOT work')
machine.reset()
#peer = b'\x18\xfe4\xde\xea\xf3' # MAC address of ESP-01S local
peer = b'$\n\xc4Yd\x88' # MAC address of ESP32 local
retval= e.add_peer(peer)
if (retval != None):
print('add_peer did NOT work')
machine.reset()
print('waiting for command')
while True:
msg = e.irecv()
utime.sleep(1)
# if (msg != None):
if msg:
command = msg[1].decode('utf-8')
print(command)
if (command == 'pump off'):
print('You have turned the pump off')
pin2.on() # this disables the discharge pump
print('send ACK')
retval = e.send(peer, "pump is now off", True)
if (retval != True):
print('send did NOT work')
machine.reset()
utime.sleep(5)
retval = e.deinit()
if (retval != None):
print('deinit() did NOT work')
machine.reset() # just to be tidy
w0.active(False) # take-down WiFi
machine.reset()
Re: ESP-Now support for ESP32 (and ESP8266)
Posted: Thu Jan 28, 2021 12:52 pm
by glenn20
I have posted new precompiled images for the esp32 and esp8266 at
https://github.com/glenn20/micropython-espnow-images.
Images are available for:
- the latest espnow-g20 branch which has been re-based against the latest micropython master branch, and
- the latest espnow-g20-v113 branch which has been rebased against the v1.13 micropython release.
In principle, the images compiled against v1.13 (with espnow patches) may be more stable overall.
These are provided as a convenience for users until such time as the ESPNow PR is merged into an official micropython release.