Node red multiple msg.payloads - sqlite

i got 2 nodes fetching some mqtt data, some temperature and humidity readings. Im trying to pass that info to a sqlite node. On that node i have the following code:
var newMsg = {
"topic": "INSERT INTO ambiente VALUES (null, #thisshouldbetemperature, #thisshouldbehumidity, date('now'), time('now') )"
}
return newMsg;
I try to use a join node but didnt make the work. So, what is the correct way to pass both msg.payload to that function? Thanks!

The join node is the correct way to combine the 2 incoming messages. You should use the manual mode and configure it to create a key value object something like this.
The problem is that your function node is ignoring the incoming data and creating a new message with just a topic set.
The fix for the function node is:
msg.topic = "INSERT INTO ambiente VALUES (null, " + msg.payload.temperature + ", " + msg.payload.humidity + " , date('now'), time('now') )";
return msg;
This will just update the msg.topic and leave the incoming msg.payload intact. This assumes that the MQTT messages arrive on topics temperature and humidity.

Related

HTTR package is not returning full response from API query

I am trying to use httr to call on an API from IGDB (documentation here). When I use the following query in Postman, I have no problem and get the full request which has 100 entries:
fields rating, game; where game = 114283; limit 100; sort id desc;
Example of entry here:
{
"id": 442667,
"game": 114283,
"rating": 3.0
},
However, when I attempt to make this query in R using httr as follows:
string <- paste0("rating, game; where game = ", ids[1,1], "; limit 100; sort id desc;")
data <- POST("https://api-v3.igdb.com/private/rates/",
add_headers("user-key" = "XXXXXXXXXX"),
query = list(fields = string)
)
fromJSON(rawToChar(data$content))
it returns only a data frame of 23 rows:
id game rating
1 442667 114283 3
...
23 383956 114283 10
Other calls similarly return shortened data frames with varying length depending upon the query.
If anyone has any idea as to why this might be happening, I would love some insight.
Thanks.
I think you're merely passing your query string in wrongly, since it is supposed to be passed into the -d (data) parameter of your http request.
Try the following:
append the initial "fields " into string
pass this to the body param of your POST request
So:
string <- paste0("fields rating, game; where game = ", ids[1,1], "; limit 100; sort id desc;")
data <- POST(
"https://api-v3.igdb.com/private/rates/",
add_headers("user-key" = "XXXXXXXXXX"),
body = string
)

DoGet with multiple parameters not being recognized

I'm currently trying to connect a Lua Script with a GS WebApp. The connection is working but due to my lack of knowledge in GScripting I'm not sure why it isn't saving my data correctly.
In the Lua side I'm just passing in a hard-code a random name and simple numerical userid.
local HttpService = game:GetService("HttpService")
local scriptID = scriptlink
local WebApp
local function updateSpreadSheet ()
local playerData = (scriptID .. "?userid=123&name:Jhon Smith")
WebApp = HttpService:GetAsync(playerData)
end
do
updateSpreadSheet()
end
On the Google Script side i'm only saving the data on the last row and then add the value of the userid and the name.
function doGet(e) {
console.log(e)
// console.log(f)
callName(e.parameter.userid,e.parameter.name);
}
function callName(userid,name) {
// Get the last Row and add the name provided
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(sheet.getLastRow() + 1,1).setValues([userid],[name]);
}
However, the only data the script is saving is the name, bypassing the the userid for reasons I have yet to discover.
setValues() requires a 2D array and range dimensions should correspond to that array. The script is only getting 1 x 1 range and setValues argument is not a 2D array. Fix the syntax or use appendRow
sheet.getRange(sheet.getLastRow() + 1,1,1,2).setValues([[userid,name]]);
//or
sheet.appendRow([userid,name])
References:
appendRow

Application Insights and Azure Stream Analytics Query export the whole custom dimensions as string

