Author Topic: Raspberry Pi Zero - Upload to WU and save images  (Read 861 times)

0 Members and 1 Guest are viewing this topic.

Offline StormCapture

  • Member
  • *
  • Posts: 30
Raspberry Pi Zero - Upload to WU and save images
« on: January 02, 2018, 01:25:39 AM »
After having a WU account since 2011, and after years of deciding to put a webcam up, I have finally got the hardware.

I got a Raspberry Pi Zero Board with the Camera (V2), still awaiting on arrival of a 16GB Micro SD card to install Raspain onto it.

What I want to do is Upload it via FTP to WU and also have the software on the Pi save the images so I can transfer them onto a windows 10 PC, giving I will need the USB Adapter for it to put on a USB flash stick,  so I can keep an archived data set of the most interesting weather days (Being in Adelaide Australia, interesting weather is a rarity in its own)

So what would be the best way/software to do this? I'm not the best at coding and whatnot as I confuse myself while doing it but managed to put CumulusMX on with ease.

Offline bchwdlks

  • Contributor
  • ***
  • Posts: 120
Re: Raspberry Pi Zero - Upload to WU and save images
« Reply #1 on: January 02, 2018, 09:27:16 AM »
The Pi cron utility is the simplest way to do this. This script that I am using should be close, you will have to change the 'wget' to use the Pi camera module instead of an IP camera. It is also overlaying weather data onto the image and trimmimg it to an size. The weather data is coming from a Meteobridge provided file. It saves the images in a 'day-of-year'-'image number' format and then each night I build a timelapse file.

SCRIPT START###
      #!/bin/bash
      
      
      echo "#### Starts at [`date`]  ##### "
      
      ###
      ## Modified/Installed 2016-03-21
      ## Executed via cron on the 5s
      ## */5 * * * *  /var/www/html/WebCam/WU_PhotoUpdate.scr
      
      
      #######
      #######
      cd /var/www/html/WebCam
      
      ###  /home/pi/MeteoData.txt is created from meteobridge ftp download service
      DAY=`date +%A`
      DATE=`grep Date /home/pi/MeteoData.txt | cut -d: -f2- `
      TIME=`grep Time /home/pi/MeteoData.txt | cut -d: -f2- `
      TEMP=`grep Temp /home/pi/MeteoData.txt`
      BARO=`grep Bar /home/pi/MeteoData.txt`
      HUMI=`grep Hum /home/pi/MeteoData.txt`
      WIND=`grep Wind /home/pi/MeteoData.txt`
      GUST=`grep Gust /home/pi/MeteoData.txt`
      RAIN=`grep Rain /home/pi/MeteoData.txt`
      RATE=`grep Rate /home/pi/MeteoData.txt`
      ISDAY=`grep isday /home/pi/MeteoData.txt | cut -c8`
      
      
      
      
      case ${ISDAY} in
         0 )
            COL_CODE=CYAN ;;
         1 )
            COL_CODE=BLACK ;;
      esac
      
      
      
      #####   Get Photo From Sharx Web Cam
      ######
      
      mv jpeg.jpg OLD_jpeg.jpg 2>/dev/null
      wget http://192.168.254.36:80/live/0/jpeg.jpg
      mv jpeg.jpg WU_jpeg.jpg
      
      
      
      ######
      #####   Use Image Magick to put weather data onto photo
      ######
      convert WU_jpeg.jpg  -fill GRAY  -draw "fill-opacity 0.35 rectangle 300 0 1715 60" -pointsize 24  -fill ${COL_CODE}  -draw "text 310 25 '                                                               ${DAY} ${DATE} ${TIME}
       ===${TEMP} ${BARO} ${HUMI} ${WIND} ${GUST} ${RAIN}  ${RATE}===" -crop 1384x776+300+0 Adjusted.jpg
      
      
      
      ########
      ####### Send to WU
      HOST='webcam.wunderground.com'
      USER='WU_USER_ID'
      PASSWD='WU_USER_PASSWD'
      FILE='Adjusted.jpg'
      ftp -n -v $HOST <<END_SCRIPT
      quote USER $USER
      quote PASS $PASSWD
      binary
      put $FILE
      quit
      END_SCRIPT
      
      
      echo "########
      ########
      WU DONE @ [`date`]
      ########
      ########"
      
      
      ######
      ##### Save photo Y or N
      SAVE_PHOTO=Y
      #SAVE_PHOTO=N
      
      FILE_NAME=`cat NUMBER`
      
      
      
      if [ "$SAVE_PHOTO" = "Y" ]
      then
         mv Adjusted.jpg ./Photos/`date +%j`-$FILE_NAME.jpg
      else
         rm Adjusted.jpg
      fi
      
      
      # FILE_NAME is reset to 0 each night at 2358 by timelapse creator utility
      FILE_NAME=`expr ${FILE_NAME} + 1`
      
      case $FILE_NAME in
      1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 )
         FILE_NAME=0${FILE_NAME}
      ;;
      esac
      echo "$FILE_NAME">NUMBER
      
      
      ######
      
