espressif / ESP8266_NONOS_SDK

ESP8266 nonOS SDK
Other
918 stars 533 forks source link

[TW#25858] esp-now support broadcast? #8

Open limin-liu opened 7 years ago

limin-liu commented 7 years ago

In your decribetion of code : WIFI

  1. Allow sending a broadcast ESP-NOW packet, but make sure that the packet is unencrypted;

But in your reference V2.1.0 : 3.8 part for ESPNOW still "ESP-NOW do not support broadcast and multicast.“

So ESPNOW actually support broadcast or not?

FayeY commented 7 years ago

Hi, ESP-NOW does support broadcast in ESP8266 non OS SDK V2.1, we will revise the documentation. Thanks for reporting!

limin-liu commented 7 years ago

in the description for this repository's new update code . link here --->https://github.com/espressif/ESP8266_NONOS_SDK/commit/90c641efe84066b47c4616ed367697a9f49f3ac5

Version 2.1.0(116b762)

System

  1. Fix and update the license;
  2. Add definitions of ROM functions;
  3. Add efuse mac crc, save efuse mac into the system parameter area of flash, as a backup mac;
  4. Implement uart_div_modify, which can support a 32-bit DivLatchValue in the SDK instead of the ROM one, and also remove uart_div_modify from the ld file;
  5. Reduce iRAM usage by transferring some functions to flash;
    • add weak function void user_spi_flash_dio_to_qio_pre_init(void). If the dio to qio flash mode is not used, users can add an empty user_spi_flash_dio_to_qio_pre_init on the application side to reduce iRAM usage;
  6. Fix WDT in system_restart;
  7. Fix Write & Read issue in SPI overlap mode;
  8. Support 8MB & 16MB spi flash;
  9. Update boot v1.7;
    • Support 8MB & 16MB spi flash;
    • Try boot the first bin for 3 times. If it fails, then boot the backup bin;
  10. Fix http packet error, BBP301;
  11. Support long periods of deep sleep;
  12. Fix NMI handle crash on unaligned memory access, BBP309;

Lwip

  1. Add set and get dns server APIs:
    • espconn_dns_setserver
    • espconn_dns_getserver
  2. Fix 2038 overflow bug in sntp_get_current_timestamp;
  3. Fix MTU negotiate bug;

AT

  1. Add new commands, AT+UART? and AT+UART_DEF?;
  2. Add new command, AT+SYSRAM?;
  3. Add new commands, AT+SYSIO series;
  4. Add new command, AT+CWHOSTNAME;
  5. Add new command, AT+SYSADC?;
  6. Add new commands, AT+CIPSNTPCFG and AT+CIPSNTPTIME;
  7. Add new commands, AT+CIPDNS_CUR and AT+CIPDNS_DEF;
  8. Support a maximum of 8 stations;
  9. Modify keepalive count to 3 times;
  10. Fix scan hidden ssid issue in AT+CWLAP;
  11. Fix the issue of the UART stop bit being 0 when queried for the first time;
  12. Fix MAC addr conflict in AP+STA mode;
  13. Add new commands, AT+RFAUTOTRACE;

WiFi

  1. Optimize the RF frequency calibration workflow, having the frequency trace disabled by default;
    • users can call system_phy_freq_trace_enable in user_rf_pre_init to enable it;
  2. Update libphy.a to version 1134_0;
  3. Allow sending a broadcast ESP-NOW packet, but make sure that the packet is unencrypted;
  4. Fix soft queue error;
  5. Fix EVENT_STAMODE_AUTHMODE_CHANGE event mode info;
  6. Fix lmac assert;
  7. Fix bug in sniffer mode;
  8. Fix arp loss continously issue;
  9. Fix bug in WiFi event;
    • auth mode changed event cannot be throw when station is in the process of scanning;
    • error old auth mode and new auth mode;
    • op mode change process cannot be blocked, so add an event to notify the caller that op mode is changed;
  10. Fix the bug in mic failure handler;
  11. Fix the bug which causes failure of connection to an AP with shared WEP;
  12. Fix the bug which causes failure of connection to an AP with hidden ssid;
  13. Fix softAP deauth;
  14. Fix reconnect policy when trying to connect to an AP that does not exist;
  15. Fix scan issue;
  16. Fix extra bytes in UDP broadcast packet, BBP310;
FayeY commented 7 years ago

Hi, thanks for your reporting. The documentation has been updated, see Chapter 3.8 in API Guide. ESP-NOW supports broadcast in V2.1.

franklinvv commented 6 years ago

How can we perform a broadcast with ESP-NOW? Do we transmit to mac address {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}? Because I tried that and it didn't seem to work ...

I would like to use broadcasts to let ESP-NOW devices discover other devices, with which they haven't paired yet. Is that possible?

Could you enlighten me, @FayeY ?

Daniel-dk commented 6 years ago

from the header file it seems we have to set it to "null" "

/**
  * @brief     Send ESPNOW data
  *
  * @attention 1. If peer_addr is not NULL, send data to the peer whose MAC address matches peer_addr
  * @attention 2. If peer_addr is NULL, send data to all of the peers that are added to the peer list
  * @attention 3. The maximum length of data must be less than ESP_NOW_MAX_DATA_LEN
  * @attention 4. The buffer pointed to by data argument does not need to be valid after esp_now_send returns
  *
  * @param     peer_addr  peer MAC address
  * @param     data  data to send
  * @param     len  length of data
  *
  * @return
  *          - ESP_OK : succeed
  *          - ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized
  *          - ESP_ERR_ESPNOW_ARG : invalid argument
  *          - ESP_ERR_ESPNOW_INTERNAL : internal error
  *          - ESP_ERR_ESPNOW_NO_MEM : out of memory
  *          - ESP_ERR_ESPNOW_NOT_FOUND : peer is not found
  *          - ESP_ERR_ESPNOW_IF : current WiFi interface doesn't match that of peer
  */
esp_err_t esp_now_send(const uint8_t *peer_addr, const uint8_t *data, size_t len);

I don't have multiple ESP32's to test with yet, will report once I do, It seems that all peers still need to be in the peer list , but it seems that they will still recieve broadcast messages anyway ( from the API docs )

the MAC header is a little different from that of standard frames. The FromDS and ToDS bits of FrameControl field are both 0. The first address field is set to the destination address. The second address field is set to the source address. The third address field is set to broadcast address(0xff:0xff:0xff:0xff:0xff:0xff).

We also need to add a Peer to the peer list with MAC addr FF:FF:FF:FF:FF:FF

From this example it seems that un-peered devices will still recieve Broadcasts ( as expected )

franklinvv commented 6 years ago

That’s not a real broadcast if you ask me. I haven’t looked at the source code, but I presume that it just loops through the peers one by one, doesn’t it?

It would be cool to allow ESPs to discover each other by broadcasting, and then adding each other as peers.

Op 27 nov. 2017 om 19:34 heeft Daniel notifications@github.com het volgende geschreven:

from the header file it seems we have to set it to "null" "

/**

  • @brief Send ESPNOW data
  • @attention 1. If peer_addr is not NULL, send data to the peer whose MAC address matches peer_addr
  • @attention 2. If peer_addr is NULL, send data to all of the peers that are added to the peer list
  • @attention 3. The maximum length of data must be less than ESP_NOW_MAX_DATA_LEN
  • @attention 4. The buffer pointed to by data argument does not need to be valid after esp_now_send returns
  • @param peer_addr peer MAC address
  • @param data data to send
  • @param len length of data
  • @return
    • ESP_OK : succeed
    • ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized
    • ESP_ERR_ESPNOW_ARG : invalid argument
    • ESP_ERR_ESPNOW_INTERNAL : internal error
    • ESP_ERR_ESPNOW_NO_MEM : out of memory
    • ESP_ERR_ESPNOW_NOT_FOUND : peer is not found
    • ESP_ERR_ESPNOW_IF : current WiFi interface doesn't match that of peer / esp_err_t esp_now_send(const uint8_t peer_addr, const uint8_t *data, size_t len); I don't have multiple ESP32's to test with yet, will report once I do

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

Daniel-dk commented 6 years ago

It seems its a real broadcast .. if you send unencrypted data to peer addr ff:ff:ff:ff:ff:ff then any device on the same channel will receive it You need to add a peer with Addr ff:ff:ff:ff:ff:ff to the peer list otherwise it doesnt send the packet..

Device A :

Sending: 29
Send Status: Success
Last Packet Sent to: ff:ff:ff:ff:ff:ff
Last Packet Send Status: Delivery Success
Device B  : 
Last Packet Recv from: 24:0a:c4:yy:yy:yy
Last Packet Recv Data: 29

test .ino here ( quick modified version of the esp-Now example, flashed to 2 ESP32 dev boards ) Gist link

franklinvv commented 6 years ago

Oh, then I stand corrected!

However, I only have one ESP32 so I can't test it on the ESP32. I have multiple ESP8266s so I will have a try asap. 🙂 Or did you already try it with multiple ESP8266s?

cnlohr commented 6 years ago

This doesn't seem to be working for me. I am able to send things freely when I call

    esp_now_send(da, "ESP8266", 8 ); /*Also tried sending to null */

However, I never seem to be able to receive anything. I've tried adding many different combinations but even this...

    esp_now_register_recv_cb(espnowcb);
    esp_now_register_send_cb(espnowcbtx);
    uint8_t routermac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff,}; //Src Address of my router.
    printf( "PEERINFO: %d\n", esp_now_add_peer(routermac, ESP_NOW_ROLE_COMBO, 0, 0, 0) );
    esp_now_set_self_role(ESP_NOW_ROLE_COMBO);