I have setup a continuous export from Application Insights into Blog. With a data stream I'm able to get out the JSON files into SQL DB. So far so good.
Also with help from Phani Rahul Sivalenka I'm able to query the individual properties of custom dimensions as described here: Application Insights and Azure Stream Analytics Query a custom JSON property
My custom dimensions looks like this when exporting manually into CSV file:
"{""OperatingSystemVersion"":""10.0.18362.418"",""OperatingSystem"":""WINDOWS"",""RuntimePlatform"":""UWP"",""Manufacturer"":""LENOVO"",""ScreenHeight"":""696"",""IsSimulator"":""False"",""ScreenWidth"":""1366"",""Language"":""it"",""IsTablet"":""False"",""Model"":""LENOVO_BI_IDEAPAD4Q_BU_idea_FM_""}"
Additionally to the single columns I like to have the whole custom dimensions as a string in a SQL Table column (varchar(max)).
In the "Test results" of my Data Stream Output Query I see the column as formated above - but when really exporting / wrinting into SQL DB all my tests ended having only the value "Array" or "Record" as value in my SQL Table column.
What do I have to do in the Data Stream Query to get the whole custom dimensions value as a string and I'm able to write this into SQL Table as a whole string?
What do I have to do in the Data Stream Query to get the whole custom
dimensions value as a string and I'm able to write this into SQL Table
as a whole string?
You could use UDF to merge all key-values of single raw into one single json format string.
UDF:
function main(raw) {
let str = "{";
for(let key in raw) {
str = str + "\""+ key+"\":\""+raw[key]+"\",";
}
str += "}";
return str;
}
SQL:
SELECT udf.jsonstring(INPUT1) FROM INPUT1
Output:
The answer brought me on the right track.
The above script don't include the values as expected. So I modified the script to get it work as needed:
function main(dimensions) {
let str = "{";
for (let i in dimensions)
{
let dim = dimensions[i];
for (let key in dim)
{
str = str + "\"" + key+ "\":\""+dim[key]+"\",";
}
}
str += "}";
return str;
}
Selecting:
WITH pageViews as (
SELECT
V.ArrayValue.name as pageName
, *
, customDimensions = UDF.flattenCustomDimensions(A.context.custom.dimensions)
, customDimensionsString = UDF.createCustomDimesionsString(A.context.custom.dimensions)
FROM [AIInput] as A
CROSS APPLY GetElements(A.[view]) as V
)
With this I'm getting the custom dimensions string as follow in my SQL table:
{"Language":"tr","IsSimulator":"False","ScreenWidth":"1366","Manufacturer":"Hewlett-Packard","OperatingSystem":"WINDOWS","IsTablet":"False","Model":"K8K51ES#AB8","OperatingSystemVersion":"10.0.17763.805","ScreenHeight":"696","RuntimePlatform":"UWP",}

Passing Array parameter to SQLiteObject.executeSql()

I'm trying to pass an array parameter to the function executeSql of SQLiteObject in ionic to make it as a value for my sql query.
For example
var sqlQuery: string = "SELECT * FROM Property WHERE ID IN (?) AND Status = ?"
var ids: number[] = [123, 321, 456];
and I'm trying to pass it here,
var db: SQLiteObject
db.executeSql(sqlQuery, [ids, 0])
So basically I want to insert all the values of ids to the IN operator and 0 for Status. But I think the SQL interprets it differently.
I tried to pass it as a string db.executeSql(sqlQuery, [ids.toString(), 0]) to remove the unnecessary characters and such. But still it doesn't return anything.
NOTE
I know I need it to enclose to a promise or something, but I just sliced it and summarize it to remove the unnecessary codes. Thanks.
I tried to search all over but still can't find a definite answer, I just invent a work around for it by doing this method.
var ids: number[] = [123, 321, 456];
var sqlQuery: string = "SELECT * FROM Property WHERE ID IN (" + ids.toString() + ") AND Status = ?";
And pass it to executeSql function
var db: SQLiteObject
db.executeSql(sqlQuery, [0]);
This is just a work around. I'll still wait for a better solution. Thanks!

Retrieve "Variant" data type from Enterprise Architect using DXL

