I want to put an ESP32 / ESP8622 in our cars so that I can use them for presence detection. E.g. Open the garage door when we arrive home, close the garage door when we turn off the car.
I’m using some ESP8266 dev boards (Adafruit Feather HUZZAH), but I can’t get ESPHome to connect to WiFi fast enough. I did a few test runs today in the car where I drove up to the garage door and had to wait for 5-10 seconds before it connected and started to open.
I’m using the fast_connect: true
option for the wifi
module, but that didn’t help very much. Is there another way to configure the wifi module to connect even faster? Does it have some exponential back-off logic if it fails to connect repeatedly? I disabled the ap
and captive_portal
options.
I think the best option might be to get a WEMOS D1 Mini Pro and use an external 2.4G antenna. Maybe it will be able to connect while I’m further away down the road.
Yet another option would be to use the remote transmitter and remote receiver modules. I could set up another ESP32 in the garage to receive the 433MHz signals. That seems like it could be a lot faster and maybe more reliable.
It might be hard to make it secure though, so that someone can’t record/replay a signal and open the garage door. I found this thread, but it looks like no-one has worked on this before. Also this thread.
I have an idea for a protocol - The car ESP32 (C) would send an initial message with it’s unique ID. The garage ESP32 (G) would calculate a random nonce and store it in memory for this ID, and then transmit ID + nonce. C would compute the SHA256 hash of ID + nonce + 32 byte pre-shared key, and then transmit ID + hash. G receives the message and checks if it’s valid. If so, then it clears the nonce from memory, and then updates the HA sensor to “connected”. (Would also add a lot of error-correction and send everything multiple times so it’s very reliable.) Then it would keep repeating this once per second until the car is turned off. If it doesn’t receive any messages for a few seconds, then it updates the sensor to “disconnected.”
Cryptography is always difficult to get right! My initial attempt was vulnerable to replay attacks because I forgot to clear the nonce after it was used. I also added unique IDs in case both of our cars are on at the same time. But I think I’ve come up with something that’s pretty secure and not too hard to implement. Could be a fun project.
Is there a better / easier / existing way to achieve this? Should I just go with the WEMOS D1 Mini Pro + antenna?