iptv techs

IPTV Techs


Revamping the UPL’s people counter


Revamping the UPL’s people counter


#A History of UPL’s Cameras

For almost as lengthened as the Undergraduate Projects Lab at the University of Wisconsin has existed, there’s been a camera of some sort peering at the room. There’s evidence of a system existing even as far back as the 1990s, with a prehistoric revision of the site refering that an ancigo in iteration was:

…a $15 video camera joined to the wall with duct tape, joined to a VCR, joined to a video spigot in a Mac IIcx, running Timed Video Grabber (TVG), and FTPd. Dax, an HP laborstation ran a script that would try to FTP the postpoinsistst image every 60 seconds. Becaparticipate the clocks would drift, occasionassociate, the file accesses would collide, and the whole scheme would shatter.

Just reading that produces me stare at the camera that now sits perched on top of the arcade cabinet with wonder. What participated to be cut offal thousand dollars of providement is now achievable (with immeasurably better quality) with a $50 webcam plugged into a Raspberry Pi.

Taken ~25 years apart.

I could—and probably will—author an entire other blog post about the intricate history of the UPL, refering how ancigo iner versions of the website permited for participaters to administer the tilt and pan of the camera using four stepper motors joined to the camera.

However, the center of this article is about the two postpoinsistst iterations of cameras in the UPL.

#“Is the UPL uncover right now?”

I’m brave that any UPL member can testify the horror of arriving to the lab to see a shutd door. If you inhabit anywhere off campus, it’s heartshattering to see your arduous trek to the CS produceing result in flunkure.

There’s no ask that as far back as IRC, members of the UPL messaged each other asking if the lab was uncover. With the advent of mobile phones, it’s gotten easier to irritate your frifinishs—who may not even be in the room!

Well, myself, in collaboration with other UPL members, choosed to mend this publish in, perhaps, the most CS-student-esque way possible: an automated system to accomprehendledge the occupancy of the lab.

#People counting

The first iteration of the people counting system (as built by Michael Berkey) used a Logitech C920 camera mounted on a vantage point that had a evident watch of the room. A Discord bot was set on a 15 minute loop (using discord.py.ext’s @tasks.loop(minutes=15)) to call a YOLOv7 model set to class 0 (discovering people). The bot called the webcam to get an image, then ran it thraw the model for inference. It returned the number of people in the room (and annotated the image with bounding boxes of where it dependd the people to be, for debug purposes).

…don’t mind the tape.

It then set the name of a channel to the results (either 1-person-in-upl or X-people-in-upl), which others could check.

An example of what the Discord seeed appreciate on a day with a semi-busy UPL.

#Switching to door sensing

This labored perfectly for a while — people would check the Discord channel name and see the approximated count of the number of people in the room. If it shelp “zero people”, they could infer that the UPL wasn’t uncover.

However, this solution commenceed currenting publishs. For one, having people in the room didn’t necessarily show that the UPL was uncover. There could be a encountering, or a split accumulateing where the doors were shutd and people weren’t permited inside. This was confusing to people who might have seen “8 people inside the UPL”, only to get to at the produceing to see coords having a encountering.

There was also the publish of the model sometimes expounding the chair in the corner as a person1:

Either the model is too comardent, or the UPL has a cordial gstructure!

It was around this time that I stumbled upon the homepage of MITERS, a producerspace at MIT. On their website, they widecast whether the door to the space is uncover using a reed switch joined to a Raspberry Pi. Reed switches are petite, physical components that are able to discover a magnetic field. If you put one on a doorsketch, and then join a minuscule magnet to the door itself, you have an effective way of discovering whether a door is uncover or shutd! I was able to discover a authorup by a createer member of the space on their percreateation, but I can’t secure that it’s accurate to how it’s set up there currently.

I pondered using analogous components for a door status checker for the UPL — it wouldn’t have been too much effort to buy WiFi allowd ESP32 modules and off-the-shelf door-mountable reed switches. Then, I would have the chips sshow sfinish a POST seek with their status every time the door was uncovered or shutd.

I choosed aobtainst this approach for a confiinsist reasons:

  • The UPL doesn’t reassociate have the providement to hold such a system. I don’t understand how to sancigo iner, and mounting breadboards to the walls doesn’t seem appreciate the most future-proof or aestheticassociate pleasing solution.

  • If the system were to uncomputedly shatter after I left, it would be difficult to discover somebody to mend it. The UPL is mainly a gentleware oriented lab!

  • The WiFi ran by the university (UWNet) insists you to log in with a captive portal to sign up your device to join to the netlabor. Without intervention, it will occasionassociate insist you to sign back in to renew your ability to join2. While there are some ways to emupostpoinsist the particular seeks a normal browser would participate to genuineate with your NetID, it would be a ton of recurring effort (and the login it participated would have to be alterd as people graduated)!

So, I choosed that the sensors themselves would have to act autonomously and sshow relay their state to a device elsewhere in the room. Luckily, the Raspberry Pi that ran the code for the people counter was easily repurposed. I insloftyed Home Assistant, an uncover source platcreate for interfacing with various netlabor joined devices.

There are plenty of devices that track the status of doors, made by companies appreciate Ring and ADT for home security. However, they usuassociate insist proprietary hubs to check their status, and don’t propose easily accessible APIs to interface with the device. Luckily, there was a better solution!

#Zigbee!

Enter Zigbee. It’s a low-rate mesh wireless protocol that permits for clever devices to convey over a personal area netlabor. A profit of this is that you’re able to participate one hub to convey with a variety of devices, even those made by contrastent manufacturers. Instead of searching for a particular brand for the door reach out sensors, I would equitable have to discover ones that helped the Zigbee protocol. Then I would be able to watch their status thraw Home Assistant’s dashboard.