How can I use the DXL OLE mechanism to fetch a diagram's modification time from Enterprise Architect 12?
Details:
I want to retrieve diagrams from EA and integrate them as OLE object into IBM Rational DOORS 9.5. This is already working. I intend to compare the modification dates of the EA diagram and the DOORS object before retrieving the diagram to decide if this operation is really needed.
Problem is, EA provides a diagram attribute EA.Diagram.ModifiedDate which returns the diagram's modification date as data type Variant. How can I handle this within DXL? The result parameter for oleGet() can be one of the types string|int|bool|char|OleAutoObj. No structured type (which would probably be DxlObject). Neither string nor int parameters contain any useful data after the call -- just null values.
Test code:
OleAutoObj eaRepository, eaProject, eaDiagram
OleAutoObj eaApp = oleGetAutoObject("EA.App")
OleAutoArgs autoArgs = create
string guid = "{729F140F-9DA4-4ff6-A9B2-75622AD1C22D}"
// connect to an existing EA instance
oleGet (eaApp, "Repository", eaRepository)
oleMethod (eaRepository, "GetProjectInterface", autoArgs, eaProject)
// call EA to a diagram which has this GUID
put(autoArgs, guid)
oleMethod(eaRepository, "GetDiagramByGuid", autoArgs, eaDiagram)
delete autoArgs
// access diagram attributes
string eaModifiedDate // DXL accepts [string|int|bool|char|OleAutoObj] only
oleGet(eaDiagram, "ModifiedDate", eaModifiedDate)
print "ModifiedDate = '" eaModifiedDate"'\n"
IBM's Support Team (commercial, available for paying customers) couldn't help and suggested to forward this question to the Service Team (for extra $s). Rather disappointing.
Try this one (just guessing :-)
OleAutoObj eaModifiedDate
oleGet(diagram, "ModifiedDate", eaModifiedDate)
if (null eaModifiedDate)
print "no eaModifiedDate\n"
else {
string diaDate
oleGet(eaModifiedDate, "Value", diaDate)
print "ModifiedDate = '" diaDate"'\n"
}
If that does not work then here comes the ultimate work around:
string err
string result
put(autoArgs, "SELECT ModifiedDate FROM t_diagram WHERE ea_guid = '" guid "'")
err = oleMethod (eaRepository, "SQLQuery", autoArgs, result)
if (!null err)
print "ERROR: " err "\n"
delete autoArgs
print "result= '" result"'\n"
This will return a XML formatted string (!) which contains the date in the format you like.
Edit 1: Turns out that EA's SQLQuery is buggy and returns just the date. Since Perl deals with OLE Variants in a similar way I found this code snippet:
my $dia = $rep->getdiagrambyguid("{63EFF3FA-0D5C-4986-AC0A-C723D2F755E3}");
my $value = $dia->ModifiedDate->Value;
print $value->Date( 'yyyy/MM/dd' );
print $value->Time( 'hh:mm:ss' );
So the ModifiedDate is an ole-object and has a Date and a Time method. This should work with DXL too.
Edit 2:Now here's the ulti-ultimate work around even shipping around the cliffs of EA's bug ocean:
my $dia = $rep->SQLQuery("SELECT Format (ModifiedDate, \"Short Time\") AS T FROM t_diagram");
This will format the date as time string. Works for EAP (aka Mickeysoft Access) according to this page. Other RDBMS likely have similar functions.
An update with a few corrections of my statements in comments.
I was wrong. It is indeed possible to receive structured data types using the OLE automation interface. As Thomas mentioned, the OleAutoObject is the proper DXL return type, oleGet() is the proper function. To access the returned object's attributes, it is required to be aware of the "real" data type and to have a look at the SDK documentation in order to know which class attributes are available since DXL is not aware of the data type.
However, in DXL, retrieving the attribute of a structured data type is a bit cumbersone. Example (intended to be appended to the inital post's code):
OleAutoObj diaLinksCollection
int count = -1
string buffer = ""
// access simple diagram attributes
err = oleGet(eaDiagram, "Version", buffer)
if (!null err) print "ERROR in Diagram.Version: " err "\n"
print "diagram version = " buffer "\n"
// access structured diagram attribute
err = oleGet(eaDiagram, "DiagramLinks", diaLinksCollection)
if (!null err) print "ERROR in Diagram.DiagramLinks: " err "\n"
err = oleGet(diaLinksCollection, "Count", count)
if (!null err) print "ERROR in Collection.Count: " err "\n"
print "count = " count "\n"
Thus, it is indeed possible to execute an SQL query, even if the repository is residing in a plain *.eap file, see Thomas' workaround.
As mentioned, the Variant data type can not be retrieved using oleGet() since this approach returns a NULL result.

Resources