Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream temperature changes #6

Closed
tobyweston opened this issue Mar 31, 2017 · 3 comments
Closed

Stream temperature changes #6

tobyweston opened this issue Mar 31, 2017 · 3 comments

Comments

@tobyweston
Copy link
Owner

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.

@tobyweston
Copy link
Owner Author

tobyweston commented Nov 10, 2017

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?

@tobyweston
Copy link
Owner Author

tobyweston commented Nov 14, 2017

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

@tobyweston
Copy link
Owner Author

This is basically done now. There are some caveats:

  • Because of the underlying driver, we can't "stream" temperature changes directly from the temperature sensor hardware. We are forced to poll.
  • We therefore poll every second from the client, sending data to the server which is stored in memory
  • The server exposes this data via websocket for average and all sensor data
  • The client UI creates a websocket to read the values displaying them as they change

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant