Visitor Flow Rate Counting With Esp32

Photo of Makerfabs01

Made by Makerfabs01

About the project

In this project, I will tell you how to use ESP32 to make a simple people counter to count the visitor number of your side.

Project info

Difficulty: Easy

Platforms: ArduinoPython

Estimated time: 1 hour

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

Micro SD Card Micro SD Card x 1
Micro USB cable Micro USB cable x 1
MakePython A9G GPRS/GPS Expansion MakePython A9G GPRS/GPS Expansion x 1
MakePython ESP32 MakePython ESP32 x 1

Software apps and online services

Arduino IDE Arduino IDE

Story

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 people counter to help him count the changes in the number of customers.

How to Count

ESP32 is work 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.

Connection

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

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
  1. void wifi_sniffer_init(void)
  2. {
  3. nvs_flash_init();
  4. tcpip_adapter_init();
  5. ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
  6. wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  7. ESP_ERROR_CHECK(esp_wifi_init(&cfg));
  8. ESP_ERROR_CHECK(esp_wifi_set_country(&wifi_country)); /* set country for channel range [1, 13] */
  9. ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
  10. ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
  11. ESP_ERROR_CHECK(esp_wifi_start());
  12. esp_wifi_set_promiscuous(true);
  13. esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler);
  14. }<br>
  • Checking the MAC addition
  1. int check_mac_only(const uint8_t addr3[6])
  2. {
  3. for (char i = 0; i < mac_count; i++)
  4. {
  5. bool flag = true;
  6. for (char j = 0; j < 6; j++)
  7. {
  8. if (mac_lib[i][j] != addr3[j])
  9. {
  10. flag = false;
  11. break;
  12. }
  13. }
  14. if (flag == true)
  15. return 0;
  16. }
  17. for (char j = 0; j < 6; j++)
  18. {
  19. mac_lib[mac_count][j] = addr3[j];
  20. }
  21. mac_count++;
  22. return 1;
  23. }
  • Writing files to SD card
  1. void writeFile(fs::FS &fs, String path, String message)
  2. {
  3. Serial.println("Writing file: " + path);
  4. File file = fs.open(path, FILE_WRITE);
  5. if (!file)
  6. {
  7. Serial.println("Failed to open file for writing");
  8. return;
  9. }
  10. if (file.println(message))
  11. {
  12. Serial.println("File written");
  13. }
  14. else
  15. {
  16. Serial.println("Write failed");
  17. }
  18. file.close();
  19. }

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.
  1. #File which you want analysis
  2. 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 people and the curve of the number of people online.

Application

First, this counter is very small and portable, the number of people 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.

Code

Github

https://github.com/Makerfabs/Makerfabs_FAQ

Github

https://github.com/Makerfabs/Project_WiFi-Statistics

Credits

Photo of Makerfabs01

Makerfabs01

Makerfabs, Turnkey PCB Assemblies | Small Batch PCBA Prototyping | IoT Hardware Engineering.

   

Leave your feedback...