Master The ESP32 WiFi: ESPNow
Written by Harry Fairhead and Mike James   
Monday, 08 December 2025
Article Index
Master The ESP32 WiFi: ESPNow
Transmit
Listing

Transmit

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "esp_wifi.h"
#include "nvs_flash.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "string.h"

#include "esp_now.h"

static void example_espnow_send_cb(const esp_now_send_info_t *tx_info, esp_now_send_status_t status)
{
    printf("Send\n");
    fflush(stdout);
}

void app_main(void)
{

    esp_event_loop_create_default();
    nvs_flash_init();
    esp_netif_init();

    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    esp_wifi_init(&cfg);

    esp_wifi_set_mode(WIFI_MODE_STA);
    esp_wifi_set_channel(3, WIFI_SECOND_CHAN_NONE);
    esp_wifi_start();

    int err = esp_now_init();
    err = esp_now_register_send_cb(example_espnow_send_cb);

    esp_now_peer_info_t peer = {
        .peer_addr = {0x08, 0xB6, 0x1F, 0x29, 0xBE, 0x7C},
        .encrypt = false,
    };

      esp_now_peer_info_t broadcast = {
        .peer_addr = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
        .encrypt = false,
    };

    err = esp_now_add_peer(&broadcast);

    uint8_t data[] = {1, 2, 3, 4, 5, 6};
    err = esp_now_send(broadcast.peer_addr,data,6);
    printf("error= %x\n", err);

    while (true)
    {
        vTaskDelay(100 / portTICK_PERIOD_MS);
    };
}

 

 

Summary

  • AP mode allows a small number of clients to connect to an ESP32.

  • A DHCP server is automatically added to an AP net interface (netif) to assign IP addresses to clients.

  • One application of AP mode is to allow the user to connect to an ESP32 using a browser or a custom mobile app and configure the ESP32.

  • You can set an ESP32 into AP and STA modes, but clients are not able to connect to the AP and use the STA to communicate with the local network or the Internet.

  • It is possible to give clients Internet and local network access using a NAT router module.

  • In promiscuous mode the WiFi will pass any packets it receives to the program, even if they are not addressed to the device.

  • Two or more ESP32 devices can connect using long range mode and achieve a range of up to 1 kilometer.

  • The ESP Now module provides a very simple point-to-point network without access points or connections.

  • ESP WiFi Mesh can be used to connect ESP32 devices to each other and to a router, even if some of the devices are too far away to communicate directly. 

MasterThe ESP32In C:
WiFi with the ESP-IDF, FreeRTOS, LwIP & MbedTLS

By Harry Fairhead & Mike James

ESPMaster360

Buy from Amazon.

Contents

  • Chapter 1 FreeRTOS Basics 
  • Chapter 2 Locks and Synchronization
  • Chapter 3 Practical Tasks 
  • Chapter 4 Data Structures
  • Chapter 5 Basic WiFi
  • Chapter 6 Using LwIP
  • Chapter 7 Sockets and HTTP Clients 
  • Chapter 8 Socket Server
  • Chapter 9 Details of Cryptography
  • Chapter 10 SSL/TLS and HTTPS
  • Chapter 11 SSL Server
  • Chapter 12 UDP For Speed
  • Chapter 13 SNTP For Timekeeping
  • Chapter 14 SMTP For Email
  • Chapter 15 MQTT For The IoT
  • Chapter 16 Advanced WiFi and AP Mode
      Extract: 
     ESPNow  NEW!!!
  • Appendix I Advanced WiFi Configuration

<ASIN:B0G5M76KLB> 

pico book

 

Comments




or email your comment to: comments@i-programmer.info

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.



Last Updated ( Monday, 08 December 2025 )