Visitor Flow Rate Counting With ESP32

2,900

30

3

Introduction: Visitor Flow Rate Counting With ESP32

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.

Supplies

Hardware:

Software:

  • Arduino

Step 1: How to Count

ESP32 is work in a promiscusous mode that this clever chip allows IEEE802.11 network packets capturing for further analyzing. Presented sniffer requires a callback function that will process all received promiscusous packets. Example callback function displays few basic information like packet type (control packet, management packet, etc.), RSSI or MAC addresses. Nowadays everyone has a smart phone 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.

Step 2: Connection

Connect two boards according to the pins. Power the boards via mobile power.

Step 3: Software and Code

ESP32 Support

Follow the Installation Instructions to add ESP32 support if you are not yet doing it: https://github.com/Makerfabs/Makerfabs_FAQ.

Code

You can get the code from here: https://github.com/Makerfabs/Project_WiFi-Statistics.

  • Sniffer init
void wifi_sniffer_init(void)
{
  nvs_flash_init();
  tcpip_adapter_init();
  ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
  wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  ESP_ERROR_CHECK(esp_wifi_init(&cfg));
  ESP_ERROR_CHECK(esp_wifi_set_country(&wifi_country)); /* set country for channel range [1, 13] */
  ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
  ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
  ESP_ERROR_CHECK(esp_wifi_start());
  esp_wifi_set_promiscuous(true);
  esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler);
}<br>
  • 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;
        break;
      }
    }
    if (flag == true)
      return 0;
  }
  for (char j = 0; j < 6; j++)
  {
    mac_lib[mac_count][j] = addr3[j];
  }
  mac_count++;
  return 1;
}
  • Writing files to SD card
void writeFile(fs::FS &fs, String path, String message)
{
  Serial.println("Writing file: " + path);
  File file = fs.open(path, FILE_WRITE);
  if (!file)
  {
    Serial.println("Failed to open file for writing");
    return;
  }
  if (file.println(message))
  {
    Serial.println("File written");
  }
  else
  {
    Serial.println("Write failed");
  }
  file.close();
}

Step 4: 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\ wifi_count.py” 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.

Step 5: Application

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.

Be the First to Share

    Recommendations

    • DIY Summer Camp Contest

      DIY Summer Camp Contest
    • First Time Author Contest

      First Time Author Contest
    • Metal Contest

      Metal Contest

    3 Comments

    0
    maxs
    maxs

    9 months ago

    This looks like a great build. I just got the parts in the mail and I'm going to make a go this weekend.

    Thanks for creating this!

    0
    RyanMake
    RyanMake

    9 months ago

    This is really interesting. I would think that this could be an interesting non-optical element to a security system where you have accepted MAC addresses could trigger different practical features in a space and then if an unknown address is present and moves around a space it could send a notification.
    Since it is just sniffing the WiFi what power state can the device be in? How low can the power consumption be?
    I am going to have to build this myself to play around with it!

    0
    Lan_D
    Lan_D

    Reply 9 months ago

    I just wanted to implement this without considering power consumption at that time. If you want low power consumption, set the working mode of ESP32 to Modem-sleep mode or other modes when don’t need a sniffer.
    Thanks for your suggestion!