Saturday, November 15, 2014

Download Newspaper on Kindle by switching on RASPBERRY PI

In my earlier post I created a cron job on raspberry pi to download the newspaper via calibre on a pre defined time. (cron job is not enabled on RASPBMC by default. You need to enable it.).

But there could be times when you dont want to keep the raspberry pi switched on all the time just to wait till morning and let the cron job download the newspaper. The alternative is to schedule the job at startup. But again there is problem that there might be instances when i am working on some other thing on Raspberry and rebooting it mutliple time in a day. In that case my kindle will be flooded with the newspaper of same day.

Solution: I created a script to be scheduled at startup which will check the current time. If the current time is between 6:30 AM - 8 AM , the newspaper will download. Otherwise no.


Make the script executable. 

chomod +x /home/pi/scripts/time.sh

The above script can be schedule on Raspberry Pi (running RASPBMC) as follows - 

1. sudo nano /etc/rc.local
2. Add below line in the last of the file- just before exit.
    
   sh /home/pi/scripts/time.sh


Now if my RASPBERRY PI is not running over night then I just switch it on in the morning and get the newspaper delivered to my kindle.

Cheerz.

Tuesday, November 11, 2014

Enabling cron job in RASPBMC

Per default running cron jobs is deactivated in Raspbmc and there are two ways to activate them.

1. In the Raspbmc GUI under Programs -> Raspbmc Settings -> System Configuration -> Service Management -> Cronjob Scheduler

2. Via SSH/FTP by modifying sys.service.cron value to “true” the settings file under /home/<your_username>/.xbmc/userdata/addon_data/script.raspbmc.settings/settings.xml – for more infos on changing settings via SSH / FTP

-Cheers 

Sunday, November 9, 2014

Get IP of Raspberry Pi as soon it starts via PushBullet

1. First of all install curl not already installed.
2. Create a shell file with below code and replace <API> and <ID>

3. make it executable
chmod +x <filename>
4. Schedule at startup. Execute below command

sudo nano /etc/rc.local
5. Add below line. 
sh /home/pi/scripts/piip.sh

Friday, November 7, 2014

Headless Calibre Server for News–RASPBMC


First of all thanks to Kovid Goyal for the wonderful software called Calibre.
One of the best features of the Calibre is to fetch news from RSS feed and send it to my Kindle in most beautiful format.

The challenge: is that I cannot keep my laptop always on so that it can send the news on the predefined time.

Solution: Using my all purpose RASPBERRY PI for the purpose.

Steps :

1. Install Calibre

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install calibre

2. Ensure that the LANG variable is set. Just because mine was not set.

export LANG=en_US.UTF-8

3. Check if it is set correctly


locale

After editing a locale file, do not forget to re-generate the locales for the changes to take effect after reboot.

The locales that can be generated are listed in the /etc/locale.gen file: their names are defined using the format [language][_TERRITORY][.CODESET][@modifier]. To generate a locale, first uncomment the corresponding line in the file (or comment to remove); when doing this, also consider the localizations that other users on the system might need. For example, for American-English uncomment en_US.UTF.8 UTF-8. When done, save the file and generate the uncommented locale(s) by executing:


# locale-gen



4. Now since we are running the headless server and calibre don’t support is by default, hence we need to use xvfb. To use this we need to first install xvfb


sudo apt-get install xvfb

5. creating email.txt file which will contain all the email to which the email will be sent and saving it to /home/pi/scripts/ (the folder which I created in my earlier posts). One email per line in file.

6. Creating a fetch_news.sh file. (Thanks to https://gist.github.com/rogeliodh/1560289). I have modified the script a little and saving it to /home/pi/scripts/ 






7. Make the script executable


chmod a+x fetch_news.sh

8. Place the latest recipe file in the same folder i.e. saving it to /home/pi/scripts/ . If you are not aware where to get the latest version go to
https://github.com/kovidgoyal/calibre/tree/master/recipes
or you may also access the same on your PC in the zip file named “builtin_recipes” on below path C:\Program Files (x86)\Calibre2\resources

9. Run the (ba)sh file to check it.


cd /scripts
sh fetch_news.sh

10. Schedule the file to run – I am setting it to 6:30 AM every morning.


crontab -e

30 6 * * * /home/pi/scripts/fetch_news.sh

press ctrl + x and y to save the file.

Tip 1: Check the date and time before setting date and time

date

if time is not correct execute below command

date +%T -s "10:13:13"

Tip 2: If you are using the same Raspberry Pi for transmission download also, then you can schedule the reduced bandwidth (for example between 60:20 - 7:00 AM as in my case) so that Calibre dont face any issue while it downloads the News RSS.

Prevent Raspberry Pi (RASPBMC) from sleeping

Observing that the raspberry pi is going down after 30 min. if no activity done on the xbmc. The problem is that i have configured sickbeard + transmission also on my raspberry pi = 24 hours downloading box.

Follow below steps to prevent raspberry from going to sleep.

sudo nano /etc/kbd/config


edit these values to:
BLANK_TIME=0
POWERDOWN_TIME=0

-Cheers