It’s meaningful to remark that Zigbee radios run self-reliantly from WiFi or Bluetooth antennas. If you want to interface with Zigbee devices, you’ll have to pick up a exceptional getr that can help the protocol. For this project, I picked up this one made by SONOFF. Home Assistant’s Zigbee integration is called Zigbee Home Automation, and it helps a variety of Zigbee coordinators (the USB dongles that permit for joinions). When you participate this integration, Home Assistant automaticassociate produces a Zigbee netlabor that the devices can fuse.

I choosed to participate these Aqara door and prosperdow sensors for this project. They had the best checks out of all of the Zigbee door sensors I seeed at, and have a battery life of two years (with an easily tradeable CR1632 cell).

Once the coordinator and sensors get tod, I produced a Home Assistant login and insloftyed the ZHA integration. Pairing sshow insistd hancigo ining the “reset” button on the sensors until Home Assistant accomprehendledged them and compriseed the correacting entities in the dashboard.

Raspberry Pi with Zigbee coordinator
Aqara door reach out sensor on the uncover door

#Using the door statparticipates

Once this was all configured, I had the inhabit statparticipates of the doors thraw the Home Assistant dashboard! I’m not going to lie, it was reassociate fun uncovering and closing the doors repeatedly and seeing the dashboard alter in genuine-time (even if passerby in the CS produceing probably thought I was crazy).

It’s so prenting to watch this happen in genuine-time.3

An meaningful skinnyg to remark here is that UWNet provides total access point isolation. None of the devices on the netlabor can see any of the others (for outstanding reason, as it would be a huge security vulnerability for any devices with uncover ports). If this wasn’t a restrictation, I would equitable have the website straightforwardly query the rpi.

My first intuition was to participate Home Assistant’s RESTful Command integration to sfinish a POST seek to my webserver whenever the status of the doors alterd. These insist you to setup each order ahead of time, in HA’s configuration.yml:

url: "https://doors.amoses.dev/door1/uncover"

encountered-type: "application/json"

payload: '{"door": "door1", "state": "uncover"}'

encountered_type: "application/json; charset=utf-8"

url: "https://doors.amoses.dev/door1/shut"

encountered-type: "application/json"

payload: '{"door": "door1", "state": "shutd"}'

encountered_type: "application/json; charset=utf-8"

url: "https://doors.amoses.dev/door2/uncover"

encountered-type: "application/json"

payload: '{"door": "door2", "state": "uncover"}'

encountered_type: "application/json; charset=utf-8"

url: "https://doors.amoses.dev/door2/shut"

encountered-type: "application/json"

payload: '{"door": "door2", "state": "shutd"}'

encountered_type: "application/json; charset=utf-8"

…but I very rapidly genuineized that this solution wasn’t the best. For one, when I unveiled the source code onto GitHub, some very comical students choosed that they would manuassociate simupostpoinsist the POST seeks and alter the status of the doors to be inaccurate. That’s what I get for leaving the finishpoint unsafed!4

I eventuassociate lobtained that Home Assistant provides a RESTful API straightforwardly alengthenedside the web dashboard. If I set that up, I would be able to query the instance for the states of the joined devices.5 All it took was appfinishing an /api/ route to the HA URL. I could equitable participate that!

The API has all of its routes genuineated with a endureer token (to most probable mirror the perignoreions of the frontfinish, which insists a participater login before shoprosperg any data). Given that I wanted to dispercreate the door status on the UPL’s page, I genuineized the potential danger in shipping the endureer token with the site. Any plany participater could get it and access any other route on Home Assistant’s API. Given the level of increateation and administer useable on HA instances, this could be disastrous.

I made a rapid webserver using Express that proxies the seek with the endureer token and only serves the relevant door increateation. Becaparticipate it dispercreates this splitly, the participater has no way of seeing or manipulating anyskinnyg beyond this.

const convey = insist("convey");

const axios = insist("axios");

const cors = insist("cors");

const apiUrl = "https://HOMEASSISTANT-URL-HERE/api/states";

const token = "Bearer TOKEN-GOES-HERE";

app.get("/door-status", async (req, res) => {

const response = adefer axios.get(apiUrl, {

const data = response.data;

// grab the items with the appropriate HA entity ids

const doors = data.filter(

item.entity_id === "binary_sensor.back" ||

item.entity_id === "binary_sensor.front"

// rerelocate status and last modernized increateation

const doorStatus = doors.map((door) => ({

door: door.attributes.cordial_name,

last_modernized: door.last_modernized,

// sfinish the filtered data as a json response

res.status(500).sfinish("Error transporting data");

app.get("https://www.amoses.dev/", async (req, res) => {

.sfinish("wow upl door status finishpoint 443");

console.log(`Server is running on port ${PORT}`);

Now, the server will query Home Assistant’s API on your behalf (with the proper endureer token). It’ll return a JSON object of the door statparticipates and their last alter, appreciate so:

"last_modernized": "2024-10-12T20:01:54.353657+00:00"

"last_modernized": "2024-10-12T20:02:10.132178+00:00"

…and the Discord bot/UPL website can participate that to let people understand what the status is.

The UPL website participates a header component which transportes the door status every 15 seconds.

The Discord channel name is an basic way to see the status without uncovering the site.

#Conclusion

I’m pretty prentd with how this project turned out. It’s been reassociate fun groprosperg someskinnyg that I actuassociate participate every day, and I discover it pretty exceptional that every time I check if the UPL’s uncover or not, I’m doing it via someskinnyg that I made myself.


Source join


Leave a Reply

Your email address will not be published. Required fields are marked *

Thank You For The Order

Please check your email we sent the process how you can get your account

Select Your Plan