Exporting then emailing groov view trends via node red?

Sorry if this is posted in the wrong forum.

I came across this thread on the AR1: https://forums.opto22.com/t/save-groov-trend-data-to-a-csv-file-on-the-ar1/1476/7

It would seem my request is possible, accessing the CSV on the EPIC and then emailing via node red?

Cheers mates

From a high level, yes, I don’t see any major red flags.
Do the API call, save the data to the local file system, then send it via email.
This thread will help: Sending an email attachment with Node-RED

1 Like

thanks - seems it goes a little deeper than I imagined.

am I correct in assuming it is better to pull the data from the trends when I need to? ie: once a week.

Scenario:
I am trending 4 scales that weigh ingredients 24/7. I have my groov view trend setup to scan every second for 1 week. At the end of the week before the data is over written or deleted (if it does) I would like to email it off to the relevant production manager.

My first thought when creating this thread was pulling the exported csv from groov view and simply attaching it to the email.
We obviously don’t want to fill the drive on the unit, so pulling the data into a csv and mailing would be first option.

Without having dug into the threads in much detail, would I need to set dates and times to pull the data from the trends - time from - time to? Export, then email straight away to prevent storing data on the EPIC hdd.

Hope I’m making sense. Cheers

Ok, sounds like we might put something together for you and everyone else…
Just help me out at the first step… Do you currently know how to pull down the graph data?

In other words, I know its a weekly task, one that we are going to automate, but do you do this at the moment?

1 Like

I am aware that the ability to download the data is there via the burger button. I have tested it before in demo and it does download. So to answer the question, yes - it would have been a weekly task on site by the operator

We don’t actually support time ranges at the moment, so no. Requesting that file via download will pull down all available data, so you might need to reconcile what you’re downloading with what you’ve already got, filter for duplicate values, etc.

@Jonathan_Fischer If the trend is 1 week long and you only pull at the same time every week, you would not get much overlap? (If any).

He’s trending once a second, so unless he’s really lucky with the timing, there should be a little bit of overlap.

2 Likes

@Jakes To avoid having an operator do this weekly it can be done programmatically with a weekly inject. A lot of the steps are from the other threads linked above, but hopefully this helps tie it all together for a PR1 / PR2 / RIO.


Firstly, you will need to download the email node package since it is no longer a core pre-installed node, and make sure you have an email account with an application password.

Next, get the URL you will need from the hamburger menu, but make sure it has the parameter ?api_key=<YOURAPIKEY> to be compatible with the http request node. You can replace the hostname with localhost if you are running the Node-RED flow on the same device as the groov View project.

You’ll also need to authorize the request, you can find a breakdown of that in this forum thread: Authenticating Opto API calls with HTTP request

Once you have the data in Node-RED you’ll need wrap it in the right message properties. That’s covered in the thread Ben linked earlier. It will not write the file to the HDD at any point, it just exists in memory.

Finally, here’s an example flow you can use to get started.

[{"id":"87dd5faefe53415b","type":"tab","label":"Email groov Trend","disabled":false,"info":""},{"id":"dbf5bb3d28d5b26a","type":"e-mail","z":"87dd5faefe53415b","server":"smtp.gmail.com","port":"465","secure":true,"tls":true,"name":"address@gmail.com","dname":"","credentials":{},"x":760,"y":120,"wires":[]},{"id":"0a1866b58bdfff4c","type":"function","z":"87dd5faefe53415b","name":"set properties","func":"var datestring = new Date().toISOString().substring(0,10);\nvar filestring = \"scanned-data_\" + datestring + \".csv\"\n\n// Set attachment file (utf-8 saved as *.csv)\nmsg.attachments =\n    {\n        filename    : filestring,\n        content     : msg.payload\n    };\n\n// Email subject\nmsg.topic = \"Your Weekly Report for \" + datestring;\n\n// Email body text\nmsg.payload = \"See attached file: `\" + filestring + \"`\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":120,"wires":[["eee6d330768dfaf2","dbf5bb3d28d5b26a"]]},{"id":"02049363f73ac611","type":"http request","z":"87dd5faefe53415b","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://localhost/view/api/v0/data-logging/2_0_720_12_false,13_0_720_12_false,1_0_720_12_false/scanned-data.csv?api_key=mR4VG3sRSrRJok4ZouNGJN7iNJQpfKER","tls":"3940dc165d82fa25","persist":false,"proxy":"","authType":"","x":350,"y":120,"wires":[["0a1866b58bdfff4c"]]},{"id":"eee6d330768dfaf2","type":"debug","z":"87dd5faefe53415b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":80,"wires":[]},{"id":"e039263cbab8638c","type":"inject","z":"87dd5faefe53415b","name":"8am Monday","props":[],"repeat":"","crontab":"00 08 * * 1","once":false,"onceDelay":0.1,"topic":"","x":160,"y":120,"wires":[["02049363f73ac611"]]},{"id":"3940dc165d82fa25","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false,"alpnprotocol":""}]

Remember to change the inject to whenever you want the report sent, add your own email, and replace the base URL and API key so it works with your tag(s). If you have multiple tags in one trend, like I do in my example, it will show them all as individual columns in the *.csv file.

Please let us know if that gets you going and if you have any follow-up questions.

2 Likes

Thank you very much guys. I’ll get cracking and provide some feedback.