Closed tobyweston closed 6 years ago
See the BlazeWebSocketExample.scala from Http4s (server side).
See react-webscoket for the client side
On the server, could use java's WatcherService
to update a queue of some sort then in the TemperatureEndpoint
create a continuous Process
to read the queue:
val source = scalaz.stream.time.duration.map{ d =>
Text( ... read the queue and encode as json ... )
}
Raspbian supports inotify
(the presence of /proc/sys/fs/inotify/
confirms it):
$ ll /proc/sys/fs/inotify/
total 0
-rw-r--r-- 1 root root 0 Nov 12 20:50 max_queued_events
-rw-r--r-- 1 root root 0 Nov 12 20:50 max_user_instances
-rw-r--r-- 1 root root 0 Nov 12 20:50 max_user_watches
$ cat /proc/sys/fs/inotify/max_user_watches
8192
Looks like http4s doesn't support websockets from the client side, perhaps Async Http Client would be better? or nv-websocket-client?
See issue_6 branch and issue_6_of_temperature_machine for the UI.
Bit of a blocker: on the Pi, the sensor file's stat
doesn't seem to update 😢
https://raspberrypi.stackexchange.com/questions/75167/ds18b20-w1-slave-file-stamp-doesnt-change
This is basically done now. There are some caveats:
There may be weird behaviour when client machines drop in and out of the pool. It looked like when a new machine was added, the UI didn't update but I need to confirm if this is the case.
Using
inotifywait
(), watch for file changes of the temperature sensor and send straight to the server.Update the sever to stream current temperatures via web sockets rather than HTTP GET.
Update the UI to respond reactively to streamed temperature changes. Potentially update the chart in real time.
Note that RRD has a rate limit of 1 second, so might need the debounce.