--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
H
regards
Dave Conway-Jones
--
For example:
var currentdate = new Date();
var currenthour = currentdate.getHours();
in a Node-Red function on my Pi is definitely reflecting the timezone I've set in raspi-config.
--
http://nodered.org
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/ff5chUeXhJI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.
Hi quick update.
Would this be the correct way of doing it ? obviously would need to change a few things but it looks like it would work ?
http://www.w3schools.com/jsref/jsref_concat_string.asp
Regards
Gary
On Tuesday, 18 November 2014 07:56:05 UTC, Gaz wrote:Hi Nicholas,
Thanks for that, but I did try that and although it does add the timestamp, I then lose the original message.
Any pointers to how I can keep both ?
I do realise I need to learn more javascript, but at the moment I am not sure what I am looking for ?
Regards
Gary
On Monday, 17 November 2014 23:37:48 UTC, Nicholas O'Leary wrote:Hi Gaz,
The easiest way to add a timestamp to a payload is to use a Function node with something like the following:
msg.payload = new Date().toString();
return msg;
That sets the payload to a human readable date. You'll have to have a read of the various functions available on the Date object within JavaScript if you want a more customised format.
Wire that function node to a twitter output node you've connected to your twitter account and it should just work.
Nick
On Mon, 17 Nov 2014 23:25 Gaz <online.a...@googlemail.com> wrote:
Hi,--
New to node-red, I am trying to add a timestamp to the message payload then output this to a twitter account.I have searched online for past hour and cannot find a solution.
Any help would be greatly appreciated
regards
Gaz
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
This certainly seems like a convoluded approach, but has been this way forever (in most languages). It is due to how arrays work, the first element being 0. Strings are the same thing, the first character is in position 0. Seems pretty dumb, but it probably comes from pointer offsets... Start of variable plus X... Where x would be zero for the first spot, then 1, etc.
Anyhow, its not a huge deal, just add 1 to it when you use it. You can do .getMonth()+1 for example.
I tried to insert my time in UTC, but I get the following error:
I have only been successful inserting to SQL with this code:
var d = new Date();
dformat = [d.getMonth()+1,
d.getDate(),
d.getFullYear()].join('/')+' '+
[d.getHours(),
d.getMinutes(),
d.getSeconds()].join(':');
dtstmp = new Date().toString();
msg.topic = "STG/A/CycleStart";
tp = msg.topic;
pay = msg.payload.digitalSamples.DIO4;
pld = "INSERT INTO [Dev].[dbo].[MQTTData] (Topic, Payload, Timestamp) "
pld = pld + "VALUES ('" + tp + "', '" + pay + "', '" + dformat + "') "
pld = pld;
msg.payload = pld
return msg;
I would gladly change to UTC, if that is what it takes to make my Dashboard Chart reflect my local time of EST.
I use a query to get the chart data. Here is the entire flow:
[{"id":"c84ec3ca.44a08","type":"xbee-rx","z":"a860ddde.52e5a","name":"XBee","xBee":"72923406.31a05c","x":80,"y":91,"wires":[["45164c96.175d54","28d19cb6.3174c4","5d9b1a9b.ba3854"]]},{"id":"ba2f2f4a.fd432","type":"debug","z":"a860ddde.52e5a","name":"","active":true,"console":"false","complete":"true","x":990,"y":93,"wires":[]},{"id":"18873f4b.0523c1","type":"MSSQL","z":"a860ddde.52e5a","mssqlCN":"3b35b5a4.fd817a","name":"MSSQL","query":"","outField":"payload","x":752,"y":92,"wires":[["ba2f2f4a.fd432"]]},{"id":"27725d2d.6b50e2","type":"rpi-gpio out","z":"a860ddde.52e5a","name":"","pin":"11","set":"","level":"0","freq":"","out":"out","x":694,"y":146,"wires":[]},{"id":"45164c96.175d54","type":"function","z":"a860ddde.52e5a","name":"","func":"if(msg.payload.digitalSamples.DIO4 === 0) {\nmsg.payload = 0;\n}\nelse {\nmsg.payload = 1;\n}\nreturn msg;","outputs":1,"noerr":0,"x":463,"y":145,"wires":[["27725d2d.6b50e2","e68fafac.f0855"]]},{"id":"e68fafac.f0855","type":"debug","z":"a860ddde.52e5a","name":"","active":false,"console":"false","complete":"false","x":705,"y":194,"wires":[]},{"id":"13ced987.c3dcc6","type":"function","z":"a860ddde.52e5a","name":"","func":"// name of the time column values:\nvar tcol = \"Timestamp\";\n// list of columns to be charted:\nvar cols = [ \"Payload\" ];\n\n// iterate over each column of the query results\nvar data = cols.map(function(col) {\n // iterate over each row of the query results\n var vals = msg.payload.map(function(row) {\n // return a data point for each col\n return [ +row[tcol], +row[col] ];\n });\n\n // return data object for each line on the chart\n return { key: col, values: vals };\n});\n\n// now put the new chart data in the payload\nmsg.payload = data;\nreturn msg;\nreturn msg;","outputs":1,"noerr":0,"x":1029,"y":268,"wires":[["87c28657.1816a8"]]},{"id":"afa157e3.8046e8","type":"MSSQL","z":"a860ddde.52e5a","mssqlCN":"3b35b5a4.fd817a","name":"MSSQL","query":"","outField":"payload","x":829,"y":268,"wires":[["13ced987.c3dcc6"]]},{"id":"87c28657.1816a8","type":"ui_chart","z":"a860ddde.52e5a","name":"","group":"84aa1ca8.6426","order":0,"width":"6","height":"6","label":"On / Off State","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"step","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":1213,"y":269,"wires":[[],[]]},{"id":"5d9b1a9b.ba3854","type":"function","z":"a860ddde.52e5a","name":"Function","func":"pld = \"SELECT Payload, Timestamp \"\npld = pld + \"FROM [Dev].[dbo].[MQTTData] \"\npld = pld + \"ORDER BY Timestamp \" ;\n\nmsg.payload = pld\nreturn msg;\n\n\n\n\n","outputs":1,"noerr":0,"x":467,"y":266,"wires":[["7451747c.9c024c"]]},{"id":"7451747c.9c024c","type":"delay","z":"a860ddde.52e5a","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":644,"y":267,"wires":[["afa157e3.8046e8"]]},{"id":"28d19cb6.3174c4","type":"rbe","z":"a860ddde.52e5a","name":"","func":"rbei","gap":"1","start":"","inout":"in","x":272,"y":91,"wires":[["52137bdb.4200a4"]]},{"id":"52137bdb.4200a4","type":"function","z":"a860ddde.52e5a","name":"Data Conversion","func":"var d = new Date();\n dformat = [d.getMonth()+1,\n d.getDate(),\n d.getFullYear()].join('/')+' '+\n [d.getHours(),\n d.getMinutes(),\n d.getSeconds()].join(':');\ndtstmp = new Date().toString();\nmsg.topic = \"STG/A/CycleStart\";\ntp = msg.topic;\npay = msg.payload.digitalSamples.DIO4;\npld = \"INSERT INTO [Dev].[dbo].[MQTTData] (Topic, Payload, Timestamp) \"\npld = pld + \"VALUES ('\" + tp + \"', '\" + pay + \"', '\" + dformat + \"') \"\npld = pld;\n\nmsg.payload = pld\nreturn msg;","outputs":1,"noerr":0,"x":503,"y":91,"wires":[["18873f4b.0523c1"]]},{"id":"72923406.31a05c","type":"xbee-config","z":"","apiMode":"1","rawFrames":false,"convertAdc":true,"vrefAdc":"1200","serialPort":"/dev/ttyS0","lock":true,"baudRate":"9600","dataBits":"8","stopBits":"1","parity":"none","bufferSize":"65536","rtscts":false,"xon":false,"xoff":false,"xany":false,"vmin":"1","vtime":"0"},{"id":"3b35b5a4.fd817a","type":"MSSQL-CN","z":"a860ddde.52e5a","name":"Dev","server":"10.0.0.120","encyption":true,"database":"Dev"},{"id":"84aa1ca8.6426","type":"ui_group","z":"","name":"STG Dashboard","tab":"c5cdd240.287e2","disp":true,"width":"6"},{"id":"c5cdd240.287e2","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]
Here is what my table looks like:
Here are the data types:
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/b6f0619d-643f-4ead-ac39-a3d57626e8a4%40googlegroups.com.
tp = msg.topic;
pay = msg.payload.digitalSamples.DIO4;
d = ??? --- Now() didn't work, Date() didn't work. (Got "ReferenceError: now is not defined")
INSERT INTO [Dev].[dbo].[MQTTData] (Topic, Payload, Timestamp) VALUES ('" + tp + "', '" + pay + "', '" + d + "')
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/fe134ef5-2ee9-482b-8c33-68eae192d308%40googlegroups.com.
INSERT INTO [Dev].[dbo].[MQTTData] (Topic, Payload, Timestamp) VALUES ('STG/A/CycleStart', 1, CURRENT_TIMESTAMP);
INSERT INTO [Dev].[dbo].[MQTTData] (Topic, Payload) VALUES ('STG/A/CycleStart', 1);
> Date.now()
1507738769623
> new Date().toString()
'Wed Oct 11 2017 12:19:42 GMT-0400 (Eastern Daylight Time)'
> new Date().toISOString()
'2017-10-11T16:20:01.282Z'
--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/ff5chUeXhJI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/b30e24e9-8da3-4b4e-ae07-287a4eab645f%40googlegroups.com.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.
var now = new Date(); // the current datetime as a Date object
var iso = now.toISOString(); // converted to YYYY-MM-DDThh:mm:ss.dddZ format
var utc = iso.replace(/^(.*)T(.*)Z$/, "$1 $2"); // with the 'T' and 'Z' removed
var utc = iso.replace(/^(.*)T(.*)\.\d+Z$/, "$1 $2"); // without fractional seconds
update MQTTData
set Timestamp = dateAdd(second, dateDiff(second, getDate(), getUtcDate()), Timestamp)
;