Crate fundamentum_edge_daemon

Crate fundamentum_edge_daemon 

Source
Expand description

The supported way to access Fundamentum’s ecosystem from linux devices.

§Usage

§Launching the daemon

$ cargo run
# ..
  • The gRPC server will bind to 127.0.0.1:8080.

  • A default version of the configuration file (config.toml) will be created in the current working directory if it does not already exists.

  • The current working directory will be used as the state directory. Here’s a list of state files you might encounter:

    • provisioning.json and rsa_(public|private).pem will be created upon first successful provisioning.

You can override these defaults using the available CLI options. Those can be listed as follow:

$ cargo run -- --help
# ..

Further customizations are also possible through the configuration file (config.toml).

§Accessing exposed services via the gRPC interface

The various Fundamentum services are made available through a gRPC interface (see fundamentum-edge-proto repository).

In order to be able to use most of the gRPC services (the most notable exception being the Provisioning service), your device will need to be provisioned. In order to do so, a good place to start would be the provisioning procedure.

§Through the CLI

It is possible to use the grpcurl CLI tool to interact with the daemon.

Note: All of the example commands below assume a TCP network socket transport. If your Edge Daemon uses a Unix Domain Socket (UDS) instead, see Using grpcurl over a Unix Domain Socket (UDS) for instructions on adapting these commands to your use case.

  • To provision the device:

    $ grpcurl \
        -plaintext \
        -d '{
            "api_base_url": "https://devices.fundamentum-iot.com",
            "project_id": 1,
            "region_id": 2,
            "registry_id": 3,
            "serial_number": "device1",
            "asset_type_id": 4,
            "access_token": "TOKEN"
        }' \
        127.0.0.1:8080 \
        com.fundamentum.edge.v1.Provisioning.Provision
    # ...
  • To publish telemetry data:

    $ grpcurl \
        -plaintext \
        -d '{
            "sub_topic": "test",
            "qos": 0,
            "payload": "SGVsbG8sIFdvcmxkIQ=="
        }' \
        127.0.0.1:8080 \
        com.fundamentum.edge.v1.Telemetry.Publish
    # ...
  • To get the device configuration:

    $ grpcurl \
        -plaintext \
        127.0.0.1:8080 \
        com.fundamentum.edge.v1.Configuration.Get
    # ...
  • To subscribe to configuration updates:

    $ grpcurl \
        -plaintext \
        127.0.0.1:8080 \
        com.fundamentum.edge.v1.Configuration.UpdateStream
    # ...
  • To publish states data:

    $ grpcurl \
        -plaintext \
        -d '{
            "states": {
                "status": "ok",
                "alarms": [
                    "alarm1",
                    "alarm2"
                ]
            },
            "sub_devices": [
                {
                    "serial_number": "device1",
                    "states": {
                        "rssi": 50,
                        "battery_level": 75,
                        "temperature": 25
                    }
                }
            ]
        }' \
        127.0.0.1:8080 \
        com.fundamentum.edge.v1.StatesEvent.PublishJson
    # ...
  • To subscribe to incoming actions:

    $ grpcurl \
        -plaintext \
        127.0.0.1:8080 \
        com.fundamentum.edge.v1.Actions.Subscribe
    # ...
  • To update the status of an action:

    $ grpcurl \
        -plaintext \
        -d '{
            "id": 123,
            "serial_numbers": ["device1", "device2"],
            "ongoing": {"progress": 50},
            "message": "In progress...",
            "payload": "SGVsbG8sIFdvcmxkIQ=="
        }' \
        127.0.0.1:8080 \
        com.fundamentum.edge.v1.Actions.UpdateStatus
    # ...
  • To subscribe to firmware update requests:

    $ grpcurl \
        -plaintext \
        127.0.0.1:8080 \
        com.fundamentum.edge.v1.FirmwareUpdate.Subscribe
    # ...
  • To update the status of an firmware update:

    $ grpcurl \
        -plaintext \
        -d '{
            "id": 123,
            "serial_numbers": ["device1", "device2"],
            "ongoing": {"progress": 50},
            "message": "Update in progress...",
        }' \
        127.0.0.1:8080 \
        com.fundamentum.edge.v1.FirmwareUpdate.UpdateStatus
    # ...

§Through language specific bindings

For more serious use cases, we provide specific support for the following languages:

Please make sure that you use a binding library version compatible with your edge daemon service.

Note that in case your language is not already officially supported, it is still possible to use the protocol buffer compiler on the gRPC *.proto files to generate a bindings library for almost any language.

§Crate Feature Flags

This crate provides the following feature flags and optional dependencies:

  • tracing — Enables application tracing for integration with tokio-console. This includes the console-subscriber crate and activates the “tracing” feature for the “tokio” crate.

    Note: To use tokio-console, the tokio_unstable cfg flag, which enables experimental APIs in Tokio, must be enabled. It can be enabled by setting the RUSTFLAGS environment variable at build-time:

    $ RUSTFLAGS="--cfg tokio_unstable" cargo build

    or, by adding the following to the .cargo/config.toml file in a Cargo workspace:

    [build]
    rustflags = ["--cfg", "tokio_unstable"]

Modules§

grpc
This application’s gRPC related stuff.
state
Provisioning state.
utils
Utils

Structs§

AppConfig
Core configuration structure
AppCore
Core structure

Enums§

AppCoreError
Error generated by the super::AppCore