Live data from Hacker News

Building an occupancy sensor with a $5 ESP32 and a serverless DB

matthew.science

141–150 of 221 posts

Re: Building an occupancy sensor with a $5 ESP32 and a serverless DB

#141
It's great seeing all the different approaches people can come up with to do similar things!

I recently worked on a similar side project but took a very different approach. It pretty much was just:

1. A bash script in a Raspberry Pi W that ran `bluetoothctl` once per minute and wrote the raw output for that minute to a file.

2. A systemd process that would ensure the script would get re-run if the process crashed or machine rebooted

3. A separate script that parsed the logs and pushed them to a local sqlite DB that tracked the minute the bluetooth id was found.

4. A daily push to my backup server that stored the sqlite DB

I decided to use systemd and a simple(10loc) bash script since I faced a similar issue to the OP where my pi would crash(although it was purely my fault for messing with a bunch of cables) and I wanted a way to get it running again with the lowest overhead. I also wanted as few dependencies as possible.

I went with SQLite because it made querying for trends and building dashboards simpler and more interesting(and because the real project was the sqlite interface I was building :) )

One thing I learned from running this which also may answer a couple of OPs questions: Apple devices like hiding themselves. The only way I could get my Apple laptops and phones to show up was to keep the bluetooth settings menu open on them. Otherwise, they wouldn't appear to the bluetooth scanner. I can't speak much to whether android devices are 'noisier', but the lack of bluetooth feeds for Apple devices alone cuts out a significant part of the value of bluetooth scanning for crowd sensing, given the market share for Apple devices.

Re: Building an occupancy sensor with a $5 ESP32 and a serverless DB

#142
post #43

How do people "productize" their ESP32 projects? (Edit: not talking about mass-producing something, I just want a self-contained unit rather than a board with a bunch of wires sticking out) I see a lot of pages where they show some bare-looking board, but in the real world you want to package that up. If you're a software guy like me, you would likely prefer to pay a bit extra to just have that tidied up for you rath…

I wouldn't call it "productize", but when I wanted to give an ESP32 project to a friend who would be using it, I did these things: designed and printed a case for the ESP32. The ESP32 is soldered into a perma-proto and all wire connections are soldered to the ESP32's terminals (I don't use a solderless breadboard, or Dupont wires, once I'm done with the design). The perma-proto is screwed into posts in the case (as are several daughterboards). The user-controlled potentiometer is also soldered into the perma-proto and is tightly screwed into the case. There's a power jack screwed into the case, and all wiring in/out of the case goes through a "cable gland" and the cables, outside the case, and wrapped into nylon sleeve with strain relief. And an on/off switch.

example: https://www.printables.com/model/72839-stable-and-waterproof.... If I am using screw terminals, wires are terminated with ferrules.

For some projects that use 120V AC directly, I've purchased nice receptacle with fuse, and grounded the metal casing. But I don't feel comfortable distributing those.

I have also been known to encase an entire project in clear epoxy (the first "maker" project I did, thanks to an enlightened shop teacher in the 1980s, was a nightlight using only 3 components, encased in epoxy; they work some 35 years later!)

Some things I can think of to go further: designing my own PCB instead of using perma-proto. FInding better temporary connectors (duponts are not reliable). Eliminating the ESP32, replacing it with simpler logic circuits when possible.

Re: Building an occupancy sensor with a $5 ESP32 and a serverless DB

#143
post #130

Ultra wide band can be used to detect tiny movements of humans in a room. It can detect a finger twitching from several meters away. https://www.eenewseurope.com/en/uwb-human-sensor-uses-impuls...

Aqara makes a mmWave presence sensor https://www.aqara.com/us/product/presence-sensor-fp2

Make It Work have reviewed 18 different home mmWave sensors, Aqara included:

"Best mmWave Presence Sensors for Home Assistant!" https://www.youtube.com/watch?v=Kt1FpRM8R18

Re: Building an occupancy sensor with a $5 ESP32 and a serverless DB

#144
post #47

Earlier quoted context omitted.

3d printed enclosure?

That sounds like one of those "I have a problem... now I have two problems" jokes. I wanted something simple and cheap and now I need to go deal with this whole other thing I don't know much about and either rent or buy into it?

The simplest I can think of is this: https://www.digikey.com/en/products/detail/sparkfun-electron... use a step drill or other large-diameter bit to cut holes for cable glands, dremels to cut rectangular holes for power switches, and drill and tap holes for standard brass standoffs. IMHO everybody should have at least one cordless drill and drill bits, as well as an M3 tap. Then use Cable glands for wires going in/out, and nylon sheathing for the cables outside the box.

If you take the time to make the holes nicely, the result often looks good enough that non-makers will think you are a god of manufacturing.

Re: Building an occupancy sensor with a $5 ESP32 and a serverless DB

#145
I was initially skeptical, but these days most of my ESP32s just run micropython and I write my "firmware" in Python. This includes (low-performance) callbacks for interrupts, python dicts. Because the ESP32 has nice peripherals, lots of stuff is really just using python or C as a command-and-control to enable part of the chip, like PWM. And porting Python to C++ is usually pretty straightforward.

Re: Building an occupancy sensor with a $5 ESP32 and a serverless DB

#148

Very impressive. This made me chuckle: > I asked campus IT to whitelist the MAC address Back at my uni this would have been a multi week endeavour with a number of forms and likely a denial. This was 15 years ago so hopefully things have changed there now.

It's actually because our WiFi portal doesn't allow printers, game consoles, etc without browsers to connect, we have to manually add it. Though there is a portal to add it ourselves without IT, I am at the max 5 devices through there so I have to ask for overrides :)

Re: Building an occupancy sensor with a $5 ESP32 and a serverless DB

#149
post #65

Did something very similar years ago - https://blog.yifangu.com/tag/library-occupancy-project/

Wow, very cool! I would have used WiFi but unfortunately our beacons either separate or merge devices (so you either get just the users on the nearest beacon, which is not a set range of distance, or every user on that region's subnet, which could be entire dorm complexes). But that seems like a really good solution!

Re: Building an occupancy sensor with a $5 ESP32 and a serverless DB

#150

I am also considering selling it to brick-and-mortar businesses that want to measure occupancy trends. They've been able to do that long before invasive solutions like this, or computers, even existed --- turnstiles.

How many stores have you visited recently that have turnstiles? You've probably been in more that are using a variation of this tech.

There are a few companies offering it as a commercial product, and yes there are people that want to buy it. The value is not just knowing how many people are in a store, but where they are going, what they are spending their time looking at.

Post reply on HN