Alternatives to WiFi direct (P2P)?

dizcza
Posts: 55
Joined: Tue Sep 07, 2021 6:59 pm

Alternatives to WiFi direct (P2P)?

Postby dizcza » Wed Sep 15, 2021 7:43 am

I need to send real-time sensor data from an ESP32 board to my Android phone (I'm the only client). The range should be 10...100 m, so Bluetooth is not an option. The ESP32 board will be placed in a field, in the middle of nowhere. No internet connection, obviously.

Could someone explain how to send real-time data from an ESP32 to a smartphone over WiFi without an internet connection?

This topic https://github.com/espressif/esp-idf/issues/6522 suggests that I need to set up the ESP32 in a soft AP mode, and it makes sense - was the AP on my smartphone, the ESP32 board, set up as a client, would pick nothing but dust in 100 m away from the AP. I'm fine connecting to a soft AP and losing the internet connection. In fact, I'm to use the WiFi protocol only to check if my ESP32 board works and see real-time plots of the sensor measurements. Optionally, I could send a command or two to the ESP32 board over the WiFi.

What I've already found:
  • HTTP WebServer/WebSocket is an option only in case of an available internet connection local network.
  • FAQ "How does ESP32 receive and transmit Wi-Fi 802.11 packets?" (https://docs.espressif.com/projects/esp ... 11-packets) provides two APIs for sending and receiving data respectively:

    Code: Select all

    esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
    esp_wifi_set_promiscuous_rx_cb(wifi_sniffer_cb);
    
    But I'm really struggling to understand how to use this API. There are no related examples. The documentation guys do mention the usage in the mconfig_chain component, but it uses the "esp_wifi_set_promiscuous_rx_cb()" function only, which is optional in my case. Besides that, it's quite hard to follow 500+ lines of code to understand how this component works. And there are no official examples for the "esp_wifi_80211_tx()" function.
  • This repository https://github.com/Jeija/esp32-80211-tx attempts to show how to use the "esp_wifi_80211_tx()" API, but questions arise:
    • There are no event handlers for setting up a connection to a station. Are these beacons accessible to every sniffer around? I'm fine with that. How a smartphone could pick them up? Answer: I could use any Android WiFi scanner to scan for WiFi networks every 1 or 10 seconds and collect the WiFi beacons that an ESP32 board is sending with the payload encoded in the name of a non-existent AP. Not only will this spam the area with WiFi beacons of non-existent APs but also
      • I won't be able to plot real-time data in Android. Only when a scan finishes, I'll get the result as an array of values.
      • There are limitations on successive WiFi scans in Android 8.0+.
      • I'll lose the data sent between every two scans issued by a phone.
    • Each frame starts with a payload header (uint8_t beacon_raw[]). And I have no idea how or should I adapt the header to represent my own data. Does this header work for any custom data an ESP32 is sending? Answer: it looks like yes. Although esp_wifi_80211_tx documentation (https://docs.espressif.com/projects/esp ... ace_tPKvib) states that the buffer length must be <= 1500 Bytes, I haven't tried sending a WiFi beacon with the data size larger than 32 characters (maximum SSDI length).
    • Apart from beacons, examples of sending the probe request, probe response, action frame, and non-QoS data frame are missing.
  • A repository https://github.com/RavenLRS/raven/blob/ ... sp32/p2p.c with an interesting implementation of P2P:

    Code: Select all

    void p2p_hal_init(p2p_hal_t *hal, p2p_hal_callback_f callback, void *user_data);
    void p2p_hal_start(p2p_hal_t *hal);
    void p2p_hal_stop(p2p_hal_t *hal);
    void p2p_hal_broadcast(p2p_hal_t *hal, const void *data, size_t size);
    
    Perhaps, ESP32 devs could take a look and see if it could be ported to ESP-IDF, but I was unable to follow it 100%.
  • While provisioning the ESP32 WiFi, a custom handler for the optional provisioning endpoint can be registered by the application.

    Code: Select all

    esp_err_t wifi_prov_mgr_endpoint_register(const char *ep_name,
                                              protocomm_req_handler_t handler,
                                              void *user_ctx);
    
    But that means that the board should never leave the provisioning state. Moreover, how to continuously send data from an ESP32 to a smartphone while being in the provisioning mode? And turn off the default WiFi scan since I don't need it... I doubt that this is the way to go.
  • WiFi Aware proximity-based beacons, but ESP32 boards don't support them.
I'd appreciate if someone points me to a working example... simple, please. Or at least explain which of the provided above options I better stick to. Or provide your own thoughts.

Thank you.

Who is online

Users browsing this forum: Baidu [Spider], ESP_rrtandler, Google [Bot], Majestic-12 [Bot] and 136 guests