Nothing gets received.

I am able to look at Wireshark and see appropriate messages going back and forth.

One note: Your protocol described here: http://esp-idf.readthedocs.io/en/latest/api-reference/wifi/esp_now.html is incomplete. There are 4 undocumented bytes between the vendor-specific action frame and vendor-specific action content. I still do not understand what they do.

Crazor commented 6 years ago

I encountered the same issue as @cnlohr where I can successfully send to FF:FF:FF:FF:FF:FF, but those broadcast packets are never received. @Daniel-dk said it is needed to add the broadcast address as a peer, however that fails with a return code of -3 (I haven't found any explanation of this function's return codes). I'm on SDK 2.2.1 (via the Arduino core 2.4.1)

cnlohr commented 6 years ago

@FayeY Can we please re-open this issue as it is definitely present in the current nonos sdk. I am stuck back at 1.5.2 for projects where this is needed.

littleyoda commented 6 years ago

I have the same Problem with esp8266. I can send boardcasts, but no esp8266 receive them.

cnlohr commented 6 years ago

Indeed. the issue is still very much open and very much a problem with the official NONOS sdk. I am not sure why espressif is leaving this issue closed.

Crypter commented 5 years ago

I can confirm this problem too. Devs, do we have anyone working on this?

Thanks

cnlohr commented 5 years ago

