Hello everyone, I"m currently working on a project where we do some querries from a AWS DynamoDB Database. I'm currently working on it and managed to print everything I want on the console, but once I want to pass it through a msg.payload node, I can't manage to do it.
So I'm not sure why my "Query on SensorTalbe" node is not returning anything...
[
{
"id": "384d5a3110ff57b6",
"type": "tab",
"label": "DynamoDB",
"disabled": false,
"info": "",
"env": []
},
{
"id": "72e62fd0ba30be05",
"type": "ui_date_picker",
"z": "384d5a3110ff57b6",
"name": "",
"label": "Date picker",
"group": "8488dbd9c1c91b57",
"order": 2,
"width": 0,
"height": 0,
"passthru": true,
"topic": "topic",
"topicType": "msg",
"className": "",
"x": 130,
"y": 280,
"wires": [
[
"075bc6787001c562"
]
]
},
{
"id": "075bc6787001c562",
"type": "function",
"z": "384d5a3110ff57b6",
"name": "Query on SensorDataTable",
"func": "var Time = msg.payload;\n\nfunction toDate(date) {\n if (date === void 0) {\n return new Date(0);\n }\n if (isDate(date)) {\n return date;\n } else {\n return new Date(parseFloat(date.toString()));\n }\n}\n\nfunction isDate(date) {\n return (date instanceof Date);\n}\n\nfunction format(date, format) {\n var d = toDate(date);\n return format\n .replace(/Y/gm, d.getFullYear().toString())\n .replace(/m/gm, ('0' + (d.getMonth() + 1)).substr(-2))\n .replace(/d/gm, ('0' + (d.getDate() + 1)).substr(-2))\n .replace(/H/gm, ('0' + (d.getHours() + 0)).substr(-2))\n .replace(/i/gm, ('0' + (d.getMinutes() + 0)).substr(-2))\n .replace(/s/gm, ('0' + (d.getSeconds() + 0)).substr(-2))\n .replace(/v/gm, ('0000' + (d.getMilliseconds() % 1000)).substr(-3));\n}\n\nlet CurrentDate = + new Date(); //number\nlet SpecifiedDate= + new Date(Time); //number\n\n\nvar dateFormat = \"Y-m-d H:i:s.v\";\n\nvar CurrentDateFormat = format(CurrentDate, dateFormat);\nvar SpecifiedDateFormat = format(SpecifiedDate, dateFormat);\n\nconsole.log(\"Between:\", SpecifiedDateFormat, \"and\", CurrentDateFormat);\n\nvar AWS = global.get('sdk');\n\nAWS.config.update({ region: 'us-east-2' });\n\nvar docClient = new AWS.DynamoDB.DocumentClient();\n\nconsole.log(\"Querying for events.\");\n\nvar params = {\n TableName : \"SensorDataTable\",\n KeyConditionExpression: \"#edt= :yyyy\",\n ExpressionAttributeNames:{\n \"#edt\": \"EventDateTime\"\n },\n FilterExpression: \"#edt between :start_edt and :end_edt\",\n ExpressionAttributeValues: {\n \":start_edt\": SpecifiedDateFormat, \n \":end_edt\": CurrentDateFormat\n }\n};\n\nconsole.log(\"Scanning EventDateTimes\");\n\ndocClient.scan(params, onScan);\n\nfunction onScan(err, data) {\n if (err) {\n console.error(\"Unable to scan the table. Error JSON:\", JSON.stringify(err, null, 2));\n } else {\n console.log(\"Scan succeeded.\");\n data.Items.forEach(function(item) {\n console.log(\n item.EventDateTime + \" Devide ID:\",\n item.DeviceID,\n \"- Temperature:\", item.Temperature,\n \"- Humidity:\", item.Humidity,\n \"- Mouvement:\", item.Mouvement,\n \"- UltraViolet:\", item.UltraViolet);\n\n payload = {\"Time\" :item.EventDateTime,\n \"ID\":item.DeviceID,\n \"Temperature\":item.Temperature,\n \"Humidity\":item.Humidity,\n \"Mouvement\":item.Mouvement,\n \"UltraViolet\": item.UltraViolet};\n \n msg.payload = payload;\n return msg;\n });\n\n }\n}\n\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 360,
"y": 280,
"wires": [
[
"6cbc2240c6325847"
]
]
},
{
"id": "6cbc2240c6325847",
"type": "debug",
"z": "384d5a3110ff57b6",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 660,
"y": 380,
"wires": []
},
{
"id": "8488dbd9c1c91b57",
"type": "ui_group",
"name": "Actionneurs",
"tab": "e55ffb8a26591b17",
"order": 4,
"disp": true,
"width": "6",
"collapse": false,
"className": ""
},
{
"id": "e55ffb8a26591b17",
"type": "ui_tab",
"name": "RaspBerry #1",
"icon": "dashboard",
"order": 1,
"disabled": false,
"hidden": false
}
]