0

I work in a powerplant and there's a power meter that is unable to be connected on the network. I need to [1] monitor the data displayed on the power meter screen at [2] 7:00 AM, 3:00 PM, and 9:00 PM for about a week and [3] automatically upload it to a Google Drive account.

I think a camera to take pictures of the power meter display will be simple enough to gather sufficient data that will be analyzed afterward.

I'm at the stage of ordering the parts for the build. Can anyone provide some guidelines, e.g., parts, suggested codes, etc.?

My tinkering skills are somewhat outdated but I'm able to get going if someone can provide some guidelines and ideas.

Thank in advance for any help, really appreciate it.

Kind regards,

Jairo

4
  • Will this device have access to WiFi or do you plan to run wired network cable? Will it have local power available or do you plan to power it via Power-over-Ethernet (PoE)? Jul 23 '20 at 15:58
  • Another question... what do you want to do with these images once your Pi captures them? Will you log in periodically to download them? Do you want the Pi to automatically send them somewhere? Jul 23 '20 at 16:36
  • Hi Tim, Thanks for the prompt response. The device will have access to WiFi and preferably be battery-powered, but a local power source is also available. No PoE required. The images captured will be analyzed individually to extract the data displayed on the Power Meter for a duration of one week or so. I will regularly login to the Google Drive account to verify if the capturing process is performing accordingly.
    – Jairo
    Jul 23 '20 at 18:02
  • Keep in mind that the Pi has to be shut down properly, like any general purpose computer (your laptop, phone, etc.), but unlike those examples it does not have circuitry to automate that (such that you push the power button and the system shuts down, then disconnects power). Point being, you can't just let it run out of battery or have the power arbitrarily cut. You can, however, safely leave it running 24/7.
    – goldilocks
    Jul 23 '20 at 18:06
2

Based on the notion that WiFi is available and this is a very light use-case, you could get away with a Pi Zero W (the 'W' is WiFi version).

The major elements of this are:

  • Acquire & assemble hardware
  • Download Raspberry Pi OS (Lite)
  • Copy OS image to microSD card
  • Configure to allow SSH access and also WiFi configuration
  • Create camera capture job (via raspistill)
  • Configure auto-capture schedule (via cron)

Also note that the main documentation site is here: https://www.raspberrypi.org/documentation/

Hardware

While quite a few Raspberry Pi models will work, this is a particularly light work-load job and would easily be handled by a Raspberry Pi Zero W. Note that this version supports 802.11b/g/n but does not support the ac standard. For 802.11ac you would need a Raspberry Pi 3 Model A+ or B+.

You also need a 5v/2.5amp power supply with a microUSB connector (the Pi 4 Model B uses a USB-C connector and requires a minimum 3amp power supply)

You will need a microSD card. These have become so inexpensive that I tend to not bother buying cards with less than 32GB space ... but even a 16GB card would be more than adequate.

You will also need a camera. You can use either the official Raspberry Pi color camera or you can use a USB web-cam (most web-cams work).

The Pi will not include a case ... there are a mind-boggling number of case choices.

Download Raspberry Pi OS

The main download page is here: https://www.raspberrypi.org/downloads/ But this page will give you several choices. Probably what you really want is Raspberry Pi OS (Lite). This version uses less storage space because it doesn't have optional applications nor does it build a 'desktop' environment -- which you don't need since you aren't going to connect a monitor or keyboard. The 'Lite' version of the OS is on this page: https://www.raspberrypi.org/downloads/raspberry-pi-os/

Once you download the image, you need to copy it to the microSD card. The download page does have instructions on how to do this. A popular tool used to create the microSD card image is Balena Etcher (aka 'Etcher').

Once you finish creating the image, it will have put two partitions on your microSD card. One image is a Linux ext4 partition which a PC or Mac wont necessarily know how to mount and read. But it will also create a partition named /boot which is an MSDOS FAT32 filesystem and your PC or Mac will be able to mount and read/write that partition.

If you get a warning about Windows not being able to recognize the microSD card (after you are finished making it) just eject the card (do not let Windows attempt to fix it ... it is complaining about not knowing how to deal with the Linux ext4 partition. You just want Windows to ignore it.)

