cyberman54 / ESP32-Paxcounter

Wifi & BLE driven passenger flow metering with cheap ESP32 boards
https://cyberman54.github.io/ESP32-Paxcounter/
Other
1.76k stars 409 forks source link

Enabling/Disabling WiFi scans through LoRaWAN commands. #477

Closed ajpaezm closed 5 years ago

ajpaezm commented 5 years ago

Hello,

I would like to turn on/off the wifi scanning at will through a LoRaWAN command. I'm not sure if such feature is already written in the code, but if not, I was thinking in this approach (identical to what set_blescan() is in rcommand.cpp script).

Please note that the variable wifiscan has been declared under globals.h and the table object has been updated as well inside rcommand.cpp.

void set_wifiscan(uint8_t val[]) {
  ESP_LOGI(TAG, "Remote command: set WIFI scanner to %s", val[0] ? "on" : "off");
  cfg.wifiscan = val[0] ? 1 : 0;
  if (cfg.wifiscan)
    wifi_sniffer_init();
  else {
    macs_wifi = 0; // clear WIFI counter
    //place here to call method that disables wifi readings.
  }
}

What I'm missing is the method that will disable wifi readings.

Is this something that already exists in the code? If so, how do we enable/disable it?

Also: is it possible for both WIFI and BLE to be enabled at the same time IF two ESP32 boards, which are supported of course, are connected?

Thanks in advance!

ajpaezm commented 5 years ago

To turn off the WiFi scanning, can I use something like this which I saw as well on main.cpp?

Line 373 of main.cpp:

WiFi.mode(WIFI_OFF)

This belongs to the library , right? Which is not included as default in the Paxcounter libraries. I tried adding this to the project folder, using this on the rcommand.cpp file:

include

...

void set_wifiscan(uint8_t val[]) {
  ESP_LOGI(TAG, "Remote command: set WIFI scanner to %s", val[0] ? "on" : "off");
  cfg.wifiscan = val[0] ? 1 : 0;
  if (cfg.wifiscan)
    wifi_sniffer_init();
  else {
    macs_wifi = 0; // clear WIFI counter
    WiFi.mode(WIFI_OFF);
  }
}

But it didn't work.

cyberman54 commented 5 years ago

paxcounter does not use the Wifi stack of ardunio-esp32, since this is neither needed nor useful for wifi promiscuous mode, but draws lot of power and RAM. So WiFi.mode() is not needed.

What is your intention, why do you want to switch off wifi scanning?

ajpaezm commented 5 years ago

Thanks for replying @cyberman54!

What is your intention, why do you want to switch off wifi scanning?

My goal with this part is just to be able to control when to scan wifi, when to scan ble, or when to scan both. Just that.

And I didn't see that option in the code. I guess I could set the rssi to -1db, which for practical usages would have the same effect. Unless of course there's a more efficient way of doing so.

cyberman54 commented 5 years ago

RSSI will affect both Wifi an bluetooth, so is not an option. Make a Pull Request to improve this software! That's why it is open source!

cyberman54 commented 5 years ago

@ajpaezm I added this feature, there is a new rcommand 0x17 to remotely switch wifi sniffing on/off. Please try current version in development branch, and report results here. Thanks.

cyberman54 commented 5 years ago

fixed in Master

ajpaezm commented 5 years ago

Hello @cyberman54, reporting results here:

1) When I set WIFICOUNTER to 0 and BLECOUNTER to 1, doesn't send me any errors. So good on that front.

2) But... when I try to use the 0x17 command, regardless if it is for turning it off or on, I get this message:

image

cyberman54 commented 5 years ago

@ajpaezm if you want to switch on/off WIFI during runtime, you need to set compile option WIFICOUNTER to 1. The runtime setting (rcmd 0x17) will automatically be saved on the board, so after you restart the device wifi will be off if you once set it to off, regardless of compile option WIFICOUNTER.