Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use several advertisement keys like https://github.com/dakhnod/FakeTag #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

olivluca
Copy link

I modified the component so that it rotates among several keys (I wouldn't want the eventual thief to be alerted there is a tag tracking him).
The configuration parameter key is now keys and it's a list (I tested with 100 keys). You can specify just one key and it will work like before.
There's a new configuration parameter key_switch_interval to specify the interval in seconds when the next key has to be used (by default 3600 = 1 hour).
Since it's the first time I touch esphome and the esp32 and I don't like C++ I'm not sure if what I did is 100% right.
I performed two tests:

  1. 100 keys with an interval of 10 seconds, checking with nrf connect on my (android) phone.
  2. 100 keys with an interval of 3 minutes and checking apple servers with https://github.com/biemster/FindMy

In test 1 I missed a handful of keys (I don't know if it's because they weren't sent or my phone was too slow to scan.
In test 2 I only saw 59 keys out of 100, I don't know which apple device is picking my tag so I cannot say if this test is failing or it's OK. I'll leave it running with a 10 minutes interval and I'll check later if it picked up more keys.

@barrenechea
Copy link
Owner

Awesome! I wasn't aware of FakeTag. I'll be taking a look and reviewing this In a bit!
Thank you very much!

@olivluca
Copy link
Author

I have the key_switch_interval set to 10 minutes, but I think the esp32 is rebooting (I'm not monitoring it constantly): I received reports up to the first 15-20 keys then it restarts from the first one.
The risk is that with an 1 hour interval (so that the 100 keys would last 4 days before repeating) it could cycle only through the first 3/4 keys (unless the restarts are due to the key change process).

@olivluca
Copy link
Author

(though the latter is unlikely, since when I had the interval set to 5 minutes I could cycle through all the keys)

@olivluca
Copy link
Author

Last night I left the esp32 connected to a good quality power bank (in case the reboots where caused by the power supply) and it only got reports of keys 0 and 1. Now I'm back to a 10 seconds interval and it cycles all 100 keys no problem (and I get reports of most of them).
I don't know what's causing the reboots, maybe the current key index could be saved to flash so when it reboots it could start from the last key, though I don't know if that would wear the internal flash too much.

@olivluca
Copy link
Author

I added an option "save_key_index_to_flash" to save the current key index to flash.
If you find the cause of the crash this code can be omitted.

@olivluca
Copy link
Author

Is there a reason why you create a task with xTaskCreatePinnedToCore instead of just calling ble_setup in setup?
Just curious (and perhaps sending log messages from a different task is what causes the crashes).

@olivluca
Copy link
Author

I'm testing a version that does just that (ble_setup in setup and key switching in loop) and it seems to be working just fine (i'll let it run for a while to see if it crashes).

@olivluca
Copy link
Author

still crashing 😞

@olivluca
Copy link
Author

I think the reboots were caused by the wifi reboot_timeout.
I now set that to 0s, as well as fast_connect to true (to remove the warning "Error! Should use default active scan time parameter for WiFi scan when Bluetooth is enabled!!!!!!").

@olivluca
Copy link
Author

I think now I really found the cause of the reboot: "[E][api:127]: No client connected to API. Rebooting..."
I wasn't seeing it because I wasn't using the serial port to monitor the esp32, in fact while I was watching it it never rebooted (d'oh, the logger was connected to the api).
I added "reboot_timeout: 0s" to the api: section, let's see if it really stops rebooting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants