Pages

Tuesday, 3 February 2015

Display real outside temperature on your android home screen (DS18B20)

Finally, my first raspberry GPIO project. What I am happy about, is that my >>hello world<< of electronics is not just a blinking diode (although even blinking diode can be quite powerful:)) but very useful and practical yet simple project which aim is to display real, outdoor temperature on android smartphone's home screen.

1) Ingridients:
- raspberry pi (with RAMP),
- 1-Wire temperature sensor: DS18B20 (waterproof version preferable):
- 4,7kΩ resistor:
- minimum 3-core cable (I used spare 4-core telephone cable):
- breadboard and jumpers (for prototyping only),
- android smartphone.

2) Hardware setup:
DS18B20 has 3 pins - see below for bare version schematics. For waterproof version: GND - black, DATA - white or yellow, Vdd - red.
Connect the temperature sensor with the resistor and raspberry pins as follows:
- wire GPIO7 with 3,3V using 4,7kΩ resistor,
- connect 3,3V raspberry pin to Vdd
- connect GPIO7 pin to DATA line
- connect GND to GND
As you can see you can make paraller connection using just one GPIO data pin and one resistor and get reliable results thanks to unique addressing of the sensors.
See below if you are unsure which pin is which (I use WiringPi naming convention). Also, find reference here.
Now do not forget to extend the reach of your sensor and put it outside:) Any meteorologist reading this will probably curse me, but I just installed mine under one of the windowsills on the first floor of the house.
3) System setup:

Edit the file /boot/config.txt and add the following line:
dtoverlay=w1-gpio,gpiopin=4

Also edit the file /etc/modules and add the following lines:
wire
w1-gpio
w1-therm
and reboot.

4) Reading the sensor:
To list all conneced devices do:

ls /sys/bus/w1/devices/

and you should see:

28-00203456e231  28-033475b26eea  w1_bus_master1

all the 28-xxxxxxxxxxxx directories represent each connected DS18B20 device.

If you cat the file /sys/bus/w1/devices/28-xxxxxxxxxxxx/w1_slave

you should see:

e2 ff 55 00 7f ff 0c 10 06 : crc=06 YES
e2 ff 55 00 7f ff 0c 10 06 t=-1875

what is interesting from our point of view is the value after "t=" at the end of second row. If you divide it by 1000 you will get the temperature in °C.

5) Webserver
Create subdirectory in your DocumentRoot of apache webserver, let's say "temperature", so it's accessible on http://raspberry_ip_address/temperature, where raspberry_ip_address can be either your internal or external IP address or domain/hostname.

Create PHP script which will read the w1_slave file (it's permission is by default 444/r--r--r--), parse it and display the temperature. You can also download my simple script (nothing fancy, a mixture of html, css and php, enough to get the job done) and edit the variable $sensorId with your DS18B20's unique address 28-xxxxxxxxxxxx:


You can extend the script, add authentication, what not. As you can see by investigating the source code of this script, it reads the temperature at runtime - that's fine. You can take different approach - read the temperature at some intervals, write it to a database/flat file/cloud and then read the latest value - whatever suits you.

6) Android configuration:
Go to Play Store and install Meta Widget. Now create the meta widget and configure it to your liking (you have to provide the URL of the temperature "website" created in step 5, click on the section of the site you wish to display and adjust some parameters like widget title, background, text size, etc). Mine looks like on the picture on the right, just underneath the "stock" weather widget:

Voilà!!!

Useful links:
http://picoboard.pl/raspberry-pi-obsluga-termomertrow-ds18b20
http://www.it-adviser.net/raspberry-pi-temperaturmessung-mit-ds18b20-1-wire-sensor
http://www.danielhansen.net/2013/03/raspberry-pi-temperature-logging-using.html
http://josy1024.blogspot.com/2014/02/raspbmc-und-temperaturmessung-mit.html
http://projects.privateeyepi.com/home/temperature-sensor-project-using-ds18b20

Thursday, 13 November 2014

My Linux essentials

Taking the sad opportunity that my pi crashed "irreversibly" (I suspect SD corruption, almost all was good except that I lost wifi access, some services stopped starting at boot and even that I investigated almost every single directory or file that should be responsible for boot/network config I couldn't find a solution; happily I had backup of everything important + this blog :)) and I had to perform clean install I will make a list of some most basic linux tools that do not come shipped with standard raspbmc installation but I find very useful:

sudo apt-get install and then:
git
htop
mc (midnight commander)
screen
tree

The above list will grow over time, as I install, test and get addicted to more "essential" tools :)


Wednesday, 15 October 2014

ownCloud

First make sure you have your RAMP set up correctly. Then it's really simple:

1) Follow steps described here to install latest version of ownCloud using apt-get (without it, my RaspBMC downloaded and installed ownCloud 4, while the latest at the time of writing this is 7.something):

sudo apt-get install owncloud

by default main ownCloud's files should install in /var/www/owncloud/ (including config/config.php), also apache's config file pointing to that location should be placed in /etc/apache2/conf.d/owncloud.conf (editing this file should allow you to change ownCloud's default URL)

2) Create directory where all your data will be stored, and make sure it's owner is changed to the user that apache runs on:

sudo chown -R apache_user:apache_user_group directory/

should do the trick

3) Complete ownCloud setup by launching http://your-rpi-local-address/owncloud

(here I stumbled upon some problems which I managed to solve with that fix)

4) Finish by polishing your ownCloud's configuration file located in /var/www/owncloud/config/config.php and edit trusted_domain section to enable access from internet (only if it's your intention!):

