lb_state_manager 1.1.3 copy "lb_state_manager: ^1.1.3" to clipboard
lb_state_manager: ^1.1.3 copied to clipboard

Logbot State Manager service to return the state of the devices and device services

Logbot State Manager SDK for Flutter #

This is a package to manage the state of the devices and device services

Requirements #

Dart 2.17 or later

Installation & Usage #

Add the dependencies from pub.dev:

dependencies:
  lb_auth:
  lb_discovery:

lb_auth is always required to make authorized calls to the APIs.

To use the SDK on you application see the example below:

import 'package:lb_auth/lb_auth.dart';
import 'package:lb_state_manager/lb_state_manager.dart';

class Example {
  
  Future<void> run() async {
    /// Initialize Logbot SDK by logging in with Logbot Credentials
    await LogbotAuth.init(LogbotCredentials(
      username: username,
      password: password,
      clientId: clientId,
      clientSecret: clientSecret,
    ));
    /// Starts the Logbot Discovery to search for local devices
    await LogbotDiscovery.startDiscovery();
    /// Starts the background service to retrieve device status every minute
    /// (needed to read device status from cache)
    LogbotStateManager.start();
    /// Now you can use every API included on the SDK
    /// for example:
    List<StateManagerDevice>? response = await LogbotStateManager.status.listDeviceStatuses();
  }
}

Note that the user must be logged in with a Logbot account before using startDiscovery() otherwise it will throw an error. This is because the user can locally connect only to the IoTs that he actually owns.

The Logbot State Managers follows this procedure to evaluate the actual device status:

  1. Retrieves the user devices from the Logbot Platform (is a user is logged in).
  2. Discovers the devices on the local network that are already configured.
  3. For every device, the local and remote connection is tested by pinging the Logbot Setup service running on the IoT.
  4. If the device does not respond on any of the two connection, the device will be marked as OFF.
  5. If the device responds on one or more connections, the device will be marked as available LOCAL or REMOTE (or both).
  6. If the device is available at least with one type of connection, the device services status will be checked.

The following procedure happens if the device is online and available. All the services running in the device will be tested to retrieve their actual status:

  1. Retrieves the services installed in the device with the Logbot Setup supervisor.
  2. If the supervisor fails, the device will have a status of ERROR (should never happen as the Logbot Setup connection was already tested in the previous steps).
  3. If the supervisor responds, the Logbot State Manager checks the status of every service installed.

The status is checked in one of these two ways:

  1. The devices has an health probe (health-check API) available (like LB Setup, LB Writer, LB Firewall):

    1. If the service is healthy, then the status is marked as HEALTHY. The service will be also flagged as ready.
    2. If the service is unhealthy but the supervisor says that the service is RUNNING, then the status is UNHEALTHY.
  2. The devices has no health probe (health-check API) available (like LB Ingestion):

    1. The status given by the supervisor is trusted.
    2. The service is marked as ready only if the status from the supervisor is RUNNING.

Only when a service is flagged as ready we can be absolutely sure that it is safe to call the service as it is running correctly.

Tests #

To run all tests:

flutter test

Documentation for API Endpoints #

All URIs are relative to http://localhost

Class Method HTTP request Description
ConnectionApi deviceConnection GET /connection/{deviceId} Returns the device connection
HealthApi healthFirewall GET /health/firewall Check Logbot Firewall status
HealthApi healthSetup GET /health/setup Check Logbot Setup status
HealthApi healthWriter GET /health/writer Check Logbot Writer status
SetupApi deviceStatus GET /device Briefing about the device status
SetupApi supervisorHealth GET /service/supervisor/health Get Supervisor health
SetupApi supervisorStatus GET /service/supervisor Get Supervisor status
StatusApi getDeviceStatus GET /status/{deviceId} Get the status of a device
StatusApi getMultipleDevicesStatus POST /status List the status of many devices and their services
StatusApi listDeviceStatuses GET /status List all the devices and services status

Documentation For Models #

Author #

Logbot SRL info@logbot.cloud

0
likes
50
points
74
downloads

Publisher

verified publisherlogbot.cloud

Weekly Downloads

Logbot State Manager service to return the state of the devices and device services

Homepage

Documentation

Documentation

License

BSD-3-Clause (license)

Dependencies

collection, http, intl, lb_auth, lb_commons, lb_core, lb_discovery, meta

More

Packages that depend on lb_state_manager