5
votes
What programming/technical projects have you been working on?
This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's interesting about it? Are you having trouble with anything?
I use Github pages for a portfolio website when I apply for jobs. On my document.onload function, I implemented a simple thing that sends me email notifications, therefore logging page views. To avoid spamming myself when they switch between index.html and other subpages, I set it up to use cookies that expire after 24hrs. The basic email notification is being done through an Ajax call to submit a Google form that gives me email notifications. I am planning on implementing having the page viewer also submit IP addresses, so that if I submit an application to two different cities, I could look up that IP address to view which organization is reviewing my application. I do need to do further research into that still though.
For my audio player project, that is currently on temporary hold. I believe I shorted out some USB connections and therefore fried my USB controller, so I am currently waiting on a replacement RPi to arrive. I also need to modify the case design, but I messed up dependencies in FreeCAD (more so did not know that existed, so the dependency tree is a dependency line), so it might just be easier to design from scratch again.
I've just succeeded, finally, in writing a proof-of-concept shim for the Aqara FP2 presence sensor that translates zone presence and illumination data to the MQTT broker which is the backbone of my smarthome infrastructure- in a totally offline way!
The problem is that the FP2, unlike the FP1, is a "wifi" smart device- in that it communicates with the Aqara cloud and is accessible in the Aqara Home App. I would refuse to use it, except that it's the only device that I have found that manages to handle zoning of the detection space. I don't know how corporations have managed to normalise externally hosted smarthome functionality. IMHO, cloud-enabled smarthome devices are moronic for multiple reasons:
Why would I want to send the data that describes my living patterns to an external service which is likely poorly secured, and often sold off to advertising services?
Why would I want the functionality of my smarthome to degrade the second I experience internet connectivity issues?
Why would I want the lifetime of my smarthome to be at the whim of a third-party who could choose to stop providing the service at any moment?
Fortunately, the device does support at least one other protocol. Unfortunately, it's Apple's HomeKit- which may be documented well but perhaps this device doesn't subscribe to any form of the published standard because no matter how I prod it according to specification, it doesn't respond.
Recently, Aqara announced that the device has been updated to support Samsung's SmartThings protocol- yet another cloud-nonsensery, but after looking through the SmartThings driver for the device, on GitHub, I found that there are a number of entirely undocumented endpoints on the device through which you can actually fetch the device status! And so I have implemented a shim in Python, using aiohttp instead of requests because I need to do an amount of debouncing for global occupancy events, and I'd love to be able to bridge a number of devices at once.
The device listens on port 443, and has the following endpoints:
Endpoints!
GET /info
Returns the device model, vendor, serial number, etc, in application/json
GET /authcode
Returns an authentication token which must be used in more complex requests, in application/json
GET /attr
Requires a token, passed in with the header "Authorization: Bearer $TOKEN"
Returns a set of static attributes, such as number of zones, in application/json
GET /status
Requires a token, passed in with the header "Authorization: Bearer $TOKEN"
This is a server-sent event (SSE) stream, as text/event-stream, which streams events
The attributes are all opaque numerical identifiers, with a small amount of determinism, but it's enough to go off of- and I've mapped zone presence events to occupancy booleans, including a debounced global occupancy parameter which performs a consensus of all zone on the device.
It's a little rough around the edges, and the device isn't exactly reliable to start with (lots of false detection events / ghosts), but the consensus online is that it improves over time, or "learns". I'm just glad that it handles a much larger detection zone than the Sonoff SNZB-06P which we use in smaller rooms (all relative- it's not a big apartment). If I can get triggers consistently working, such as brightening lights at a workbench when you sit down at it, I'll be very happy indeed.