I'm not really sure how to get their attention...

Crypter commented 5 years ago

@cnlohr, as far as I'm concerned they might as well have abandoned esp8266 and are working on esp32. Most of them are dedicated to direct customers of espressif (for example alibaba), with features going into the SDK only if they need them for the customers.

If only everything could be open source... 🙄

FayeY commented 5 years ago

@Junhao-Espressif, PTAL

cnlohr commented 5 years ago

@FayeY I am glad that Espressif is pursuing this again. It is much more powerful than any framework could be. By having true broadcast access, it opens a lot of doors that are unworkable with different options.

cnlohr commented 5 years ago

@FayeY I am coming up on a commercial project that will be using 2,500 units and I really could use this feature. I don't want to stick the customer with the old firmware version.

nemonote01 commented 5 years ago

Hi @limin-liu @franklinvv @Daniel-dk @cnlohr

Please try using the following two files. After testing, we will update them on GitHub.

lib_support_broadcast.tar.gz

SDK ver: 3.0.0(e27cf60) compiled @ Sep  5 2018 15:35:05
phy ver: 1136_0, pp ver: 10.2

SDK version:3.0.0(e27cf60)
mode : sta(5c:cf:7f:14:c7:8a)
add if0
esp_now init ok
==================
CONTROLLER
==================
FF FF FF FF FF FF SEND SUCCESSFUL!
now from[5E CF 7F 14 C6 4A  len: 13]:ACK[00000000]
FF FF FF FF FF FF SEND SUCCESSFUL!
now from[5E CF 7F 14 C6 4A  len: 13]:ACK[00000001]
FF FF FF FF FF FF SEND SUCCESSFUL!
now from[5E CF 7F 14 C6 4A  len: 13]:ACK[00000002]
FF FF FF FF FF FF SEND SUCCESSFUL!
now from[5E CF 7F 14 C6 4A  len: 13]:ACK[00000003]
FF FF FF FF FF FF SEND SUCCESSFUL!
FF FF FF FF FF FF SEND SUCCESSFUL!
now from[5E CF 7F 14 C6 4A  len: 13]:ACK[00000004]
FF FF FF FF FF FF SEND SUCCESSFUL!
SDK version:3.0.0(e27cf60)
mode : softAP(5e:cf:7f:14:c6:4a)
add if1
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
bcn 100
esp_now init ok
==================
SLAVE
==================
recv action mgment
now from[5C CF 7F 14 C7 8A  len: 12]:Hello World!
5C CF 7F 14 C7 8A SEND SUCCESSFUL!
recv action mgment
now from[5C CF 7F 14 C7 8A  len: 12]:Hello World!
5C CF 7F 14 C7 8A SEND SUCCESSFUL!
recv action mgment
now from[5C CF 7F 14 C7 8A  len: 12]:Hello World!
5C CF 7F 14 C7 8A SEND SUCCESSFUL!
recv action mgment
now from[5C CF 7F 14 C7 8A  len: 12]:Hello World!
5C CF 7F 14 C7 8A SEND SUCCESSFUL!
recv action mgment
now from[5C CF 7F 14 C7 8A  len: 12]:Hello World!
5C CF 7F 14 C7 8A SEND SUCCESSFUL!
recv action mgment
now from[5C CF 7F 14 C7 8A  len: 12]:Hello World!
5C CF 7F 14 C7 8A SEND SUCCESSFUL!
recv action mgment
now from[5C CF 7F 14 C7 8A  len: 12]:Hello World!
5C CF 7F 14 C7 8A SEND SUCCESSFUL!
recv action mgment
now from[5C CF 7F 14 C7 8A  len: 12]:Hello World!
5C CF 7F 14 C7 8A SEND SUCCESSFUL!
recv action mgment
now from[5C CF 7F 14 C7 8A  len: 12]:Hello World!
5C CF 7F 14 C7 8A SEND SUCCESSFUL!
recv action mgment
now from[5C CF 7F 14 C7 8A  len: 12]:Hello World!
5C CF 7F 14 C7 8A SEND SUCCESSFUL!
recv action mgment
now from[5C CF 7F 14 C7 8A  len: 12]:Hello World!
cnlohr commented 5 years ago

