Pi Garage worked well for a while, however there was one thing that bugged me. When you would have 2 devices open on the home screen (in the mobile app) and you would open the door on one device the state would change from “closed” to “opening” to “open” but on the other phone it would still say “closed”.
This annoyed me as to get the latest state you constantly had to “swipe to refresh” to ensure that you had the latest state of the garage door. Not a big deal in the scheme of things but it was a good problem to solve.
At first for a quick solution I tried just adding a “refresh timeout” that would periodically refresh the screen. As you can gather this performed poorly for a number of reasons.
- Still had a delay that the data was not right
- Constantly sending traffic from clients to server (potentially even when the app minimised)
- Taking in the previous this would potentially(?) use data when you are on mobile data (especially if you are roaming data)
To fix this issue I decided to introduce websockets (specifically socket.io) so that bi-directional realtime communication could occur between clients and the server. This meant as soon as a door state was changed it was immediately sent to all other clients in real time.
NOTE: Only the realtime data has moved to websockets, the basic REST API is still supported and recommended for 3rd party integrations. To support realtime 3rd party event messages there is an feature request issue for this on GitHub to introduce webhooks in the future.
Leave a Reply