Espnow on esp8266 micropython OSError: -3 - esp8266

I was recantly experimenting with espnow in micropython. Sudenly I rann Into A Problem wenn trying to run this code:
import network, espnow, time
wlan_sta = network.WLAN(network.STA_IF)
wlan_sta.active(True)
e = espnow.ESPNow()
e.active(True)
peer = b'\xff\xff\xff\xff\xff\xff' # MAC
e.add_peer(peer)
while True:
e.send(peer, "ESP")
time.sleep(1.1) # Sekunden
i get the Error OSError: -3
The Code worked on my Esp32 but not on the 8266 no clue why.
I tried reflashing my esp but that did not help either.

According to the documentation you need to call wla_sta.disconnect() after setting wlan_sta.active(True). This is the example from the docs:
import network
import espnow
# A WLAN interface must be active to send()/recv()
sta = network.WLAN(network.STA_IF) # Or network.AP_IF
sta.active(True)
sta.disconnect() # For ESP8266
e = espnow.ESPNow()
e.active(True)
peer = b'\xbb\xbb\xbb\xbb\xbb\xbb' # MAC address of peer's wifi interface
e.add_peer(peer)
e.send("Starting...") # Send to all peers
for i in range(100):
e.send(peer, str(i)*20, True)
e.send(peer, b'end') # The example in the docs is missing the `peer` argument.
If I run that example as written (well, correcting the second call to e.send as shown in the above code) and the corresponding receiver code, it all works just fine on a pair of esp8266's running v1.19.1-espnow-6-g44f65965b.
Update I think your problem is that the esp8266 may not support the broadcast address. While the documentation suggests that the esp8266 should be able to send to the broadcast address:
All active ESP-Now clients will receive messages sent to their MAC address
and all devices (except ESP8266 devices) will also receive messages sent to
the broadcast MAC address (b'\xff\xff\xff\xff\xff\xff') or any multicast MAC
address.
All ESP-Now devices (including ESP8266 devices) can also send messages to the
broadcast MAC address or any multicast MAC address.
It appears that this isn't the case. I'm able to use the example code from the docs when operating in unicast mode, but attempting to call e.add_peer with the broadcast address results in the same error you've reported.
I've opened issue #11 with this problem.

In Conclusion you can say that It IS posibille to use ESPnow on the esp 8266 in SingelCasting Mode but not in MultiCasting

Related

How to determine if ESP32 MicroPython wifi access point is ready to show IP address?

I have an ESP32 microcontroller with MicroPython 1.19.1 that I'm setting up as a wifi access point. But, when I attempt to print the IP address with print(f'{wlan.ifconfig()}') it gets stuck in a reboot loop.
Here's the code in my boot.py:
from network import WLAN, AP_IF
from config import AP_NAME, AP_PASS
print('Starting in wifi access point mode...')
wlan = WLAN(AP_IF)
wlan.config(authmode=3, essid=AP_NAME, password=AP_PASS)
wlan.active(True)
while (wlan.active() == False):
print('.')
print(f'SSID: {AP_NAME}')
print(f'Password: {AP_PASS}')
print(f'{wlan.ifconfig()}')
Commenting out the print(f'{wlan.ifconfig()}') fixes the reboot loop, as does inserting a delay just before the statement.
This leads me to believe the access point is not fully ready by the time I'm calling ifconfig(). But, I'm working under the assumption the while (wlan.active() == False) is supposed to take care of that. Though in the serial output, there's not a single dot printed to indicate it looped even once.
Serial output looks like this (after inserting a delay to mitigate the reboot loop):
Starting in wifi access point mode...
SSID: Lab
Password: ********
('192.168.4.1', '255.255.255.0', '192.168.4.1', '0.0.0.0')
If the while loop were actually waiting for the access point to come up, I would expect a few lines with dots between the 'Starting' message and the printing of SSID. So I'm thinking wlan.active() is just telling me what I set in the line above: wlan.active(True) and is not a true reflection of the access point's readiness.
I tried help(wlan) to see what methods might be available to determine the state of the access point. Some of the more promising ones and their results are shown below.
>>> wlan.active()
True
>>> wlan.isconnected()
False
>>> wlan.status()
>>>
I'm not surprised by isconnected() returning false since it's probably just for wifi station mode. I had high hopes for status(), but it only returns None
Every tutorial I've found so far uses the while loop to check active(), but obviously that's not working. Sticking a random delay in seems like a bad solution.
Is there a reliable way to ensure the access point is fully ready before asking for its IP address?

ESP32 with Micropython resets when try to connect to Wifi

Sorry about my english. I try to connect my ESP32 to wifi and it's resets. I post text in the Micropython interpreter of ESP32 (only erase ">>>"promt from every line) :
MicroPython v1.19.1 on 2022-06-18; ESP32 module with ESP32
Type "help()" for more information.
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
True
wlan.connect('Dpto', '03755422170')
ets Jun 8 2016 00:22:57
rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
etc...
It's happends with an older firmware too.
In google there are a lots topics about it, but I don't find any usefull.
I try to find why the Timer Group 1 of the Whach Dog Timer send Resets, but donĀ“t find answers.
I erase the Firmware and write again, but the error continue.
Thanks in advance..

