Go to file
2024-09-24 15:33:03 +02:00
app add a tiny bit more documentation 2024-09-24 13:00:58 +02:00
display update all dependencies 2024-09-24 09:57:32 +02:00
entity correctly handle updated alerts 2024-05-11 18:37:41 +02:00
migration update all dependencies 2024-09-24 09:57:32 +02:00
.envrc use direnv for nix develop 2024-09-24 08:05:22 +02:00
.gitignore use direnv for nix develop 2024-09-24 08:05:22 +02:00
Cargo.lock initial readme 2024-09-24 15:33:03 +02:00
Cargo.toml update all dependencies 2024-09-24 09:57:32 +02:00
COPYING clarify licenses and add cargo deny 2024-05-20 12:00:39 +02:00
deny.toml clarify licenses and add cargo deny 2024-05-20 12:00:39 +02:00
flake.lock wip 2024-05-08 18:12:49 +02:00
flake.nix update all dependencies 2024-09-24 09:57:32 +02:00
README.md initial readme 2024-09-24 15:33:03 +02:00
rust-toolchain.toml update all dependencies 2024-09-24 09:57:32 +02:00

Alert-Me

Alertswiss is an information hub collecting all relevant information pertaining to precautions and behaviour during disasters and emergencies in Switzerland.

The usual way of getting that information (the alerts) is via a proprietary smartphone app and push notifications. While this works very well and is perfectly fine for most, I think that such data is a nice stepping stone to build upon.

Fortunately, the data is not hidden and easily accessible through a JSON endpoint. In order to prepare this for consumption, the service in app periodically polls the JSON data and persists alerts that changed or have not been seen yet. Additionally it publishes all changes to an MQTT broker where other clients can use that data as they see fit.

An example client is implemented for an nRF52840 microcontroller in display.

Workspace Organization

app

Backend service to poll alerts and publish new ones to an MQTT broker.

display

Microcontroller (nRF52840) application to show basic alert information on an LCD. Because cargo has trouble with different target architectures (see issue 9406) this can not be part of the workspace. Go into the directory to run build commands. There is a separate readme in its project directory.

entity

Entity definitions (tables) for SeaORM. This translates the RDBMS entities to rust structs.

migration

Database migrations that get run at the start of the alert-me app.

Building

The recommended way is to use nix with nix flakes. It still is not for the faint of heart but worth the investment.

Otherwise, rustup and other tools can be installed manually.

Nix

Install nix and enable nix flakes.

Enter the dev environment with nix develop. From there on the usual rust commands work.

To build for different architectures use nix-build .#cross-<architecture> with the desired architecture.

The following architectures are supported so far (different operating systems would be nice but makes it more complicated):

  • x86_64-linux
  • i686-linux
  • aarch64-linux
  • armv6l-linux

The resulting binary (statically linked with musl) is written to result/bin.

Manual Way

Install rustup and an MQTT broker (such as mosquitto). When running rust commands (such as cargo build), rustup should pull in the specified toolchain. However, I can not test this.

Usage

During development the typical way is to run cargo run -p alert-me --, followed by the cli arguments. Nothing changes if instead one runs an already built binary directly (such as result/bin/alert-me) apart from that first part.

Usage: alert-me [OPTIONS] --mqtt-broker <MQTT_BROKER> --mqtt-user <MQTT_USER> --mqtt-password <MQTT_PASSWORD>

Options:
  -i, --interval <INTERVAL>            Update interval in seconds [default: 10]
  -c, --connection <CONNECTION>        Database connection string where timestamps are stored (SQLite, Postgres or MySql) [default: sqlite::memory:]
  -m, --mqtt-broker <MQTT_BROKER>      MQTT broker where alerts get published
  -p, --mqtt-port <MQTT_PORT>          MQTT port [default: 1883]
  -u, --mqtt-user <MQTT_USER>          MQTT user
  -P, --mqtt-password <MQTT_PASSWORD>  MQTT password
  -h, --help                           Print help
  -V, --version                        Print version

MQTT Broker

The alert-me app needs to connect to an MQTT broker to publish alerts. The following is an example of running your own with mosquitto).

Create a file mosquitto.conf with a content of:

A password for publishing is set, so not everyone can just publish alerts. This is not mandatory though.

Run the broker with mosquitto -v -c mosquitto.conf. With mosquitto_sub -v -h localhost -p 1883 -t 'alerts' new alerts will be shown as they arrive.