fundamentum_edge_daemon/lib.rs
1//! The supported way to access Fundamentum's ecosystem from linux devices.
2//!
3//! # Usage
4//!
5//! ## Launching the daemon
6//!
7//! ```sh
8//! $ cargo run
9//! # ..
10//! ```
11//!
12//! - The *gRPC server* will bind to `127.0.0.1:8080`.
13//! - A default version of the *configuration file* (`config.toml`) will be
14//! created in the *current working directory* if it does not already exists.
15//! - The *current working directory* will be used as the *state directory*.
16//! Here's a list of state files you might encounter:
17//!
18//! - `provisioning.json` and `rsa_(public|private).pem` will be created
19//! upon first successful provisioning.
20//!
21//!
22//! You can override these defaults using the available CLI options. Those can
23//! be listed as follow:
24//!
25//! ```sh
26//! $ cargo run -- --help
27//! # ..
28//! ```
29//!
30//! Further customizations are also possible through the *configuration file*
31//! (`config.toml`).
32//!
33//! ## Accessing exposed services via the gRPC interface
34//!
35//! The various Fundamentum services are made available through a *gRPC
36//! interface* (see [`fundamentum-edge-proto` repository][proto-repo]).
37//!
38//! In order to be able to use most of the gRPC services (the most notable
39//! exception being the `Provisioning` service), your device will need to be
40//! *provisioned*. In order to do so, a good place to start would be the
41//! [provisioning procedure][prov-proc].
42//!
43//! [proto-repo]: https://bitbucket.org/amotus/fundamentum-edge-proto
44//! [prov-proc]: ./doc/provisioning-procedure.md
45//!
46//! ### Through the CLI
47//!
48//! It is possible to use the [`grpcurl`][grpcurl] CLI tool to interact with the
49//! daemon.
50//!
51//! > **Note**: All of the example commands below assume a TCP [*network
52//! > socket*][net-sock] transport. If your Edge Daemon uses a [*Unix Domain
53//! > Socket* (UDS)][uds] instead, see [Using `grpcurl` over a *Unix Domain
54//! > Socket* (UDS)][grpcurl-over-uds] for instructions on adapting these commands
55//! > to your use case.
56//!
57//! - To provision the device:
58//!
59//! ```sh
60//! $ grpcurl \
61//! -plaintext \
62//! -d '{
63//! "api_base_url": "https://devices.fundamentum-iot.com",
64//! "project_id": 1,
65//! "region_id": 2,
66//! "registry_id": 3,
67//! "serial_number": "device1",
68//! "asset_type_id": 4,
69//! "access_token": "TOKEN"
70//! }' \
71//! 127.0.0.1:8080 \
72//! com.fundamentum.edge.v1.Provisioning.Provision
73//! # ...
74//! ```
75//!
76//! - To publish telemetry data:
77//!
78//! ```sh
79//! $ grpcurl \
80//! -plaintext \
81//! -d '{
82//! "sub_topic": "test",
83//! "qos": 0,
84//! "payload": "SGVsbG8sIFdvcmxkIQ=="
85//! }' \
86//! 127.0.0.1:8080 \
87//! com.fundamentum.edge.v1.Telemetry.Publish
88//! # ...
89//! ```
90//!
91//! - To get the device configuration:
92//!
93//! ```sh
94//! $ grpcurl \
95//! -plaintext \
96//! 127.0.0.1:8080 \
97//! com.fundamentum.edge.v1.Configuration.Get
98//! # ...
99//! ```
100//!
101//! - To subscribe to configuration updates:
102//!
103//! ```sh
104//! $ grpcurl \
105//! -plaintext \
106//! 127.0.0.1:8080 \
107//! com.fundamentum.edge.v1.Configuration.UpdateStream
108//! # ...
109//! ```
110//!
111//! - To publish states data:
112//!
113//! ```sh
114//! $ grpcurl \
115//! -plaintext \
116//! -d '{
117//! "states": {
118//! "status": "ok",
119//! "alarms": [
120//! "alarm1",
121//! "alarm2"
122//! ]
123//! },
124//! "sub_devices": [
125//! {
126//! "serial_number": "device1",
127//! "states": {
128//! "rssi": 50,
129//! "battery_level": 75,
130//! "temperature": 25
131//! }
132//! }
133//! ]
134//! }' \
135//! 127.0.0.1:8080 \
136//! com.fundamentum.edge.v1.StatesEvent.PublishJson
137//! # ...
138//! ```
139//!
140//! - To subscribe to incoming actions:
141//!
142//! ```sh
143//! $ grpcurl \
144//! -plaintext \
145//! 127.0.0.1:8080 \
146//! com.fundamentum.edge.v1.Actions.Subscribe
147//! # ...
148//! ```
149//!
150//! - To update the status of an action:
151//!
152//! ```sh
153//! $ grpcurl \
154//! -plaintext \
155//! -d '{
156//! "id": 123,
157//! "serial_numbers": ["device1", "device2"],
158//! "ongoing": {"progress": 50},
159//! "message": "In progress...",
160//! "payload": "SGVsbG8sIFdvcmxkIQ=="
161//! }' \
162//! 127.0.0.1:8080 \
163//! com.fundamentum.edge.v1.Actions.UpdateStatus
164//! # ...
165//! ```
166//!
167//! - To subscribe to firmware update requests:
168//!
169//! ```sh
170//! $ grpcurl \
171//! -plaintext \
172//! 127.0.0.1:8080 \
173//! com.fundamentum.edge.v1.FirmwareUpdate.Subscribe
174//! # ...
175//! ```
176//!
177//! - To update the status of an firmware update:
178//!
179//! ```sh
180//! $ grpcurl \
181//! -plaintext \
182//! -d '{
183//! "id": 123,
184//! "serial_numbers": ["device1", "device2"],
185//! "ongoing": {"progress": 50},
186//! "message": "Update in progress...",
187//! }' \
188//! 127.0.0.1:8080 \
189//! com.fundamentum.edge.v1.FirmwareUpdate.UpdateStatus
190//! # ...
191//! ```
192//!
193//! [grpcurl]: https://github.com/fullstorydev/grpcurl
194//! [uds]: https://en.wikipedia.org/wiki/Unix_domain_socket
195//! [net-sock]: https://en.wikipedia.org/wiki/Network_socket
196//! [grpcurl-over-uds]:
197//! https://bitbucket.org/amotus/fundamentum-edge-daemon/src/master/doc/grpcurl-over-uds.md
198//!
199//! ### Through language specific bindings
200//!
201//! For more serious use cases, we provide specific support for the following
202//! languages:
203//!
204//! - Rust: [source][proto-rust-repo] / [crates.io][proto-rust-pkg] /
205//! [examples][proto-rust-examples]
206//! - Python: [source][proto-python-repo] / [pypi][proto-python-pkg]
207//!
208//! Please make sure that you use a binding library version compatible with your
209//! edge daemon service.
210//!
211//! Note that in case your language is not already officially supported, it is
212//! still possible to use the [protocol buffer compiler][protoc] on the [*gRPC*
213//! `*.proto` files][proto-repo] to generate a bindings library for *almost any
214//! language*.
215//!
216//! [protoc]: https://grpc.io/docs/protoc-installation
217//! [proto-rust-repo]: https://bitbucket.org/amotus/fundamentum-edge-proto-rust
218//! [proto-rust-pkg]: https://crates.io/crates/fundamentum-edge-proto
219//! [proto-rust-examples]:
220//! https://bitbucket.org/amotus/fundamentum-edge-proto-rust/src/master/examples
221//! [proto-python-repo]:
222//! https://bitbucket.org/amotus/fundamentum-edge-proto-python
223//! [proto-python-pkg]: https://pypi.org/project/fundamentum-edge-proto/
224//!
225#![doc = document_features::document_features!()]
226#![cfg_attr(test, allow(clippy::unwrap_used))]
227
228mod app_core;
229pub use app_core::{AppConfig, AppCore, AppCoreError, state};
230
231mod services;
232pub use services::grpc;
233
234pub mod utils;