Configure the image to allow remote access and WiFi

In the /boot partition (before ejecting from your PC or Mac)

  1. Make a file named 'ssh' in the /boot folder. The file can be empty. On first boot, if Raspberry Pi OS sees a file with this name it will automatically enable the ssh service to allow remote logins.

  2. Configure WiFi. Use this page: https://www.raspberrypi.org/documentation/configuration/wireless/headless.md

If these two steps (ssh has been enabled and you have pre-configured your WiFi settings) then you are ready to boot your Raspberry Pi.

Eject the microSD card from your PC or Mac and insert it into the Raspberry Pi and power it on.

On first boot it will resize the root (/) partition (the Linux ext4 partition) to use all remaining space on your microSD card.

It will also enable the SSH service.

It will join your WiFi network.

It is now ready for login.

From a Mac, open the 'Terminal' window and use:

$ ssh pi@raspberrypi.local

The initial password is 'raspberry'.

From Windows it's slightly trickier because you wont know what IP address was assigned. This page offers hints on how to do that: https://www.raspberrypi.org/documentation/remote-access/ip-address.md

Once you know the IP address, you can log in from Windows. Check Microsoft docs if you have questions on how to use PowerShell, but basically it's just like the Unix version where you run the command

ssh pi@<ip address>

The free 3rd party PuTTY tool is also very popular.

Once you have successfully logged in, run 'rasps-config'

$ sudo raspi-config

This will let you change the hostname to something more meaningful (otherwise every raspberry pi you have will end up with the same hostname -- not good) and also change the default password to something unique.

Use arrow-keys and/or the TAB key to navigate the menus.

Also navigate to '5 Interfacing Options' and make sure the camera is enabled.

From time to time you should keep the OS updated to latest patch levels. Do this via these two commands:

$ sudo apt update
$ sudo apt upgrade

The first command refreshes the Pi's package repository (think of this as a catalog of available packages and version levels) but does not actually change any software.

The second command tells the Pi to compare it's current install version to the latest available, and then download and install any upgrades as needed.

Camera

Get the camera working. Earlier I mentioned that you can use rasps-config (requires the 'sudo' command to run it ... e.g. 'sudo rasps-config') to enable the camera. Make sure it is enabled.

You can find instructions on using 'raspistill' to capture images from the camera here: https://www.raspberrypi.org/documentation/usage/camera/raspicam/raspistill.md