Sim5360e communication over UART2

I will implement the data exchange between the module and the device Sim5360e through UART2. I write in the Lua, AT commands to send / receive information via the UART2 did not find - so use internal devio function.
sio.send("AT+CSCLK=0\r\n")
readAndPrintAtUnswer()
sio.send("AT+CGFUNC=21,1\r\n")
readAndPrintAtUnswer()
sio.send("AT+IPR2=9600\r\n")
readAndPrintAtUnswer()
local msg,count=getHex(str)
local unswer
devio.open(3)
devio.write(3,msg,count)
unswer=devio.read(3,4000)
print(unswer)
devio.close(3)
When connected to a terminal on the PC - see the correct incoming message, the module enters the mode of reading, I send data through the terminal, but after a timeout (4000 ms) unswer = nil. Data from the terminal out exactly correct - checked by another device.
Can you please tell, how do I get an answer to my message?

path of packets through network stack

I'm trying to study and understand operations of the Linux tcp/ip stack, specifically how 'ping' sends packets down and receives them.
Ping creates raw socket in AF_INET family, therefore I placed printk in inet_sendmsg() at net/ipv4/af_inet.c to print out the socket protocol name (RAW, UDP etc.) and the address of protocol specific sendmsg function which correctly appears to be raw_sendmsg() from net/ipv4/raw.c
Now, I'm sending a single packet and observe that I'm getting printk form inet_sendmsg() twice.This puzzles me -- is it normal (has something to do with interrupts etc. ?) or there's something broken in the kernel?
Platform - ARM5te, kernel 2.6.31.8
Looking forward to hearing from you !
Mark

UDPClient not receiving packets on HTC G2

I'm attempting to receive a UDP Broadcast under Mono for Android and I am seeing no data coming in. This is somewhat perplexing because it works fine on the Galaxy Tab 7 and Galaxy Tab 10 (Android v 3.2) I have, but fails on an HTC G2 (Android v2.3.4).
The code is straightforward:
public void BeginDiscover()
{
var packet = new DiscoverPacket();
lock (m_syncRoot)
{
var localEndpoint = new IPEndPoint(m_local, 0);
using (var udp = new UdpClient(localEndpoint))
{
var remoteEndpoint = new IPEndPoint(IPAddress.Broadcast, DiscoverPort);
udp.Send(packet.Data, packet.Data.Length, remoteEndpoint);
Thread.Sleep(100);
}
}
}
I have verified that the manifest includes this line:
<uses-permission android:name="android.permission.INTERNET" />
Though this is happening in Debug, so that should be implicitly set anyway.
Other very strange observations:
Again, this is working just fine on another type of device
The handler listening for UDP broadcasts (which list listening for the response) does see this outbound packet. The code for this listener is also straightforward:
[listener code]
private void Start()
{
m_discoverListener = new UdpClient(DiscoverPort);
m_discoverListener.BeginReceive(DiscoverCallback, m_discoverListener);
}
private void DiscoverCallback(IAsyncResult result)
{
try
{
var ep = new IPEndPoint(IPAddress.Any, DiscoverPort);
var data = m_discoverListener.EndReceive(result, ref ep);
// filter out what we send
var add = AddressWithoutPort(ep.Address);
if (add == m_local.ToString()) return;
// parse discover response
// [clipped for clarity]
}
finally
{
m_discoverListener.BeginReceive(DiscoverCallback, m_discoverListener);
}
}
Wireshark running on a separate PC on the same network does see the discover request packet (from above)
The "discovered" device is also seeing it, because Wireshark is also seeing the reply
The Android device UDP listener is not receiving the response packet
The only major differences between devices that I can think of (other than different OEMs implementing the platform) is that the G2 has a cellular radio built in and the Galaxy Tab does not. In my specific test case, I have no SIM card in the phone, though, so no cellular connection is being made. Note that the code above is explicitly using the local endpoint that is on the WiFi network.
Is there a known issue with UDP on the G2 specifically or generally on older implementations of the Android platform?
It took a bit of work as the UDP response in question is coming from a microcontroller on the device and I wanted to make absolutely certain that it wasn't an issue on the micro end (though I suspected it wasn't). I created a PC-based simulator for the microcontroller device that handles my Android UDP request and that sends back the exact same UDP response that the microcontroller does, then verified all of the traffic looks fine with Wireshark.
The net result is that I see he exact same behavior with the simulator. The Galaxy Tab 7 and 10 devices receive the UDP response no problem. The HTC G2 never does. This leads me to conclude that one of the following is true:
a) The HTC G2 specifically has an implementation bug preventing it from receiving (or at least passing along) UDP broadcasts on the network
or
b) The older Android build has his bug.
Until I find different hardware with the same Android version as the G2 (v2.3) I can't tell which is the case. In either event, it's a bug that makes this (and potentially other) hardware unusable for my specific solution.
I have a couple of applications on the market based on UDP communication.
I have problems with HTC phones not receiving the UDP broadcast packets sent from another device... if sent from the same device, the packets arrive.
so, I think the problem is in HTC, and I found a possible solutions online (even though I have not tried it):
http://www.flattermann.net/2010/09/fix-udp-broadcasts-on-htc-phones-running-stock-firmware/

Resources