echo "##### ENDS at [`date`]    #####"






SCRIPT END ###

Offline StormCapture

  • Member
  • *
  • Posts: 30
Re: Raspberry Pi Zero - Upload to WU and save images
« Reply #2 on: January 15, 2018, 06:27:24 AM »
Well I managed to write the script out (with the help of YouTube tutorails)

Just gotta figure out why it is coming up with the FTP: webcam.wunderground.com is coming up with Name or Service not known

Offline Bushman

  • Forecaster
  • *****
  • Posts: 7001
    • Eagle Bay Weather
Re: Raspberry Pi Zero - Upload to WU and save images
« Reply #3 on: January 15, 2018, 10:48:23 AM »
'Cause WU webcams are no more.

Offline Catskin

  • Member
  • *
  • Posts: 11
Re: Raspberry Pi Zero - Upload to WU and save images
« Reply #4 on: January 15, 2018, 11:15:42 AM »

The Pi cron utility is the simplest way to do this....

Brilliant, thank you.

Offline bchwdlks

  • Contributor
  • ***
  • Posts: 120
Re: Raspberry Pi Zero - Upload to WU and save images
« Reply #5 on: January 15, 2018, 12:59:48 PM »
'Cause WU webcams are no more.
Not true - WU has reversed on that plan and has now said that webcams will stay around.

This problem (Name or Service not known) is most likely a dns issue on the RPi.  You should be able to type in :
$ host webcam.wunderground.com

And if your dns is working the response should be :

webcam.wunderground.com has address 54.148.11.142
webcam.wunderground.com has address 52.37.52.183
webcam.wunderground.com has address 52.36.136.128

If you do not get that answer, search the RPi forum in the 'troubleshooting' section for common solutions to this problem.

You can bypass this error by changing 'webcam.wunderground.com' to 54.148.11.142  - this might allow you to send photos to WU now, but it does not correct the problem.

That ip address is the webcam server that allows 10000 users, so most of the time it will accept your photo. The other 2 severs are only accepting 50 connections so most of the time you will not connect to them. But there is no guarantee that WU will use the photo. Right now I am sending photos every 15 minutes and about 90% are successfully transferred. But there are only about 5-10 per day that show up on the web page.

Offline StormCapture

  • Member
  • *
  • Posts: 30
Re: Raspberry Pi Zero - Upload to WU and save images
« Reply #6 on: January 15, 2018, 06:12:28 PM »
Ill give that a whirl and see how I go otherwise I will look into an alternative

If anything, Iíll set up my own webpage VIA Cumulus and send it to that site

Offline StormCapture

  • Member
  • *
  • Posts: 30
Re: Raspberry Pi Zero - Upload to WU and save images
« Reply #7 on: January 15, 2018, 08:36:18 PM »
only 1 of the 3 is correct, this is what I got:

webcam.wunderground.com has address   52.37.52.183
webcam.wunderground.com has address   52.34.136.128
webcam.wunderground.com has address   52.148.11.142

 

anything