0

Reposting my Reddit sub - not much of help there :)

I have two different DIY projects, based on ESP32 BLE stack:

They both are pretty similar by the nature - what they mostly do is scanning BLE advertisements (first one for tags, second one - for lock status) and interact with MQTT. You may check corresponding files in src/esphome directories to see pure logic.

However, they're pretty different in a way to use data.

Tracker project:

  • does scan for several devices, so has stable scanning intervals;
  • does send generic payload to defined topic;
  • that's it.

Lock gateway:

  • does search for one device only, so scan is restarted right after getting adv from lock (or by timeout, as in tracker project);
  • does send advertisement data to defined topic;
  • has subscription to command topic, and does create BLEClient on command to connect to lock, write payload to some characteristic, and send result after.

The problem statement is following:

Right now I use separate devices for both projects. I have SONOFF NSpanel right beside the front door (I made custom alarm panel from it, so it's convenient). So I included my tracker to it's firmware, and it sends command to open the door for me right while I'm approaching. NSpanel has pretty good range BTW.

Also, as lock gateway should be pretty close to the lock for good connection, I have another ESP32 with lock gateway firmware. But it's still pretty far from lock, as I don't have sockets in vicinity.

Would be super-cool to have both tracker and lock functionality on NSpanel.

So I'm thinking, how (and if) I can merge these into one project, considering all unsimilarities in logic.

Does someone have any thoughts? Bumping my head for couple days already.

formatBCE
  • 159
  • 1
  • 12
  • 1
    What stops you from scanning continuously and handling the different devices after finding them? – Michael Kotzjan Sep 12 '22 at 06:26
  • 1
    That's actually perfect advice! It pushed me to search, how to make devices appear again after first message processed (I thought it's only possible on first scan, but apparently not). So first part is done. I don't need to restart scan to get new advertisement from same beacon. Now just need to realize, if it's possible to don't stop scan while sending commands to lock. Thank you @MichaelKotzjan – formatBCE Sep 12 '22 at 13:37
  • 1
    With your kick @MichaelKotzjan I did it, and it works good. Thanks for thoughts! – formatBCE Sep 12 '22 at 20:50

1 Answers1

1

Instead of scanning in sequence with defined interval, I'm starting scan forever, and stopping only for short period of time, when I need to send command to lock. It works pretty good.

formatBCE
  • 159
  • 1
  • 12