I cannot look into this for another few days. But, I am eagerly going to try it out when I can!

AEFeinstein commented 5 years ago

@Junhao-Espressif I gave the libs posted on September 9th a try, and they worked! In the setup I called esp_now_add_peer() with NULL for the key, and 0 for the key length and was able to broadcast and receive unencrypted packets. Thanks!

AEFeinstein commented 5 years ago

Also I did my testing with @cnlohr, so I think those libs can be uploaded to the repository.

torntrousers commented 5 years ago

Is there a way to try the fix in lib_support_broadcast.tar.gz with the Arduino/ESP8266 code? When I try updating with the two files in lib_support_broadcast.tar.gz then all the compiles fail with:

C:\Arduino\ESP8266\181104\arduino-1.8.7\hardware\esp8266com\esp8266/tools/sdk/lib\libpp.a(pm_for_bcn_only_mode.o): In function `fpm_open':

/home/jhzhang/workspace/source_code/ESP8266_NONOS/esp8266_nonos_sdk_core/app/pp/pm_for_bcn_only_mode.c:227: undefined reference to `system_rf_cal_sector'

C:\Arduino\ESP8266\181104\arduino-1.8.7\hardware\esp8266com\esp8266/tools/sdk/lib\libpp.a(trc.o): In function `rcBuildIndex':

/home/jhzhang/workspace/source_code/ESP8266_NONOS/esp8266_nonos_sdk_core/app/pp/trc.c:414: undefined reference to `open_signaling_measurement'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board LOLIN(WEMOS) D1 R2 & mini.

