Skip to content

Commit

Permalink
Readings working, but no more graph
Browse files Browse the repository at this point in the history
  • Loading branch information
MonsieurV committed Nov 24, 2024
1 parent 84b9ced commit 26ac032
Showing 13 changed files with 488 additions and 607 deletions.
16 changes: 5 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -30,15 +30,9 @@ debug:
pipenv run python app.py --debug

run:
pipenv run gunicorn -k eventlet -w 1 --bind 0.0.0.0:8080 app:app
pipenv run gunicorn -k eventlet -w 1 --bind 0.0.0.0:9898 app:app

PID=$(shell cat run.pid)

start_gunicorn:
pipenv run gunicorn -k eventlet -w 1 --bind 0.0.0.0:8080 app:app > /dev/null 2>&1 & echo $$! > run.pid

start:
pipenv run python app.py > /dev/null 2>&1 & echo $$! > run.pid

stop:
kill ${PID}
install-systemd-unit:
sudo cp ./misc/gamma-box.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable gamma-box.service
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ black = "*"
gunicorn = ">=19.4.1"
eventlet = ">=0.17.4"
twython = "==3.3.0"
PiPocketGeiger = ">=0.3"
PiPocketGeiger = ">=0.5.0"
Flask = ">=0.10.1"
Flask-SocketIO = ">=1.2"
SafecastPy = "==0.1.0"
922 changes: 371 additions & 551 deletions Pipfile.lock

Large diffs are not rendered by default.