'trusted_domains'=>
array (
0=>'your-internal-domain-or-ip_address',
1=>'your-external-domain-or-ip_address'
),

5) WebDAV should be enabled by default, so use it with the following URL:

internal-or-external-domain-or-ip/owncloud/remote.php/webdav

Bunch of useful links:
http://www.ebayram.net/how-to-install-owncloud-on-ubuntu-and-debian/
https://forum.owncloud.org/viewtopic.php?f=8&t=18742
http://www.instructables.com/id/Raspberry-Pi-Owncloud-dropbox-clone/step3/Configuor-php-Apache/
http://doc.owncloud.org/server/7.0/admin_manual/installation/installation_wizard.html

Friday, 28 February 2014

RAMP: raspberry pi / apache / mysql mariadb / php5 / phpmyadmin

Let's start with installing apache essentials:

sudo apt-get install apache2 apache2-doc apache2-utils

then PHP5:

sudo apt-get install libapache2-mod-php5 php5 php-pear php5-mysql php5-xcache

and finally MariaDB... but wait, it's nowhere to be found in official raspbmc repository, so since I had some problems adding it and installing from official MariaDB repo, I used this one instead. So install it by simply doing:

sudo apt-get install mariadb-server

During MariaDB installation you should be prompted to set up root password.

Frankly.... I installed this some time ago and didn't take proper notes :( Well, maybe next time I install the RAMP stack I will work on this post ;) Sorry

Wednesday, 8 January 2014

transmission

Install transmission from OSMC App Store - according to OSMC Project Leader Sam Nazarko this is the preferable way as oposed to apt-get.

After installation is completed stop daemon with:

sudo systemctl stop transmission

then edit ~/.config/transmission-daemon/settings.json (where ~ means your home directory, so it will most likely be /home/osmc).

There's a plethora of settings, nicely described here, the default ones guarantee transmission running just fine, but you propably will want to change at least:
- download-dir - where your torrents will land,
- incomplete-dir-enabled (true) & incomplete-dir - where your torrents in progress will be stored,
- rpc-authentication-required (true) rpc-usernamerpc-password - transmission's web interface credentials (as for the password - type it in plain-text form, after you restart transmission it will be encrypted)
- script-torrent-done-enabled (true) & script-torrent-done-filename - full path to a bash script that will be executed when the torrent is finished (for example for sending emails follow sending emails with msmtp post).

As transmission runs under osmc user by default (beware - only if you install it from OSMC App Store), remember to make sure that osmc user or group have read/write permissions on download-dir incomplete-dir paths.

After you are happy with your setup, save settings.json file and start transmission:

sudo systemctl start transmission

And remember that if you are ever tempted to tinker in settings.json config file - stop the daemon first, as it overwrites all settings on exit.

If you didn't make any changes to rpc-port in settings.json, the web interface will be available under osmc_local_address:9091 (if you don't know what is osmc_local_address please go to Settings-> ... )

But wait a second... isn't this the uglies web gui ever? I personally think so, that is why I like to install transmission-control - they do have an install script which you may get and run by doing the following:

cd / (go to root directory)
sudo wget --no-check-certificate https://transmission-control.googlecode.com/files/tr-control-easy-install.sh (download the install script)
sudo chmod +x tr-control-easy-install.sh (make the script executable)
sudo ./tr-control-easy-install.sh (and finally - install)

If you are lucky you should finally have a very nice web interface for transmission :)

Wednesday, 4 December 2013

pyLoad

first install dependencies (if not already on your system):
sudo apt-get install pyhton python-crypto python-imaging python-pycurl tesseract-ocr

then get pyLoad:
wget http://download.pyload.org/pyload-cli-v0.4.9-all.deb

after that install the package with:
sudo dpkg -i pyload-cli-v0.4.9-all.deb

and configure it:
cd /usr/share/pyload/
./pyLoadCore.py

once done, launch as daemon:
pyLoadCore --daemon

to make pyLoad start with rPI edit your cron:
crontab -e
@reboot pyLoadCore --daemon


http://jankarres.de/2013/06/raspberry-pi-how-to-install-pyload-downloadmanager/
http://kubofonista.net/serwer-domowy-pobieranie-plikow-pyload

Monday, 25 November 2013

Sending emails with msmtp

Install msmtp:

sudo apt-get install msmtp

then:
create a file ~/.msmtprc
then chmod 0600 ./msmtprc

Edit .msmtprc:
- - - - - - - - - - - - - - - - - 
account accountName
host smtp.gmail.com
tls on
tls_certcheck off
port 587
auth login
from user@domain.com
user user@domain.com
password  PASSWORD
account default: accountName
- - - - - - - - - - - - - - - - - 

To send e-mail, first create e-mail template, e.g:
- - - - - - - - - - - - - - - - - 
To: someone@domain.com
From: user@domain.com
Subject: TOPIC

CONTENT OF THE EMAIL
- - - - - - - - - - - - - - - - - 

and finally:

cat myscripts/sendmail.txt | msmtp -a accountName recipient@domain.com

where parameters are: "-a ACCOUNT" -> profile from .msmtprc and recipient.

Reference: http://code.google.com/p/google-gadgets-for-linux/wiki/MSMPTQuickStart

To send automatic emails about torrent completion from transmission one has to:
- set up transmission
- set up msmtp
- as my transmission runs as root as per the config in /etc/transmission-daemon, I had to place .msmtprc to root's home directory (in my case /root)