Thats with the latest (today) Arduino/esp8266 github code where system_get_sdk_version() returns: 3.0.0-dev(c0f7b44)

AEFeinstein commented 5 years ago

I see libespnow.a and libpp.a were modified in b7ac6686ff7b906f6c80a45df02956e94d4b4566, but they are not identical to the files from lib_support_broadcast.tar.gz. @xcguang are the only differences compilation options, or did something else change?

DavidAC95 commented 5 years ago

@Junhao-Espressif Can you tell me how to implement this fix for a normal Esp8266 with Arduino IDE? As I cannot figure out how to install that file you posted, and I really need to be able to broadcast to get my project working. @AEFeinstein Or can you tell me how you got it working, if you were using an Arduino IDE that is? (this is for windows btw)

AEFeinstein commented 5 years ago

I was not using the Arduino IDE, I was using the non os sdk directly with a makefile on Linux. Sorry I cannot help you.

nemonote01 commented 5 years ago

Hi @DavidAC95 ,

Could you tell me the SDK verison ?

torntrousers commented 5 years ago

@Junhao-Espressif the most recent ESP8266 core for the Arduino IDE (2.5.0-beta2) was released just yesterday and that uses SDK version 3.0.0-dev(c0f7b44).

marcelstoer commented 5 years ago

@torntrousers

that uses SDK version 3.0.0-dev(c0f7b44)

not according to this file: https://github.com/esp8266/Arduino/blob/2.5.0-beta2/tools/sdk/version#L1

torntrousers commented 5 years ago

Mmm, interesting. I just now did a Serial.println(system_get_sdk_version()); on an ESP running the latest release and 3.0.0-dev(c0f7b44) is what that outputs.

DavidAC95 commented 5 years ago

@Junhao-Espressif I dont have the system in front of me at this moment. And I won't for a few weeks now but the last library update I did was for esp8266 2.4.2 which was on Dec 13th.

canadaduane commented 5 years ago

I too am interested in the Arduino IDE release of this fix.

DavidAC95 commented 5 years ago

@Junhao-Expressif has any progress been made on this issue for the Arduino IDE?

d-a-v commented 5 years ago

@ arduino users, please understand that espressif cannot answer here for arduino. Check the referenced issue above directing to the esp8266/arduino repository. Short answer, arduino still has not nonos-sdk-v3. Upgrading to this version is not straightforward as it was with older versions and we are currently busy with arduino core 2.5.0 stabilization. With espressif's vision of nonos-sdk's future, we need to think a bit more before our next step.

torntrousers commented 5 years ago

If thats the case then in the interim is there any possibility of having the ESP-Now broadcast fix thats in nonos-sdk-v3 back ported to the nonos-sdk version used in https://github.com/esp8266/Arduino/issues/5521#issuecomment-448383868?

DavidAC95 commented 5 years ago

@d-a-v I understand, then we will probably switch to the esp32 as we need broadcast capability. I do have one more question though, can the esp32 talk to esp8266? As in if we have the main hub being a esp32 could it broadcast to the esp8266s that we already have?

leenowell commented 5 years ago

Hi

I have this issue too and have tried 2.5 beta2 and 2.4.2 and neither seem to work. I have changed the 2 libraries from 2.5 beta 2 to the ones about and then get linker errors. Anyone have broadcasting working?

@Junhao-Espressif any update on the bug?

@DavidAC95 I have an esp32 sending an espnow message to an esp8266 (directly using its mac address) and the esp8266 receiving it. Broadcasting from the esp32 to the esp8266 is what doesn't seem to work.

thanks

Lee.

theicfire commented 4 years ago

Here's the fix for the Arduino library: https://github.com/esp8266/Arduino/issues/6174

petrkucerak commented 1 year ago

In my experience, the Arduino framework uses a library that implements only pseudo broadcast.[1] So if you want to simply send messages to all devices, you will be satisfied. Protocol will not function if you have any requirements for time.

You may want to use the ESP-IDF framework based on freeRTOS. This version supports broadcast too. It isn't a real broadcast also.

But I'll be planning to inspect this problem in more detail. I'll actualize the information.