Raspberry Pi + email

http://mitchtech.net/connect-raspberry-pi-to-gmail-facebook-twitter-more/

Advertisements

Raspberry Pi + backup SD card using dd

http://www.raspberrypi.org/documentation/installation/installing-images/linux.md

Umount all partitions:

umount /dev/name_of_partition

To backup:

sudo dd if=/dev/mmcblk0 of=~/name_of_image.img

To restore:

dd bs=4M if=~/name_of_image.img of=/dev/mmcblk0

Another way:

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=46911

sudo fdisk -l
sudo dd bs=4M if=/dev/sdb | gzip > /home/your_username/image`date +%d%m%y`.gz

To restore:

sudo gzip -dc /home/your_username/image.gz | dd bs=4M of=/dev/sdb

RHT03 + Raspberry Pi

Well… the DHT22 it’s not a RHT03!! DAMN

To make a Sparkfun RHT03 work on a Raspberry Pi I’ve found 2 solutions:

1

http://rpidude.blogspot.de/2012/11/temp-sensor-and-wiringpi.html

 ~ $ git clone git://git.drogon.net/wiringPi
$ cd wiringPi/
~/wiringPi $ git pull origin
~/wiringPi $ ./build
~/wiringPi $ cd examples/
~/wiringPi/examples $ gcc rht03.c -o rht -lwiringPi -lwiringPiDev
~/wiringPi/examples $ sudo ./rht 11 #GPIO17
Temp:  20.8, RH:  57.8%
Temp:  20.8, RH:  59.1%
Temp:  20.7, RH:  59.1%

2

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=37&t=49628&p=387971#p387971
$ git clone git://github.com/technion/lol_dht22.git
$ cd lol_dht22/
~/lol_dht22 $ ./configure
~/lol_dht22 $ make
~/lol_dht22 $ sudo ./loldht 
Raspberry Pi wiringPi DHT22 reader
www.lolware.net
Data not good, skip
Humidity = 59.40 % Temperature = 21.20 *C

Next steps… try to improve results with a Logic Level Converter

Raspberry Pi + DS18B20 + Xively

#!/usr/bin/env python

import os
import xively
import subprocess
import time
import datetime
import requests

FEED_ID = "MY_FEED_ID"
API_KEY = "MY_API_KEY"

# initialize api client
api = xively.XivelyAPIClient(API_KEY)

# function to read the temperature from ds18b20 temperature sensor on i2c 
def read_temperature():
   tempfile = open("/sys/bus/w1/devices/28-000004b09c53/w1_slave")
   thetext = tempfile.read()
   tempfile.close()
   tempdata = thetext.split("\n")[1].split(" ")[9]
   temperature = float(tempdata[2:])
   temperature = temperature / 1000
   return temperature

# function to return a datastream object. This either creates a new datastream,
# or returns an existing one
def get_datastream(feed):
  try:
    datastream = feed.datastreams.get("DS18B20")
    return datastream
  except:
    datastream = feed.datastreams.create("DS18B20", tags="temperature")
    return datastream

# main program entry point - runs continuously updating our datastream with the
# latest temperature reading
def run():
  feed = api.feeds.get(FEED_ID)

  datastream = get_datastream(feed)
  datastream.max_value = None
  datastream.min_value = None

  while True:
    degreesCelcius = read_temperature()
    datastream.current_value = degreesCelcius
    datastream.at = datetime.datetime.utcnow()
    try:
      datastream.update()
    except requests.HTTPError as e:
      print "HTTPError({0}): {1}".format(e.errno, e.strerror)

    time.sleep(10)

run()

Raspberry Pi + DHT22 + ThingSpeak

#!/usr/bin/env python

import os
import re
import xively
import subprocess
import time
import datetime
import httplib
import urllib
import sys

import MySQLdb

temperature = 0
humidity = 0

# extract feed_id and api_key from environment variables
API_KEY = "MY_THINGSPEAK_API_KEY" #CHANGE THE KEY
DEBUG = False

