Automate a screen capture?

Hi,

I have a dashboard with 20 gauges on it, once a month I have to open a new window and type "scrot -d 20" , I then minimise the window and the screenshot is taken, I then manually send the image via e-mail to a friend, my question is could this process be automated so that it could be done if i wasn't there ?

Thanks
Stuart

Hi, honestly it depends on how much time / effort you want to spend on it plus the environment you're running on. Looks like Linux? If it is simply once a month is it worth automating?

I think you could cobble something together with a shell script for this...

Read and format the current date. Compare to requested date. If they match then run the script. scrot accepts command line params to delay X seconds first. You should also think about detecting a failure with the script so it can be executed manually. Maybe mail the snapshot to yourself as well?

Command-line mail is possible as well - including the snapshot as an attachment.

Doing this in Node-RED is also possible. We use it to automate complex web pages all the time. There is more needed (look at WDIO nodes) including Java / Selenium on a machine but can allow for much more sophisticated automation.

Cheers,

Paul

Hi,

It is on a raspberry pi running node red , I have found a suitable sheduler called cronplus which can stipulate the time of month trigger, there are a few screenshot nodes, but i just don't really know where to start putting them togethor to send via email, any help grately appreciated

cheers
Stuart

The problem is, node-red (including cron-plus) work at the server side. The browser is 100% client side.

You could, as suggested, trigger a shell script IF node-red is on same machine as browser....

Cron-plus > exec shell > (opens browser)

Uicontrol (detect connection to dashboard) > exec shell (to take screen grap and save to file. Then, close browser)

Uicontrol (detect browser disconnected from dashboard) > load file > email it.

Just a whole load of hassle.

There are probably tons of scripts or apps that can fire up a browser and print to image on regular schedule, then you can just do this...

Cron-plus > read file > email.

1 Like

If Microsoft's new browser testing/automation library Playwright installs on a Raspberry, it might be quite a straightforward route for getting the screenshot. You would create a standalone Node.js script to do that, then use exec node to run it.

Here's an example code snippet from their documentation you could adapt to your needs:

const { webkit } = require('playwright');  // Or 'chromium' or 'firefox'.

(async () => {
  const browser = await webkit.launch();
  const context = await browser.newContext();
  const page = await context.newPage();
  await page.goto('https://example.com');
  await page.screenshot({path: 'screenshot.png'});
  await browser.close();
})();

Hi,
Everything is on the pi, the screenshot that i want to take is of the node-red dashboard which constantly displays my 20 gauges,on the pi, so everything is server side.

Thanks
Stuart

For my suggestion this shouldn't be a problem as the library can even operate the browsers "headless" (without the browser window opening). But the big if is compatibility with Raspberry's CPU architecture. I don't know if they support ARM.

Edit: Install is running, let's see what happens!

Edit 2: Nope, unfortunately it didn't work at least through ssh. Install went without issues but running the script crashes. I don't have time to try to figure out if it's fixable right now. :expressionless:

Why? Why image? 20 gauges is 20 values. Gauge shows current state of some measurement. Why the friend needs picture of gauges. You can easily format the email content as current state of your measurements as json which in other end can be feed to local node red and show the state with gauges. But what really means something is state. And may be proof that setup is working well.
Move data, not the representation of that same data.

3 Likes

Hi hotNipi,

i am just looking for an easy option, the gauges are 20 temperatures that are updated every 3 mins via mtqq sensors on the network, i need to email the temperatures once a month to a collegue, all very easy when i am there but the childrens charity that i work for are having to fulough me untill things hopefully get back to a normality, therefore i need to send myself the temperatures, if i can somehow put the data off the gauges into an email and that is easier then that will be fine i just don't know how to do it.

Thanks
Stuart

It really depends on how your flows are created but simple strategy will be to hold one global object of all measurements which have named parameters of different measured targets. Then with every incoming measurement update also the global object and if time comes for report just read values from that object and format the email content.
To go in details with it, it takes you to start doing it and ask specific questions if you stuck with something.

Hi hotNipi,

yes it is more complicated than it seems, i seem to remember asking about this some time ago and nobody could help, in my mind what i would do is just put the values into variables as they come in, then an email could be made from adding the variables, but i beleive there is something odd about node red not having variables or something similar, i think it isd something that a developer/codewriter would be able to do i am nowhere near clever enough

Thanks
Stuart

Here's a simple example flow that demonstrates storing and retrieving values from global storage variables. Press the first two inject nodes to simulate temperatures you'd display in a gauge. The change nodes store the values.

The third inject node reads the latest temperature values and the result is displayed in the debug log. This payload you could use as the data for the email to be sent.

[{"id":"da553073.8d165","type":"inject","z":"bf210454.b85538","name":"temp indoor","topic":"","payload":"22.0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":80,"wires":[["6009aa90.cfa2d4"]]},{"id":"52e5b8b0.6ef608","type":"inject","z":"bf210454.b85538","name":"temp outdoor","topic":"","payload":"5.0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":140,"wires":[["8927fc14.0a32a"]]},{"id":"8927fc14.0a32a","type":"change","z":"bf210454.b85538","name":"","rules":[{"t":"set","p":"temp.outdoor","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":140,"wires":[[]]},{"id":"f24b5892.f6acd8","type":"debug","z":"bf210454.b85538","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":350,"y":220,"wires":[]},{"id":"6009aa90.cfa2d4","type":"change","z":"bf210454.b85538","name":"","rules":[{"t":"set","p":"temp.indoor","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":80,"wires":[[]]},{"id":"7d5eaa63.91ec54","type":"inject","z":"bf210454.b85538","name":"read temperatures","topic":"","payload":"temp","payloadType":"global","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":220,"wires":[["f24b5892.f6acd8"]]}]

Hi Ristomatti,

Thanks for this I have some time at home to try it, i have also just enrolled on an online node-red course so fingers crossed

Thanks
Stuart

1 Like

It if curiosity, what course?

I would also recommend watching this playlist: Node-RED Essentials. It is by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in less than an hour.

Hi Steve,

Thanks for the info, the courses are udemy dont know if they are any good yet, will check your link out tommoz

Cheers
Stuart

Could I suggest an alternative approach to the problem.
1.) A minor modification to the existing flow to add InfluxDB nodes so that all messages going to the Dashboard also go to a cloud InfluxDB
2.) A cloud instance of Grafana connects to the InfluxDB database and provides multi user access to the data in real time from anywhere.
This is not as complex as it sounds and a small application like this would probably be possible in a "free" tier on many of the cloud providers (Google, IBM Cloud, Amazon Web Services)
I have a number of these implemented and they work great.

Hi mtoko,

Thanks for your sugestion, although I am not a fan of cloud services & databases, I am toying with the idea of using Sqlite as a db locally and keep the temperatures in that, another avenue to go down as I am not sure how the raspberry pi would cope, hopefully some courses in the next few days will help.

cheers
Stuart

Hi Stuart
If you use InfluxDb, it is already a time series database so temperature and time stamp are easily saved. You could run InfluxDB and Grafana on a Pi ( providing you manage the size of the database) and then just give remote access to the Grafana ports only. I have also done this successfully and tried the option of running InfluxDB and Grafana in Docker.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.