60 changes: 35 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -18,21 +18,50 @@ Technically Gamma Box is a box currently composed of a [Raspberry Pi](https://ww

## Shopping list

TODO
The Pocket Geiger is not sold anymore by Radiation Watch, neither by [Sparkfun](https://www.sparkfun.com/products/retired/14209). There remains some units to be sold by [RoboDyne](https://www.robo-dyne.com/prodotto/pocket-geiger-radiation-sensor-type-5/?lang=it) and [Hellas Digital](https://www.hellasdigital.gr/electronics/sensors/radiation/pocket-geiger-radiation-sensor-type-5/?sl=en).

## Assembling and Wiring

See [PiPocketGeiger](https://github.com/MonsieurV/PiPocketGeiger) instructions for wiring your Raspberry Pi to your Radiation Watch Pocket Geiger.

## Installating the Gamma Box application

TODO pip package for gammabox?
First install the GPIO library and its dependencies.
Follow [PiPocketGeiger](https://github.com/MonsieurV/PiPocketGeiger) instructions.

We'll also use pipenv:

```sh
pip install pipenv --user --break-system-packages
```

(Follow the instructions to add pipenv to PATH)

Install the repository dependencies (mainly `PiPocketGeiger`):

```sh
pipenv install
```

You can try launching the server with

```sh
# Ensure RPi.GPIO library is installed.
# Instruction here for Raspbian. See https://sourceforge.net/p/raspberry-gpio-python/wiki/install/
sudo apt-get install python3-rpi.gpio
sudo pip3 install PiPocketGeiger
make run
```

This launch the web server on port `9898`.
You can access it (replacing your RPi host):

http://raspberrypi:9898

### Systemd installation

Follow the template in `misc/gamma-box.service` (modify `WorkingDirectory` and `User` following your installation). You can then install and activate the service to runs as a daemon:

```sh
sudo cp ./misc/gamma-box.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable gamma-box.service
```

-------
@@ -53,25 +82,6 @@ It may support other sensors by creating appropriate drivers. Contributions are

[Ask gently](https://github.com/MonsieurV/GammaBox/issues) to get help for making it work. :-)

-------

## TODO

* Create systemd service file + doc to install and enable
* Migrate backend to Go
* Go install on RPi
* https://gist.github.com/simoncos/49463a8b781d63b5fb8a3b666e566bb5
* https://www.e-tinkers.com/2019/06/better-way-to-install-golang-go-on-raspberry-pi/
* create a WiringPi based driver (in C/C++)
* https://github.com/alexellis/rpi/
* Website
** GitHub Pages and/or https://gammabox.ytotech.com
* Cloud relay for Gamma Box
* allows to acces to readings from everywhere
* create simple owner app with React-Native
* simple sensor page to be shared
* transmitting settings
* community readings aggregation and open-access to data flux

-------

21 changes: 20 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
TODO:
## Code

* Create systemd service file + doc to install and enable
* Migrate backend to Go
* Go install on RPi
* https://gist.github.com/simoncos/49463a8b781d63b5fb8a3b666e566bb5
* https://www.e-tinkers.com/2019/06/better-way-to-install-golang-go-on-raspberry-pi/
* create a WiringPi based driver (in C/C++)
* https://github.com/alexellis/rpi/
* Website
** GitHub Pages and/or https://gammabox.ytotech.com
* Cloud relay for Gamma Box
* allows to acces to readings from everywhere
* create simple owner app with React-Native
* simple sensor page to be shared
* transmitting settings
* community readings aggregation and open-access to data flux

## Publicize

* Write a blog article
* Design a nice logo, neutral and non-offensive, even positive (cartoon-like)
* Create landing page for the project
3 changes: 2 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Launch the Gamma Box.
"""

import sys
import logging
import logging.handlers
@@ -21,4 +22,4 @@
if "-d" in sys.argv or "--debug" in sys.argv:
socketio.debug = True
# TODO Make it configurable.
socketio.run(app, port=8080, host="0.0.0.0")
socketio.run(app, port=9898, host="0.0.0.0")
15 changes: 14 additions & 1 deletion gammabox/forward.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@
import datetime
import logging
import threading
from .forwarders import twitter, safecast, plotlyf, radmon, gammaapi, zapier

# from .forwarders import twitter, safecast, plotlyf, radmon, gammaapi, zapier


def run_forwarder(forwader, configuration, readings):
@@ -56,14 +57,26 @@ def do_dispatch(self, readings, period_elapsed):
# Naive dispatching.
if period_elapsed:
if self.configuration["twitter"]["enabled"]:
from .forwarders import twitter

run_forwarder(twitter.forward, self.configuration, readings)
if self.configuration["safecast"]["enabled"]:
from .forwarders import safecast

run_forwarder(safecast.forward, self.configuration, readings)
if self.configuration["radmon"]["enabled"]:
from .forwarders import radmon

run_forwarder(radmon.forward, self.configuration, readings)
if self.configuration["plotly"]["enabled"]:
from .forwarders import plotlyf

run_forwarder(plotlyf.forward, self.configuration, readings)
if self.configuration["gammaapi"]["enabled"]:
from .forwarders import gammaapi

run_forwarder(gammaapi.forward, self.configuration, readings)
if self.configuration["zapier"]["enabled"]:
from .forwarders import zapier

run_forwarder(zapier.forward, self.configuration, readings)
2 changes: 2 additions & 0 deletions gammabox/static/js/jquery-3.7.1.slim.min.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions gammabox/static/js/jquery.min.js

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions gammabox/static/js/socket.io.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions gammabox/stream.py
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
service (to broadcast them). That way the reading part will
be less sensitive to issues from the backend or frontend processes.
"""

try:
import queue
except ImportError:
@@ -41,12 +42,11 @@ def on_connect():
"uSvh": history[-1]["uSvh"],
"uSvhError": history[-1]["uSvhError"],
},
json=True,
)
else:
emit("readings", {"cpm": None, "uSvh": None, "uSvhError": None}, json=True)
emit("readings", {"cpm": None, "uSvh": None, "uSvhError": None})
# Send historical data.
emit("history", history, json=True)
emit("history", history)


def on_radiation():
@@ -65,7 +65,7 @@ def listen_to_queue():
readings = radiation_watch.status()
readings["timestamp"] = datetime.datetime.now().isoformat() + "Z"
# Send current readings.
socketio.emit("readings", readings, json=True)
socketio.emit("readings", readings)
# Persist historical data.
history.append(readings)
while len(history) > HISTORY_LENGTH:
@@ -78,5 +78,5 @@ def listen_to_queue():

eventlet.spawn_n(listen_to_queue)
radiation_watch.register_radiation_callback(on_radiation)
# TODO Also register noise an **dring** when noise present.
# TODO Also register noise and **dring** when noise present.
# (Show a message + some recommendation for noise prevention)
9 changes: 6 additions & 3 deletions gammabox/web_portal.py
Original file line number Diff line number Diff line change
@@ -29,13 +29,16 @@ def settings():

@app.route("/api/settings", methods=["GET"])
def api_settings_get():
with open(RADBOX_SETTINGS_FILE, "rb") as file:
return jsonify(json.load(file))
try:
with open(RADBOX_SETTINGS_FILE, "rb") as file:
return jsonify(json.load(file))
except Exception as exc:
return "", 404


@app.route("/api/settings", methods=["POST"])
def api_settings_post():
with open(RADBOX_SETTINGS_FILE, "wb") as file:
with open(RADBOX_SETTINGS_FILE, "w", encoding="utf8") as file:
json.dump(request.get_json(), file)
# TODO Use message passing.
forwarder.reload_configuration()
18 changes: 18 additions & 0 deletions misc/gamma-box.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=Gamma Box
After=network.target

[Service]
ExecStart=pipenv run gunicorn -k eventlet -w 1 --bind 0.0.0.0:9898 app:app
WorkingDirectory=/home/canard/git/GammaBox
# For old boards, force revision code
# See https://rpi-lgpio.readthedocs.io/en/latest/differences.html#pi-revision
# https://github.com/raspberrypi/documentation/issues/1888
# Environment="RPI_LGPIO_REVISION=900032"
Restart=always
RestartSec=30s
User=canard
Type=simple

[Install]
WantedBy=multi-user.target

0 comments on commit 26ac032

Please sign in to comment.