Skip to content

Latest commit

 

History

History
93 lines (73 loc) · 2.73 KB

cheatsheet.md

File metadata and controls

93 lines (73 loc) · 2.73 KB

Thingsboard Widgets Cheatsheet

Add Data to Timeseries

Swagger UI: https://thingsboard.cloud/swagger-ui.html#!/telemetry-controller/saveEntityTelemetryUsingPOST

Thingsboard Source:

class AttributeService
Method:

  public saveEntityAttributes(entityId: EntityId, attributeScope: AttributeScope, attributes: Array<AttributeData>,
                              config?: RequestConfig): Observable<any>

Example:

var attributeService = self.ctx.attributeService;
var entityId = self.ctx.datasources[0].entityId;
var entity = {
	    entityType: 'DEVICE',
	    id: entityId
	}
attributeService.saveEntityTimeseries(entity, 'CLIENT_SCOPE', [{key: 'BatteryLevel', value: 375}]).subscribe((responseBody) => {
    console.log(responseBody);
}); 

Add Data to Attributes

var attributeService = self.ctx.attributeService;
        var entityId = self.ctx.datasources[0].entityId;
        var entityType = self.ctx.datasources[0].entityType;
        var key = self.ctx.datasources[0].dataKeys[0].name;
        var entity = {
        	    entityType: entityType,     //DEVICE
        	    id: entityId
        	}
    
        	console.log (entityId)
        	var containerType = $('#containerType  option:selected', self.ctx.$container).val()
        	
        attributeService.saveEntityAttributes(entity, 'SERVER_SCOPE', [{key: 'Container type', value: containerType  }]).subscribe((responseBody) => {
            console.log(responseBody);
}); 

Get Attribute Values

    var attributeService = self.ctx.attributeService;
    var entityId = self.ctx.datasources[0].entityId;
    var entityType = self.ctx.datasources[0].entityType;
    var key = self.ctx.datasources[0].dataKeys[0].name;
    var entity = {
    	    entityType: entityType,     //DEVICE
    	    id: entityId
    	}
    	console.log(self.ctx);
    if (self.ctx.datasources[0].type != 'function')
    {
    attributeService.getEntityAttributes(entity, 'SHARED_SCOPE', [key]).subscribe((responseBody) => {
        slider[0].noUiSlider.set( [parseFloat(responseBody[0].value)]);            
    }); 

Scale Widgets (Alternative to Zoom)

<div id="outer" style="transform: scale(1); transform-origin: 0% 0% 0px;">
$('#outer', self.ctx.$container)[0].style.transform =  "scale(" + (self.ctx.width / 190) + ")";

For Latest Telemetry Widget limit Datasource to 1

https://thingsboard.io/docs/user-guide/contribution/widgets-development/#type-parameters-object

self.typeParameters = function() {
    return {
        maxDatasources: 1,
        maxDataKeys: 1,
        singleEntity: true
    };
}