Friday, March 11, 2016

Weather Station 3: Crontab, ffmpeg & Youtube

Some things are up and running. You can check out the pictures and temp data here, but you might only see pictures of my apartment and the temp data is being wonky. All things to fix!

With the hardware complete, I need to wrap up the loose ends with software.

This is what needed to be done:

  1. Schedule all the tasks
    1. Take pictures every 10 seconds
    2. Make a video from those pictures once a day
    3. Clean up and reset for next day
    4. Shut down pi at 10pm and reboot at 5am
  2. Make the video - I'm using ffmpeg
  3. Upload that video to youtube
Clearly some of these overlap, but I decided to figure out Crontab first so I can get the pictures scheduled.

Crontab

You can schedule scripts in linux using crontab. There are countless tutorials online showing you how to do this. Before scheduling anything, be sure to run your script from your home directory as that is where cron starts looking. If you call many other files in your script (as I was doing) be sure to use ABSOLUTE PATHS! Your script will not work if you are using relative paths and your working directory is not home.


Test in home directory:


$ cd /home

$ python /home/pi/Documents/WeatherProject/MainScript.py

If that doesn't work, cron will not work. Fix issues here!

Scheduling in crontab

To open the crontab document, type the following command:

$ crontab -e

You should see a bunch of comments followed by blank space. In the blank space add the following line:

SHELL = /bin/bash

This makes cron interpret your commands as if you were typing them into the bash shell like normal.

Next, schedule the task.

* 5-21 * * * python /home/pi/Documents/WeatherProject/MainScript.py

The normal bash command comes after the asterisks, the asterisks are a sort of clock.
The above command would run every minute of every hour between 5am and 10pm, not including 10pm.

This is how I scheduled the photos, sensor read and uploading to dropbox and google sheets.

As for cleanup, I'm planning on resetting the image number (currently stored, read and updated in a text file), make the video and then delete the day's images. Will post code when it's all working.

I haven't yet scheduled the cleanup or video stuff. I still have to figure out ffmpeg.

ffmpeg

I followed this tutorial to install ffmpeg. It takes a while.

I also followed this explanation for how to use ffmpeg to make a timelapse video from jpg files. It hasn't worked yet, but I'm trying to reinstall then i'll try a few more things. Will update once it works.

Youtube

So I anticipate this being the hardest portion. Once I have ffmpeg working i'll work through this support page from google. One of the changes google made to its API is to have a central developer account so that, theoretically, all of the google apis get routed through the same thing. This ideally will make things easier for me since I already have the oauth2 information in that json file, but I can't really say until its all working. Will update soon!

Weather Station 2: Hardware

I got all the hardware!!! I'm so excited to show this! It came out really well.
Before I get into the nitty gritty of soldering and circuitry... some software stuff changed since I last posted. First, I had to stop using timestamps as the image file names. This is because I am using ffmpeg to make the videos and it expects names like image001, image002 etc. Second, I decided only to upload one image to dropbox and call it current_image.jpg. This ends up working better because then I don't need any fancy javascript on the website end to show the most recent photo. This is what I have so far for the site. So now onto the fun stuff...

Hardware

I followed a portion of the tutorial here, however they fail to mention that you need an additional JST connector, so add that to the shopping list. Here are some pics of the modules and soldering jobs (mostly terrible).
Charger module (best soldering job for this project)
Power Booster (terrible soldering job!)

Solar panel connected to charger module, connected to lithium ion battery


With everything connected:
The finished product!
The charger module does double duty charging the lithium ion battery and dispensing that charge to the booster module. The booster is then plugged into the pi. It all works too!

One part that I totally messed up was the DHT22. I tried to solder the connections together, but did such a terrible job that the connection goes in and out. I have to go back and fix it.
10k ohm resistor between pins 1 and 2

Camera and sensor embedded in tupperware
In order to seal the tupperware from water, I used caulk and hot glue to seal around the DHT22 sensor and around the cable connecting the charging module to the solar panel.
No seal on the cord
Hot glue and caulk to seal the hole

Everything would seem to be working!
Hand held, solar powered computer!!
Hardware complete! I haven't tested how long the charge lasts or how well it charges in cloudy weather.

Now to finish the software portion...