Those instructions end up creating a script called 'camera.sh' (the name isn't important) but I'll assume that name was used for the next step.

Configure auto-capture

Unix & Linux systems use a utility called 'cron' to schedule job runs based on time & date. This list of jobs that need to run are maintained in a text file called 'crontab' (cron table). A background process called crond (cron daemon) reads this file and runs jobs per your schedule.

You'll need to create your schedule. To do this type:

$ crontab -e

The first time you run this, it will ask you which text editor you prefer to use. It will suggest Nano (since it is the easier/most-user-friendly).

You will need to add a new row to the bottom of that file. Anything with a '#' o the start of the line is a comment and is ignored by cron.

You'll notice the last comment line reads:

# m h  dom mon dow  command

This are hints as to the field order you use for your scheduled job.

m = minutes. You want your job to run at the top of the hour (but only on certain hours) so you'll enter '00' for the minutes.

h = hours. This could be a single value like 7; a range value like 7-11, or a comma-separated list of hours like 7,15,21. Cron uses a 24-hour clock so 3pm = 15 and 9pm = 21. Therefore you'll use 7,15,21 for 7pm, 3pm, and 9pm.

dom = day-of-month. You want your job to run everyday ... not just some days ... so you can enter an asterisk (*) as the wildcard character.

mon = month. You want all months of the year, so use '*'

dow = day-of-week. You want every day of the week, so again, use '*'.

The last field is the command you want to run. But cron does not inherit a default 'path' environment. This means you need to enter the full-qualified-path to your command. e.g. instead of 'cature.sh' it needs to be '/home/pi/capture.sh' (assuming capture.sh is in your home folder).

Putting it all together, the final command needs to read:

00 7,15,21 * * * /home/pi/capture.sh

Save this file and exit Nano.

Finished

At this point the configuration is complete. The Pi is now able to self-boot, join WiFi, and will run the 'capture.sh' command at your scheduled time intervals.

It wont do anything with the images it captures... it's up to you to copy them to another host.

You can use 'scp' commands (secure copy) to copy the files. You can find tips on that here: https://www.raspberrypi.org/documentation/remote-access/ssh/scp.md

If you prefer a GUI instead of command line, there are loads of graphical tools to do this. Just do a web search for an SCP utility.

(Hopefully I didn't miss any steps. Let me know if you see an omission/typo/error, etc.)

Specify an ad-hoc future time

Cron lets you schedule recurring tasks ... they'll get run periodically based on your schedule. If you want to run something in the future ... but don't want to schedule it as a recurring task (via cron) you can use the at command.

This allows a one-time future execution of some command (or set of commands).

I have a full-install (plus desktop) of Raspberry Pi OS and even in my 'full' install, the 'at' command wasn't installed (this surprised me because usually cron and at go hand-in-hand.)

So you'll likely have to do:

sudo apt install at

Follow the command prompts and hit "Y" when prompted to install it.

Once installed, the basic command is:

$ at 2:00PM 

which implies today, or

$ at 2:00PM Wed

which sets it to 2PM next Wednesday (instead of today)

Notice, however, that this command doesn't actually say what to do at 2:00PM. When you submit the command it will interactively prompt you to start typing commands. Alternatively you can use the Linux pipe facility to pipe the command to at. You can also use the -f option to tell it to pull the commands from a file (and name the file).

Here's an example of the interaction:

pi@tims-raspi-8gb:~ $ at 1:26 PM
warning: commands will be executed using /bin/sh
at> echo "Hello"
at> <EOT>
job 4 at Fri Jul 24 13:26:00 2020

I typed 'at 1:26 PM' -- indicating the time when I want to run some commands.

It responds with a prompt: at>

I type the first command. In my example it's: echo "Hello"

It responds with another prompt: at>

I don't have any more commands to give it, so I end input by doing a CTRL+D (it prints to acknowledge the end of my input). It also tells me it has scheduled this as job #4.

After the command runs, I get a message on the terminal (the message wont display until the next time I enter something (anything) in the shell. So I just hit return to get it show the message.

pi@tims-raspi-8gb:~ $ 
You have mail in /var/mail/pi

This is the output from my command. Unless you redirect output to another source, any output that would have been displayed if you ran the command yourself will get saved and mailed to you (yes, there's mail already installed in the OS. It isn't configured to send mail to other computers but it is set up to send/receive mail to/from processes or other users on the same computer.)

Read it via the mail command:

pi@tims-raspi-8gb:~ $ mail
"/var/mail/pi": 1 message 1 new
>N   1 pi@tims-raspi-8gb  Fri Jul 24 13:26  14/461   Output from your job     
? 

Message #1 is my mail output. Just type '1' to read message 1. When finished, type 'd' to delete it, then 'q' to quit.

Uploading to Google Drive

I'm sure there are multiple ways to do this. I haven't done this myself, but here's (what appears to be) a fairly thorough article on the topic:

https://medium.com/@artur.klauser/mounting-google-drive-on-raspberry-pi-f5002c7095c2

9
  • After all of this... I forgot to mention the Google Drive component. There are a few ways to do this. I'll update this shortly with a link to an article that walks through that process (it is a bit involved.) Jul 24 '20 at 1:28
  • Hi Tim. Many thanks for all the information. I really appreciate it. Unfortunately, it appears that the website decided to "close" my post since it "needs to be more focused". Hopefully, you'll have the time to include the Google Drive part but this should get me going with the parts ordering.
    – Jairo
    Jul 24 '20 at 14:07
  • Tim, is there a way I can directly provide additional questions to you regarding your solution?
    – Jairo
    Jul 24 '20 at 15:41
  • Tim, also say, for example, I wanted to capture an image at a specific time other than the auto-capture schedule or a "ad-hoc" live view, which code should I use?
    – Jairo
    Jul 24 '20 at 16:07
  • @Jairo, Use the 'at' command. I'll update the answer. Jul 24 '20 at 16:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.