Telemetry being split - thingsboard

My device has its own MQTT format which example follows below.
[{"bn": "086BD7FFFE4AD603", "bt": 1620926752}, {"n": "model", "vs": "nit20z"}, {"n": "2803ddec09000020", "u": "Cel", "v": 1.25}, {"n": "gateway", "vs": "086BD7FFFEB97C60"}]
I managed to write a transformation script that puts it in a proper way, but the Rule Chain splits it the 4 parts and my scripts only works in the message as a whole.
What could be the best way to make the telemetry be processed as a whole in the Rule Chain?
I can not change the device's MQTT format, and don't wanna use an external gateway server.

Related

Krakend: Use previous backend response data to populate post body using lua

I am new to Kraken but quite excited about it. What I am trying to do currently is to have two sequential backends where I would like to use parts of the response from the first backend to populate the body of the second request using Lua. the only issue I am having is to get a hold of the data that I can get via {resp0} if I use it outside the Lua scripts.
This is the part of the krakend.json where I would like to access the previous response:
"extra_config": {
"modifier/lua-backend": {
"sources": [ "/etc/krakend/config/lua/enrichRequestBody.lua" ],
"pre": " populate_request_body(request.load(), {resp0});",
"live": false
}
Any input or suggestions would be much appreciated!
Thanks
I have been trying finding {resp0} or the corresponding value from debugging but no luck. I haven't found any documentation or examples for this in the Kraken documentation

How do I insert data to Astra DB using GraphQL API?

I am trying to follow this youtube tutorial.
I am getting stuck at inserting the first piece of data. Ania demonstrates it at 20.46 as follows:
mutation insertGenres {
action: insertreference_list(value: {label: "genre", value: "action"}) {
value{
value
},
}
When I try this, I get an error that says:
{
"errors": [
{
"message": "Validation error of type FieldUndefined: Field 'insertreference_list' in type 'Mutation' is undefined # 'insertreference_list'",
"locations": [
{
"line": 2,
"column": 3
}
],
"extensions": {
"classification": "ValidationError"
}
}
]
}
When I google the error, a lot of responses tell people to use mutations instead of queries - but I've started from a mutation. I would like to know how to resolve the error, but I'd also like to find the skills to improve my search strategy for finding answers.
When I look at the documentation for using GraphQL with DataStax, I see a different format to the write structure, which is as follows:
insertbook(value: bookInput!, ifNotExists: Boolean, options:
UpdateOptions): bookMutationResult
It has a colon and a fragment of text after it. It also explicitly states the ifNotExists: Boolean and options. I don't know if there may have been a change to how to use DataStax since the time Ania recorded the tutorial that means it is no longer a current demonstration of how to use the tool, or if there is an answer for this and I just haven't found it yet.
You didn't provide details of how you've configured your Astra DB for Ania's Netflix Clone tutorial so I'm going to assume that you've named your keyspace as netflix.
It seems as though you haven't followed the instructions correctly and have missed steps. I can replicate the error you reported if I skip at least one of the steps in the tutorial.
In step 5 of the tutorial, you needed to do the following:
✅ In graphQL playground, change tab to now use graphql. Edit the end of the URl to change from system to the name of your keyspace: netflix
✅ Populate HTTP HEADER variable x-cassandra-token on the bottom of the page with your token as shown below (again !! yes this is not the same tab)
Switch tabs
In order to insert data, you need to switch to the graphql tab.
If you try to insert the data in the graphql-schema tab, you will get the error you reported.
Set keyspace
You need to update the URI of your GraphQL playground in the graphql tab to use the keyspace name netflix instead of system. For example:
https://db_id-us-west1.apps.astra.datastax.com/api/graphql/system
change to:
https://db_id-us-west1.apps.astra.datastax.com/api/graphql/netflix
If you try to insert data into the system keyspace, you will get the error you reported because the reference_list table does not exist in that keyspace. Cheers!

Can we call External Rest API from Rule Chain to collect telemetry data from another API?

I am trying to collect energy generation statistics like Watts and wattHour form external API. I have External Rest API endpoint available for it.
Is there a way in Thingsboard using rule chain to call external endpoint and store its as telemetry data. Later i want to show this data in dashboards.
I know it has been too long, but thingsboard has lacking documentation and it might be useful for someone else.
You'd have to use the REST API CALL external node (https://thingsboard.io/docs/user-guide/rule-engine-2-0/external-nodes/#rest-api-call-node)
If the Node was successful, it will output it's OutboundMessage containing the HTTP Response, with the metadata containing:
- metadata.status
- metadata.statusCode
- metadata.statusReason
and with the payload of the message containing the response body from your external REST service (i.e. your stored telemetry).
You then have to use a script transformation node in order to format the metadata, payload and msgType, into the POST_TELEMETRY_REQUEST message format, see: https://thingsboard.io/docs/user-guide/rule-engine-2-0/overview/#predefined-message-types
Your external REST API should provide the correct "deviceName" and "deviceType", as well as the "ts" in UNIX milliseconds.
Notice that you also need to change the messageType (msgType return variable) to "POST_TELEMETRY_REQUEST".
Finally, just transmit the result to the Save timeseries action node and it will be stored as a telemetry from the specified device. Hope this helps.

How do I display data from Rails backend to Ember frontend without saving it in the database and without using Ember-Data?

The problem:
I have used rest-client to pull news articles from newsapi.org through my Rails backend. I can display that data on localhost:3000/articles. I do not (necessarily) want to save this data to a database and would like to simply display it on my Ember frontend after calling it on my Rails backend. I get this error:
Error while processing route: article Assertion Failed: You must include an 'id' for article in an object passed to 'push'
I understand this to mean that my data has no 'id' - which it doesn't. I have no control over the data coming in.
{
"status": "ok",
"totalResults": 6868,
"articles": [
{
"source": {
"id": "mashable",
"name": "Mashable"
},
"author": "Lacey Smith",
"title": "Cannabis may alter the genetic makeup of sperm",
"description": "A new study suggests that marijuana use can not
only lower sperm count, but also affect sperm DNA. Read more... More
about Marijuana, Cannabis, Sperm, Science, and Health",
"url": "https://mashable.com/video/cannabis-sperm-dna/",
"content": null
},
Ember-Data doesn't like this because it's not in JSONAPI format and I can't change it to JSONAPI. How do I display this data on my ember frontend without using Ember-Data and without having to save it into my database? The tutorials I've found all have examples using databases and Ember-Data.
What I've already tried:
I tried to save it to my database and load from there, but I'm thinking that might complicate the idea, since I would need to scrape the data and save it to my database and that has proven difficult to do. I'm not experienced with backend stuff and haven't found many answers. If you have an answer for doing it this way, feel free to answer here:
How to automatically save data from url to database
I'm willing to try it out. I thought originally this would be the best way to go. I could save the data and only add to the database when new articles were returned. I'm not having any luck this way, so I thought I'd approach it from another direction.
Thanks for any help!
If you want to do some processing outside of ember-data, create a service. In your service, you will need to then make an ajax/fetch request to your backend. Let's say you are using ember-ajax to make your requests:
import Service, { inject } from '#ember/service';
export default Service.extend({
// inject the ember-ajax ajax service into your service
ajax: inject(),
//this returns a promise
getNewsItems(){
var options = {
// request options (aka anything needed to authenticate against your api, etc)
};
let url = "yourBackendEndpoint/for/this/resource";
return request(url, options).then(response => {
// `response` is the data from the server
// here you want to convert the JSON into something useable
return response;
});
}
});
Then, let's say in a model hook for some route, you needed this service (which we will say is defined in your-app/services/my-service.js) to fetch the news feed items:
import Route from '#ember/route';
import { inject } from '#ember/service';
export default Route.extend({
myService: inject(),
model(){
let myService = this.get('myService');
return myService.getNewsItems();
}
)
I personally use ember-fetch which avoids the jQuery dependency and is useable in all target browsers for my app. I do not use ember-data in any of my apps.

404 response when creating a course with the API

I am attempting to create a course with the API, and no matter how I tweak what I am sending I keep getting back the same 404 error. I am posting the following to /d2l/api/lp/1.4/courses/ in our test instance.
{
"Name":"STLR Course-112",
"Code":"STLR.112.201420",
"Path":"",
"CourseTemplateId":22462,
"SemesterId":22460,
"StartDate":"2014-05-07T12:00:00.000Z",
"EndDate":"2014-05-07T13:00:00.000Z",
"LocaleId":null,
"ForceLocale":false,
"ShowAddressBook":false
}
I can confirm with a test instance here that this API works with data almost identical to the block you provide here. POSTing a body like this (white space added for clarity):
{"CourseTemplateId": 8082,
"LocaleId": null,
"Code": "STLR.112.201420",
"Name": "STLR Course-112",
"Path": "",
"ShowAddressBook": false,
"EndDate": "2014-05-07T13:00:00.000Z",
"StartDate": "2014-05-07T12:00:00.000Z",
"ForceLocale": false,
"SemesterId": 6984}
Gets me a 200 with a response like this (white space added for clarity):
{"Identifier":"114119",
"Name":"STLR Course-112",
"Code":"STLR.112.201420",
"IsActive":true,
"Path":"/content/enforced/114119-STLR.112.201420/",
"StartDate":"2014-05-07T12:00:00.000Z",
"EndDate":"2014-05-07T13:00:00.000Z",
"CourseTemplate":{"Identifier":"8082",
"Name":"ExtensibilityTemplate",
"Code":"EXT-TMPL"},
"Semester":{"Identifier":"6984",
"Name":"Fall 2011",
"Code":"FA2011"},
"Department":{"Identifier":"8081",
"Name":"Extensibility",
"Code":"EXT"}
}
It appears to me that the only differences between my input block and yours are the IDs provided for course template and semester, so that I could hook the new course into my local test instance instead of the IDs for those orgunits in yours. Otherwise, it appears the input properties are identical.
Some things you could look at:
Ensure you're using the right Org Unit Id values for your course template and your semester
Ensure that your LMS is configured to enforce content paths for new org units: this should then provoke the LMS to auto-create the path for you when you create a course offering; if you don't have content path enforcement on, then you might have to instead specify a valid content path for your course offering on create, and passing in an empty string probably won't be a valid path, and thus you might get a 404 back because the API service handler "can't find the content path" you've specified.
Is there a particular message that comes back with the 404?

Resources