Code Monkey home page Code Monkey logo

dart_thingsboard_client's Introduction

ThingsBoard API client library for Dart developers. Provides model objects and services to communicate with ThingsBoard platform using RESTful APIs and WebSocket protocol. Current client version is compatible with ThingsBoard starting from version 3.6.3.

Usage

A simple usage example:

import 'package:thingsboard_client/thingsboard_client.dart';

main() async {
    try {
      var tbClient = ThingsboardClient('https://demo.thingsboard.io');
      await tbClient.login(LoginRequest('[email protected]', 'tenant'));

      print('isAuthenticated=${tbClient.isAuthenticated()}');

      print('authUser: ${tbClient.getAuthUser()}');

      var currentUserDetails = await tbClient.getUserService().getUser();
      print('currentUserDetails: $currentUserDetails');

      await tbClient.logout();

    } catch (e, s) {
        print('Error: $e');
        print('Stack: $s');
    }
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

dart_thingsboard_client's People

Contributors

ashvayka avatar ikulikov avatar vvlladd28 avatar ybeshkarov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dart_thingsboard_client's Issues

Runtime issues on SDK 30

I can't figure out why, but the app's dashboards don't work properly when I install the APK on androids with SDK less than 33.

When I run it on an android with SDK 33 it works correctly, but on android SDK 30 it doesn't work...

The figure below shows execution on an SDK 33 device (no problems) and alongside the execution on SDK 30 (the dashboard did not load)

example

[Issue] Method "getAttributeKeys" not working

Hello, i'm using the library version 1.0.8, fetching data from a account in https://thingsboard.cloud/.

I trying to fetch my device attributes using the following code:

var attrs = await tbClient
        .getAttributeService()
        .getAttributeKeys(DeviceId('4d1d43f0-a977-11ee-80a4-b9287a012345'));

Unfortunately it is not working and returning the following exception:

Error: ThingsboardError: message: [type 'List<dynamic>' is not a subtype of type 'List<String>?' in type cast], errorCode: 2, status: null
#0      toThingsboardError (package:thingsboard_pe_client/src/error/_thingsboard_error_handler_io.dart:89:18)
#1      ThingsboardClient.get (package:thingsboard_pe_client/src/thingsboard_client_base.dart:257:13)
<asynchronous suspension>
#2      AttributeService.getAttributeKeys (package:thingsboard_pe_client/src/service/attribute_service.dart:18:20)
<asynchronous suspension>
#3      main (file:///C:/Users/fbioa/Desktop/Personal%20Dev/Flutter_Estudos/thingsboard_client_tests/bin/thingsboard_client_tests.dart:56:9)
<asynchronous suspension>

I tested another method, the getLatestTimeseries, which receives the same EntityId as the first argument, to confirm if the problem was in there, but this method worked, therefore the arguments of the first method is correct. Here is the second method test:

var telemetry = await tbClient.getAttributeService().getLatestTimeseries(
        DeviceId('4d1d43f0-a977-11ee-80a4-b9287a012345'), ['temperature']);

Any clues for solving the first method problem?

Problem occurred when using web socket and loosing internet

When listening telemetries and attributes update via the WebSocket. If we loose internet, the following exception happens and can't be managed:

#0      _NativeSocket.startConnect (dart:io-patch/socket_patch.dart:719:35)
#1      _RawSocket.startConnect (dart:io-patch/socket_patch.dart:1877:26)
#2      RawSocket.startConnect (dart:io-patch/socket_patch.dart:27:23)
#3      RawSecureSocket.startConnect (dart:io/secure_socket.dart:297:22)
#4      SecureSocket.startConnect (dart:io/secure_socket.dart:77:28)
#5      _ConnectionTarget.connect (dart:_http/http_impl.dart:2482:26)
#6      _HttpClient._getConnection.connect (dart:_http/http_impl.dart:2924:12)
#7      _HttpClient._getConnection (dart:_http/http_impl.dart:2929:12)
#8      _HttpClient._openUrl (dart:_http/http_impl.dart:2784:12)
#9      _HttpClient.openUrl (dart:_http/http_impl.dart:2622:7)
#10     _WebSocketImpl.connect (dart:_http/websocket_impl.dart:1021:42)
#11     WebSocket.connect (dart:_http/websocket.dart:320:22)
#12     new IOWebSocketChannel.connect (package:web_socket_channel/io.dart:81:28)
#13     connect (package:web_socket_channel/src/_connect_io.dart:15:24)
#14     new WebSocketChannel.connect (package:web_socket_channel/src/channel.dart:115:16)
#15     TelemetryWebsocketService._openSocket (package:thingsboard_client/src/service/telemetry_websocket_service.dart:204:38)
#16     TelemetryWebsocketService._tryOpenSocket (package:thingsboard_client/src/service/telemetry_websocket_service.dart:184:11)
#17     TelemetryWebsocketService._onClose.<anonymous closure> (package:thingsboard_client/src/service/telemetry_websocket_service.dart:292:61)
#18     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
#19     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
#20     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
#21     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)

The problem seems to come from the lib you use: WebSocketChannel, as you can see here: dart-lang/web_socket_channel#268

The solution suggested is the following one: flutter/website#8765 (comment)

Getting json attributes

Using getAttributesByScope or getAttributeKvEntries on a json attribute crashes with exception:

"type 'List<dynamic>' is not a subtype of type 'String'"

The stack trace is:

#0      RestJsonConverter._parseValue (package:thingsboard_client/src/model/telemetry_models.dart:359:42)
#1      RestJsonConverter.toAttributes.<anonymous closure> (package:thingsboard_client/src/model/telemetry_models.dart:325:21)
#2      MappedListIterable.elementAt (dart:_internal/iterable.dart:415:31)
#3      ListIterator.moveNext (dart:_internal/iterable.dart:344:26)
#4      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
#5      new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#6      new List.of (dart:core-patch/array_patch.dart:47:28)
#7      ListIterable.toList (dart:_internal/iterable.dart:214:7)
#8      RestJsonConverter.toAttributes (package:thingsboard_client/src/model/telemetry_models.dart:327:10)
#9      AttributeService.getAttributesByScope (package:thingsboard_client/src/service/attribute_service.dart:49:30)
<asynchronous suspension>
...

[BUG] AlarmDataCmd incorrect behaviour over TelemetrySubscriber (websockets)

I have Flutter web application. We are paying customer and I tried both PE and community version of dart client - we have this problem since version 1.0.2 till the latest.

There is one subscription to get latest device data and another to get latest alarm data.
The problems are:

  1. AlarmDataCmd kills the other EntityDataQuery (as then the other does not receive any response).
  2. AlarmDataCmd behaves incorrectly, as it creates a new websocket every 1 second or so, instead of communicating over the same open websocket (like EntityDataQuery does) - as you can see here in Developer Console:
    image

So if there is no AlarmDataQuery - then everything works fine.

sample code that I am using:

var alarmFields = <EntityKey>[ EntityKey(type: EntityKeyType.ALARM_FIELD, key: "createdTime"), EntityKey(type: EntityKeyType.ALARM_FIELD, key: "type"), EntityKey(type: EntityKeyType.ALARM_FIELD, key: "severity"), EntityKey(type: EntityKeyType.ALARM_FIELD, key: "status"), ]; var alarmQuery = AlarmDataQuery( entityFilter: DeviceTypeFilter(deviceType: "v4"), alarmFields: alarmFields, pageLink: AlarmDataPageLink( pageSize: 1000, searchPropagatedAlarms: true, timeWindow: 604800000, sortOrder: EntityDataSortOrder(key: EntityKey(type: EntityKeyType.ALARM_FIELD, key: "createdTime"), direction: EntityDataSortOrderDirection.DESC))); subscription = TelemetrySubscriber(client.getTelemetryService(), [AlarmDataCmd(cmdId: 101, query: alarmQuery)]); subscription!.alarmDataStream.listen(onData, onError: onError, onDone: onDone, cancelOnError: true); subscription!.subscribe();

Error: type 'Null' is not a subtype of type 'String' when calling getEntityRelationService().findInfoByQuery

Environment

  • ThingsBoard: 3.6.2
  • Dart API: 1.0.8

Description
Got exception when tried to call getEntityRelationService().findInfoByQuery, the root cause is that 'fromName' of response is null, the same query can be executed fine with REST API.

    RelationsSearchParameters parameters = RelationsSearchParameters(rootId: 'bcbca450-c1a8-11ee-9f93-492ffd078c6c', rootType: EntityType.ASSET);
    RelationEntityTypeFilter filter = RelationEntityTypeFilter('Contains', [EntityType.DEVICE]);
    EntityRelationsQuery query = EntityRelationsQuery(parameters: parameters, filters: [filter]);
    List<EntityRelation> relations = await relationService.findInfoByQuery(query);
D:/flutter/bin/cache/dart-sdk/bin/dart.exe --enable-asserts D:\src\dart_test\bin\dart_test.dart
Error: type 'Null' is not a subtype of type 'String'
Stack: #0      new EntityRelationInfo.fromJson (package:thingsboard_client/src/model/relation_models.dart:183:18)
#1      EntityRelationService.findInfoByQuery.<anonymous closure> (package:thingsboard_client/src/service/entity_relation_service.dart:157:57)
#2      MappedListIterable.elementAt (dart:_internal/iterable.dart:425:31)
#3      ListIterator.moveNext (dart:_internal/iterable.dart:354:26)
#4      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
#5      new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#6      new List.of (dart:core-patch/array_patch.dart:39:18)
#7      ListIterable.toList (dart:_internal/iterable.dart:224:7)
#8      EntityRelationService.findInfoByQuery (package:thingsboard_client/src/service/entity_relation_service.dart:157:70)
<asynchronous suspension>
#9      main (file:///D:/src/dart_test/bin/dart_test.dart:13:38)
<asynchronous suspension>

image

Changed API END POINT

Once Thingboard is initialization after that how can we reinitilization or changes the API end point

Subscripe to RPC Commands from Server

Hello,

I cannot find anywhere in the client how I would subscribe to RPC commands sent from a Control Widget on the server to the client. Do you have an example of how this would be done?

Failed to send message via FCM: SenderId mismatch

hello everyone.
I am trying to send a notification from ThingsBoard to my custom Flutter app. I Generated a project in FireBase and I set the key of ThingsBoard like the following link:
https://thingsboard.io/docs/pe/mobile/getting-started/
I use thingsboard_client: ^1.1.1 in my custom Flutter app, and I set FireBase in my app according to the following link:
https://firebase.google.com/docs/flutter/setup?hl=en&authuser=0&platform=android
Now, I can receive notifications from the FireBase console, But not ThingsBoard!
when I send a notification from thingsBoard, I get "Failed to send message via FCM: SenderId mismatch" error.
2

Please, let me know, how I can fix this problem.

I am using thingsboard 3.6.3, and flutter 3.19.4.

Creating Customer User with Dart API

Dear official; Since the library has just been published and there are not many examples and documentation, I cannot create a customer user, but I create and activate a tenant admin user. How can I do this with Dart?

Error Note: Unhandled Exception: ThingsboardError: message: [Customer user should be assigned to customer!],

Error by adding user to user group

Hi,

Situation
I tried to change the user group of new created user from all to customer administators. Therefore I used the following code snippet:

List<String> userList = [];
userList.add("aaaaaaaaaaaaa-11ec-bbbb-c14a5834e2da");
userList.add("bbbbbbbbbbb-11ec-aaaa-c14a5812e1da");
      await _tbClient
          .getEntityGroupService()
          .addEntitiesToEntityGroup(
              "43aaaa80-c9b5-1111-9aa8-0baaaaa0a69b", userList)
          .then((value) => print("done"))
          .catchError((onError) => print("in addUserToGroup(): $onError"));

Problem
The code throws an error during the execution, although the users being added to the group. How can I prevent this error?

Exception has occurred. ThingsboardError (ThingsboardError: message: [type 'String' is not a subtype of type 'Map<String, dynamic>?' in type cast], errorCode: 2, status: null #0 toThingsboardError (package:thingsboard_pe_client/src/error/_thingsboard_error_handler_io.dart:86:18) #1 ThingsboardClient.post (package:thingsboard_pe_client/src/thingsboard_client_base.dart:227:13) <asynchronous suspension> ....

Thingsboardversion PE 3.3.3
Flutterversion 2.10.5
thingsboard_pe_client: ^1.0.3

[BUG] Notifications web socket

Using the latest version of thingsboard 3.6.1 and version 1.0.7 of dart client
trying to get notifications with a code from examples:
var notificationService = client.getNotificationWebsocketService(); var subscription = NotificationSubscriber.createNotificationsSubscription(notificationService: notificationService, limit: 100); subscription.notificationStream.listen(onData, onError: onError, onDone: onDone, cancelOnError: true); subscription.subscribe();
first data retrieval was successful, but further notifications getting this error:

Error: Expected a value of type 'Iterable', but got one of type 'WhereIterable'

dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:3 throw
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 127:3 castError
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 818:12 cast
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/classes.dart 652:14 as_C
packages/thingsboard_client/src/model/notification_models.dart 373:58 _onNotificationData
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5 _async
packages/thingsboard_client/src/model/notification_models.dart 365:35 [_onNotificationData]
packages/thingsboard_client/src/model/notification_models.dart 355:7 onCmdUpdate
packages/thingsboard_client/src/service/notification_websocket_service.dart 219:23 _onMessage
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50
dart-sdk/lib/async/zone.dart 1661:54 runUnary
dart-sdk/lib/async/future_impl.dart 162:18 handleValue
dart-sdk/lib/async/future_impl.dart 846:44 handleValueCallback
dart-sdk/lib/async/future_impl.dart 875:13 _propagateToListeners
dart-sdk/lib/async/future_impl.dart 647:5 [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 721:7 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.