Skip to content

Commit

Permalink
Update to ensure batteryLevel property for insert statement
Browse files Browse the repository at this point in the history
Added dataTablename not null check
Updated some stdouts
  • Loading branch information
st-randers committed May 6, 2024
1 parent 9896dd8 commit 68ca17b
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 22 deletions.
3 changes: 2 additions & 1 deletion node-red/flows_js/_order.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@
"change.6b9a4e582b1e4da4.flows.js",
"comment.463a093b401ccd0b.flows.js",
"switch.f495d16c127c3ba0.flows.js",
"debug.5468111c8102dba1.flows.js"
"debug.5468111c8102dba1.flows.js",
"change.38afcc1229ffc351.flows.js"
]
29 changes: 29 additions & 0 deletions node-red/flows_js/change.38afcc1229ffc351.flows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const Node = {
"id": "38afcc1229ffc351",
"type": "change",
"z": "7d89c5933c6ac70c",
"name": "",
"rules": [
{
"t": "set",
"p": "device.batteryLevel",
"pt": "msg",
"to": "device.batteryLevel ~> $type = 'number' ? \tdevice.batteryLevel : -1",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 420,
"y": 1600,
"wires": [
[
"94c08cd5b3d4e152"
]
]
}

module.exports = Node;
4 changes: 2 additions & 2 deletions node-red/flows_js/comment.e3cca0e958a2d3ef.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const Node = {
"z": "7d89c5933c6ac70c",
"name": "Opdater metadata",
"info": "",
"x": 410,
"y": 1540,
"x": 230,
"y": 1560,
"wires": []
}

Expand Down
2 changes: 1 addition & 1 deletion node-red/flows_js/debug.144c2f0348f31878.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Node = {
"targetType": "jsonata",
"statusVal": "",
"statusType": "auto",
"x": 920,
"x": 1200,
"y": 1600,
"wires": []
}
Expand Down
2 changes: 1 addition & 1 deletion node-red/flows_js/debug.8623dd2211386e01.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Node = {
"tosidebar": true,
"console": true,
"tostatus": false,
"complete": "payload ~> $count() > 0 ?\t{\t data.deviceEui: \"device is registered\",\t \"lastObservation\": payload[0].lastObservation = \"0000-00-00 00:00:00\" ?\t \"no observation\" : payload[0].lastObservation\t}\t:\tdata.deviceEui ~> $exists() ?\t {\t data.deviceEui: \"device is NOT registered\"\t }\t :\t {\t \"unknown-device\": \"no deviceEui provided\"\t }",
"complete": "payload ~> $count() > 0 ?\t{\t data.deviceEui: \"device is registered\",\t \"lastObservation\": payload[0].lastObservation = \"0000-00-00 00:00:00\" ?\t \"no observation\" : payload[0].lastObservation,\t \"tablename\": payload[0].dataTablename\t}\t:\tdata.deviceEui ~> $exists() ?\t {\t data.deviceEui: \"device is NOT registered\"\t }\t :\t {\t \"unknown-device\": \"no deviceEui provided\"\t }",
"targetType": "jsonata",
"statusVal": "",
"statusType": "auto",
Expand Down
3 changes: 1 addition & 2 deletions node-red/flows_js/debug.d55a813ba56dba9e.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ const Node = {
"id": "d55a813ba56dba9e",
"type": "debug",
"z": "7d89c5933c6ac70c",
"d": true,
"name": "stdout",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload.warningCount > 0\t? { data.tablename: \"table exists\" }\t:\t{ data.tablename: \"table created\" }",
"complete": "payload.warningCount > 0 ?\t{\t data.tablename: \"warning when creating table\",\t payload: payload\t}\t:\t{\t data.tablename: \"data table created\"\t}",
"targetType": "jsonata",
"statusVal": "",
"statusType": "auto",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Node = {
"type": "subflow:f637fce5f03731d6",
"z": "7d89c5933c6ac70c",
"name": "",
"x": 710,
"x": 990,
"y": 1600,
"wires": [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const Node = {
"y": 820,
"wires": [
[
"455b8bd3394db098"
"455b8bd3394db098",
"d55a813ba56dba9e"
]
]
}
Expand Down
2 changes: 1 addition & 1 deletion node-red/flows_js/switch.7e1977c7cfb7a24f.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Node = {
"type": "switch",
"z": "7d89c5933c6ac70c",
"name": "Findes en \\n observation?",
"property": "payload[0].lastObservation = null or payload[0].lastObservation = \"0000-00-00 00:00:00\"",
"property": "payload[0].dataTablename = null or\tpayload[0].lastObservation = null or\tpayload[0].lastObservation = \"0000-00-00 00:00:00\"",
"propertyType": "jsonata",
"rules": [
{
Expand Down
2 changes: 1 addition & 1 deletion node-red/flows_js/switch.f495d16c127c3ba0.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Node = {
"y": 1600,
"wires": [
[
"94c08cd5b3d4e152"
"38afcc1229ffc351"
]
]
}
Expand Down
7 changes: 5 additions & 2 deletions node-red/flows_js/template.455b8bd3394db098.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ const Node = {
}

Node.template = `
UPDATE {{global.metadataTablename.maaler}} SET
UPDATE
{{global.metadataTablename.maaler}}
SET
dateFirstUsed = CURRENT_TIMESTAMP
WHERE deviceEui = '{{data.deviceEui}}'
WHERE
deviceEui = '{{data.deviceEui}}'
`

module.exports = Node;
4 changes: 2 additions & 2 deletions node-red/flows_js/template.7fe6f3f247026a69.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const Node = {

Node.template = `
INSERT INTO {{data.tablename}}
(observedAt, type, value)
(observedAt, type, value)
VALUES
{{{sqlvalues}}}
{{{sqlvalues}}}
`

module.exports = Node;
9 changes: 6 additions & 3 deletions node-red/flows_js/template.94c08cd5b3d4e152.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Node = {
"syntax": "mustache",
"template": "",
"output": "str",
"x": 450,
"x": 730,
"y": 1600,
"wires": [
[
Expand All @@ -19,12 +19,15 @@ const Node = {
}

Node.template = `
UPDATE {{global.metadataTablename.maaler}} SET
UPDATE
{{global.metadataTablename.maaler}}
SET
lastObservation = '{{data.observedAt}}',
dataTablename = '{{data.tablename}}',
rssi = {{data.rssi}},
batteryLevel = {{data.batteryLevel}}
WHERE deviceEui = '{{data.deviceEui}}'
WHERE
deviceEui = '{{data.deviceEui}}'
`

module.exports = Node;
12 changes: 8 additions & 4 deletions node-red/flows_js/template.d64e6d1b2aeeb641.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ const Node = {

Node.template = `
SELECT
lastObservation
FROM {{global.metadataTablename.maaler}}
WHERE deviceEui = '{{data.deviceEui}}'
ORDER BY lastObservation DESC LIMIT 1
lastObservation,
dataTablename
FROM
{{global.metadataTablename.maaler}}
WHERE
deviceEui = '{{data.deviceEui}}'
ORDER BY
lastObservation DESC LIMIT 1
`

module.exports = Node;

0 comments on commit 68ca17b

Please sign in to comment.