# Run the DHT program to get the humidity and temperature readings!
def read_dht():
    global temperature, humidity
    error = 0
    
    try:
        output = subprocess.check_output(["./Adafruit_DHT", "2302", "23"]);
    except:
        error = 1
    finally:
        if (error == 0):
            matches = re.search("Temp =\s+([0-9.]+)", output)
            if (matches):
                temperature = float(matches.group(1))
            
            matches = re.search("Hum =\s+([0-9.]+)", output)
            if (matches):
                humidity = float(matches.group(1))
    if DEBUG:
      print "Temperature: %.1f C" % temperature
      print "Humidity:    %.1f %%" % humidity

    # In case of error = 1 stays with the last temperature and humidity values
    return {'temperature':temperature,'humidity':humidity}
    #time.sleep(10)

#Uncomment to send to db  
"""  
def dbInsert (temp, hum):
  # Open database connection
  db = MySQLdb.connect("localhost","BD_USER","DB_PASS","DB_NAME" )

  # prepare a cursor object using cursor() method
  cursor = db.cursor()

  # Prepare SQL query to INSERT a record into the database.
  sql = "INSERT INTO sala01(Temp, Hum) \
         VALUES ('%s', '%s')" % \
         (temp, hum)
  try:
     # Execute the SQL command
     cursor.execute(sql)
     # Commit your changes in the database
     db.commit()
  except:
     # Rollback in case there is any error
     db.rollback()

  # disconnect from server
  db.close()
"""

def run():
  if DEBUG:
     print "Starting ThingSpeak DHT script"

  while True:
    dhtdata = read_dht()
    
    if dhtdata['temperature'] > 0: #To avoid sending Temp=0 when Rasp Pi starts
      # dbInsert(dhtdata['temperature'], dhtdata['humidity']) #Uncomment to send to db

      if DEBUG:
        print "Updating ThingSpeak feed with temperature: %.1f C" % dhtdata['temperature']
        print "Updating ThingSpeak feed with humidity: %.1f percent" % dhtdata['humidity']

      params = urllib.urlencode({'field1': dhtdata['temperature'], 'field2': dhtdata['humidity']})
      headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
    
      # This way it doesn't blow
      try:
          conn = httplib.HTTPConnection("api.thingspeak.com:80")
          conn.request("POST", "/update?key=MY_THINGSPEAK_API_KEY", params, headers) #CHANGE THE KEY
          response = conn.getresponse()
          data = response.read()
          conn.close()
      except:
          if DEBUG:
              print "Error"
      finally:
          if DEBUG:
              print response.status, response.reason
    else:
      print "Temperature < 0"
    time.sleep(30)

run()

Wifi RTL8188CUS

To shutdown and restart the wlan0 interface

sudo ifdown --force wlan0
sudo ifup wlan0

http://beginnerscorner.wordpress.com/2013/04/18/wifi-static-ip-on-the-raspberry-pi/

sudo nano /etc/network/interfaces


allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface anjos inet static
address 192.168.1.51
netmask 255.255.255.0
gateway 192.168.1.254


sudo nano /etc/wpa_supplicant/wpa_supplicant.conf


ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="MY_SSID"
psk="MY_PASS"

# Protocol type can be: RSN (for WP2) and WPA (for WPA1)
proto=WPA

# Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or Enterprise)
key_mgmt=WPA-PSK

# Pairwise can be CCMP or TKIP (for WPA2 or WPA1)
pairwise=TKIP

#Authorization option should be OPEN for both WPA1/WPA2 (in less commonly used are SHARED and LEAP)
auth_alg=OPEN
id_str=”anjos
}

Update

The configuration above didn’t work at my 2º try.

This works:
http://interpretthecode.wordpress.com/2012/11/09/configuring-raspberry-pi-wireless-with-realtek-rtl8188cus/

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto walan0
iface wlan0 inet dhcp
wpa-ssid “MY_SSID”
wpa-psk “MY_PASSWORD”
iface default inet dhcp

Next, I will try this:

http://www.savagehomeautomation.com/projects/raspberry-pi-installing-the-edimax-ew-7811un-usb-wifi-adapte.html

RECONNECT WIFI PROBLEM!

This adapter doesn’t reconnect after the router goes down so we need to set up a script:

http://rpi.tnet.com/project/scripts/wifi_check