redis pub/sub with websockets - part II
Date: 2021-02-12
Author: Andrew
Some progress today but a camera problem put a screeching halt to the development.
First was understanding why the pubsub arrangement appeared to be initialized correctly but the messages weren't appearing. Looking through the example I suddenly realised. The code that the service was triggering was using r.mset({"ram_free" : get_ram()}) (get_ram() being a custom function I wrote). When instead it should be r.publish("ram_free", get_ram()).
As soon as I changed the code to have a publish instead of mset the messages started appearing in the listener script output!
Next step is to integrate the pubsub arrangement with the server so that on launch it triggers a new thread to establish the pubsub arrangement and monitor redis for changes. When there is a change it is pushed to the websocket, which will update the UI.
Started making the changes and the first time I ran the script to test how things were going I got a camera error. Opened a terminal session and tried to use the most basic of camera commands.
pi@br-v3:~ $ raspistill -t 0
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
mmal: camera component couldn't be enabled
mmal: main: Failed to create camera component
mmal: Failed to run camera app. Please check for firmware updates
So off on a bug hunt. These are the kind of bugs I hate (those and package version problems) where the underlying problem is unclear, in places where I can't easily get to them and have little or no understanding of how they really work.
So I:
- checked that the camera is detected and all good.
- disabled camera, reboot, enable camera, reboot.
- swapped camera to another that I know works.
Still no progress :(
When I run the server script in Thonny I am also getting also getting a "socket is in use" error when the camera code bombs. I've asked Rohan what could cause this. Is it possible that somehow a previous video stream connection isn't closed and is causing the camera to lock the new session out? Awaiting response...