I have configured a RPC Control Widget and a device which receives the command from the RPC Control widget.
Actually, I created an alias for that device, and assigned this alias to the Control Widget.
But if I use another alias that has multiple devices, any command on the Control Widget is delivered to the 1st device only.
Is there anyway to send a command to multiple devices?
As I know, all default RPC widgets are working only with one device. You need to create a custom RPC widget that will send a command to all devices (that are defined in the alias)
Here is a reference:
https://thingsboard.io/docs/user-guide/contribution/widgets-development/#rpc-control-widget
@vparomskiy
Yeah, I created an alias for multiple devices, but the RPC command was sent to the 1st one only...
Here is a referecne implementation. It will send RPC command to all devices defined in the alias:
var requestBody = {
method: 'testMethod',
params: 'someParams'
};
var $scope = self.ctx.$scope;
var deviceService = $scope.$injector.get('deviceService')
var aliasId = self.ctx.defaultSubscription.targetDeviceAliasId;
var aliasInfo = self.ctx.aliasController.getAliasInfo(aliasId);
var deviceIds = [];
for(var i = 0; i<aliasInfo.$$state.value.resolvedEntities.length; i++) {
var deviceId = aliasInfo.$$state.value.resolvedEntities[i].id;
deviceIds.push(deviceId);
deviceService.sendOneWayRpcCommand(deviceId, requestBody).then(
function success(response) {
console.log('ok responce');
},
function fail(rejection) {
console.log('reject responce');
}
);
}
PERFECT!
It works like a charm!
Closing this issue now... :)
@vparomskiy
I am getting a couple of errors in this code. (This has been working well til last week, but suddenly stopped working... )
Error: aliasInfo is undefined
If I use the device_id to a known one(so without getting all device_id of assigned devices), I am getting this error then:
XML Parsing Error: no root element found
Location: https://mytk.ch/api/plugins/rpc/oneway/7b93a780-e18e-11e8-90a1-27e75d0d674e
Line Number 1, Column 1:
Any idea?
NOTE: TB server is hosted on https://mytk.ch
@openedhardware does this issue still valid for you?
(Thingsboard Community edition, 2.3.0 on AWS EC2 deployed automatically via Doc's link)
most of things working flawlessly
But i think i'm having kind of similar issue but there is important detail:
This part is working:
This part is not working:
"Failed to load resource: the server responded with a status of 403 () /api/plugins/rpc/oneway/
If i click to the link like my-server/api/plugins/rpc/oneway/165f1d10-400f-11e9-872c-8d390fa314c2
it shows "{"status":401,"message":"Authentication failed","errorCode":10,"timestamp":1551960499467}"
So basically it works in Tenant mode, and not works in User or Public mode
can you please advice how to solve that?
Thanks for great product indeed!
This is known issue and already fixed in master branch. This fix will be
available in upcoming 2.3.1 release.
On Thu, Mar 7, 2019 at 2:09 PM alexmed notifications@github.com wrote:
(Thingsboard Community edition, 2.3.0 on AWS EC2 deployed automatically
via Doc's link)
most of things working flawlesslyBut i think i'm having kind of similar issue but there is important detail:
This part is working:
- If im using dashboard+device logged as Tenant (no matter if
dashboard+device public or not) - everything works ok, particulary Control
Widges like "Switch Control" configured to perform RPC call.This part is not working:
- if I make dashboard+device Public or assign dashboard+device to some
Client/User - the "Switch Control" stops working and Chrome console shows"Failed to load resource: the server responded with a status of 403 ()
/api/plugins/rpc/oneway/"If i click to the link like
my-server/api/plugins/rpc/oneway/165f1d10-400f-11e9-872c-8d390fa314c2
it shows "{"status":401,"message":"Authentication
failed","errorCode":10,"timestamp":1551960499467}"So basically it works in Tenant mode, and not works in User/Public mode
can you please advice how to solve that?
Thanks for great product indeed!
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/thingsboard/thingsboard/issues/1232#issuecomment-470502067,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AH7FZfxOyrjtQ6QIV80ZL7OuWEcrbfrpks5vUQGEgaJpZM4YR4m6
.
thank you, if i look better i could find it in issues list - sorry, now i found lots of this issue mentions
Can you please advice any simple/safe way to upgrade current 2.3.0 to master branch or its better to wait for official 2.3.1 release?
Here is a referecne implementation. It will send RPC command to all devices defined in the alias:
var requestBody = { method: 'testMethod', params: 'someParams' }; var $scope = self.ctx.$scope; var deviceService = $scope.$injector.get('deviceService') var aliasId = self.ctx.defaultSubscription.targetDeviceAliasId; var aliasInfo = self.ctx.aliasController.getAliasInfo(aliasId); var deviceIds = []; for(var i = 0; i<aliasInfo.$$state.value.resolvedEntities.length; i++) { var deviceId = aliasInfo.$$state.value.resolvedEntities[i].id; deviceIds.push(deviceId); deviceService.sendOneWayRpcCommand(deviceId, requestBody).then( function success(response) { console.log('ok responce'); }, function fail(rejection) { console.log('reject responce'); } ); }
Hi,
Can you please explain how to create a widget with this code please ? I am new to ThingsBoard and coding.
Thank you
deviceService.sendOneWayRpcCommand
Hello,
How is possible to know that deviceService has the sendOneWayRpcCommand method?
Hi guys, I'm using the Thingsboard 3.0.1 but unfortunately I got:
Widget Error: NullInjctorError: R3.Injector(e)[deviceService -> deviceService -> deviceService -> deviceService]: NullInjectorError: No provider for deviceService!
On line:
var deviceService = $scope.$injector.get('deviceService');
Have any suggestions guys?
With the snippet mentioned above, i tried to replicate and add a custom action on the control widget.
I have added an action button on the widget to control the group of devices
The alias configured for the widget is a Device Group
var requestBody = {
method: ‘set_light_state’,
params: ‘1’
};
console.log("control widget -> ");
var aliasId = widgetContext.defaultSubscription.targetDeviceAliasId;
console.log("control widget -> "+aliasId);
var aliasInfo = widgetContext.aliasController.getAliasInfo(aliasId);
console.log("AliasInfo"+aliasInfo);
var deviceIds = [];
for(var i = 0; i
console.log(deviceId);
widgetContext.deviceService.sendOneWayRpcCommand(aliasId, requestBody).then(
function success(response) {
console.log('ok responce');
},
function fail(rejection) {
console.log('reject responce');
}
);
I am able to get the aliasInfo but not able to resolve the entities in the group.
Any ideas?
Most helpful comment
Here is a referecne implementation. It will send RPC command to all devices defined in the alias: