ESP32 Project: Visitor Flow Rate Counter

ESP32 Project: Visitor Flow Rate Counter

November 13, 2020

In this ESP32 project, we will make a visitor flow rate counter with ESP32, using the MakePython ESP32 and MakePython A9G GPRS/GPS expansion board.

Last weekend I went to my friend’s milk tea shop to help because the business was so hot that he didn't arrange enough clerks. In order to reasonably arrange the working hours of the clerk, I Build a counter to help him count the changes in the number of customers.

1. Materials

1.1 Hardware

1.2 Software

  • Arduino

2. How the Visitor Flow Rate Counter Works


ESP32 is working in a promiscuous mode that this clever chip allows IEEE802.11 network packets capturing for further analysis. Presented sniffer requires a callback function that will process all received promiscuous packets. Example callback function displays a few basic information like packet type (control packet, management packet, etc.), RSSI, or MAC addresses. Nowadays everyone has a smartphone that has a unique MAC address. It means the MAC address represents one person, and counting the MAC address means counting the number of people.

3. How to Connect the Hardware


Plugin two boards according to the pins. Power the boards via mobile power bank.

4. Software and Code

4.1 ESP32 Support

Follow the Installation Instructions to add ESP32 support if you are not yet doing it:

4.2 Code

  • Sniffer init
void wifi_sniffer_init(void)
  ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
  wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  ESP_ERROR_CHECK(esp_wifi_set_country(&wifi_country)); /* set country for channel range [1, 13] */
  • Checking the MAC addition
int check_mac_only(const uint8_t addr3[6])
  for (char i = 0; i < mac_count; i++)
    bool flag = true;
    for (char j = 0; j < 6; j++)
      if (mac_lib[i][j] != addr3[j])
        flag = false;
    if (flag == true)
      return 0;
  for (char j = 0; j < 6; j++)
    mac_lib[mac_count][j] = addr3[j];
  return 1;
  • Writing files to SD card
void writeFile(fs::FS &fs, String path, String message)
  Serial.println("Writing file: " + path);
  File file =, FILE_WRITE);
  if (!file)
    Serial.println("Failed to open file for writing");
  if (file.println(message))
    Serial.println("File written");
    Serial.println("Write failed");

5. Processing Data

  • The data file obtained by the counter is stored in the SD card that starting with “log”. Copy it to the PC.
  • Open the Python file “\Project_WiFi-Statistics\” with notepad mode, modify the code about the file path and name.
#File which you want analysis
trace_file_name = "./log3.txt"
  • Use “cmd.exe” to open the Python file and get graphics.
  • In addition to saving the data in the SD card, you can send the data to the website with ESP32, and you can view the current number of pedestrians and the curve of the number of pedestrians online.

6. More Applications for ESP32 Visit Flow Counter


First, this counter is very small and portable, the number of pedestrians can be counted anytime and anywhere as long as you connect the mobile power supply, I think it is very convenient. Second, the detection range of this counter is large. It can be used in a large shopping mall to count the number of people in the shopping mall over time, so that you can see what time period the passenger flow peaks and how many people will increase. At the same time, it can be used in public places, such as parks and squares that you can investigate the number of people as a hawker, etc.
If you have any further questions or need some PCBA customizations based on those MakePython IoT boards, feel free to contact

Contact us