c8y_client 0.0.4

Dart native js
Flutter Android iOS web

Dart client for Cumulocity IoT Platfom. Based on http://resources.cumulocity.com/documentation/javasdk/current/ and http://resources.cumulocity.com/documentation/websdk/client/

A library for Dart developers.

Created from templates made available by Stagehand under a Apache License Version 2.0 license.

Usage #

import 'package:c8yClient/src/core/model/id.dart';

A simple usage example: Get all devices with Position as Streaming

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';
import 'package:c8y_client/src/core/model/device_capabilities/c8y_position.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
    var inventoryApi = client.inventory();
    var iterator = await inventoryApi.stream({'fragmentType': 'c8y_Position'});
      while (await iterator.moveNext()) {
        var position = C8YPosition.fromJson(
            iterator.current.fragments['c8y_Position'] as Map<String, Object>);
        print(position.lat);
      }
  }
  catch (error) {
    print("error : " + error.toString());
  }
}

Get list of all devices with Position:

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
    var inventoryApi = client.inventory();
    var devices = await inventoryApi.listAll({'fragmentType': 'c8y_Position'});
    print('total devices : ' + devices.length.toString());
  }
  catch (error) {
    print("error : " + error.toString());
  }

}

Get list of devices with limit (40):

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
    var inventoryApi = client.inventory();
    var devices = await inventoryApi.listByLimit({'fragmentType': 'c8y_Position'}, 40);
    print('total devices : ' + devices.length.toString());
  }
  catch (error) {
    print("error : " + error.toString());
  }
}

A simple usage example: Get device by ID and a get dynamic property

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
     var inventoryApi = client.inventory();
     var mo = await inventoryApi.get(ID('10407719'));
    print(mo.name);
    print(mo.fragment['Numero_de_Satelites']);
  }
  catch (error) {
    print("error : " + error.toString());
  }
}

A simple usage example: Get all alarms as Streaming

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
      var alarmApi = client.alarm();
      var alarmsIterator = await alarmApi.stream({});
      while (await alarmsIterator.moveNext()) {
        print(alarmsIterator.current.text);
      }
  }
  catch (error) {
    print("error : " + error.toString());
  }
}

Get list of all alarms:

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
      var alarms = await alarmApi.listAll({});
      print('total alarms listall : ' + alarms.length.toString());
  }
  catch (error) {
    print("error : " + error.toString());
  }

}

Get list of alarms with limit (40):

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
      var alarmApi = client.alarm();
     var alarmsByLimit = await alarmApi.listByLimit({}, 40);
     print('total alarms list with limit : ' + alarmsByLimit.length.toString());
  }
  catch (error) {
    print("error : " + error.toString());
  }
}

A simple usage example: Get current user

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
    var currentUser = await client.user().currentUser();
    print(currentUser.userName);
  }
  catch (error) {
    print("error : " + error.toString());
  }
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

3
likes
80
pub points
28%
popularity

Dart client for Cumulocity IoT Platfom. Based on http://resources.cumulocity.com/documentation/javasdk/current/ and http://resources.cumulocity.com/documentation/websdk/client/

Homepage

Documentation

API reference

Uploader

jorgeh@bismark.net.co

License

Apache 2.0 (LICENSE.txt)

Dependencies

http, http_parser, json_annotation, logger

More

Packages that depend on c8y_client