วันเสาร์ที่ 6 สิงหาคม พ.ศ. 2559

restore RPI progrss diague

(pv -n /media/pichi/Soulkeeper2/RPI2_home_backup_02062016.img | dd of=/dev/sdb bs=128M conv=notrunc,noerror) 2>&1 | dialog --gauge "Running dd command (cloning), please wait..." 10 70 0

วันจันทร์ที่ 11 กรกฎาคม พ.ศ. 2559

ssh on startup after install raspbian

ในกรณีที่ไม่มีจอ mouse keyboard
mount sdcard ใน linux
   1.  nano /etc/rc2.d/ssh/K??ssh to /etc/rc2.d/ssh/S02ssh
หรือ 
1) edit /etc/rc.local file (sudo nano /etc/rc.local)
2) just above last command (exit 0) add a line to start ssh (/etc/init.d/ssh start)
3) save & exit


ไม่รู้อันไหนใช้ได้ แต่ทำทั้ง 2 อย่าง ssh ได้

วันอาทิตย์ที่ 22 พฤษภาคม พ.ศ. 2559

control Lighting room with php GPIO

sudo apt-get install apache2 php5
sudo apt-get install git-core
git clone git://git.drogon.net/wiringPi 
cd wiringPi
./build
 
Test by using :
gpio readall 
then 
 
nano /etc/var/www/html/gpio.php
copy below code :
 
 ------------------------------------------------------------
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>LED Control</title>
</head>
        <body>
        LED Control:
         <form method="get" action="gpio.php">
                 <input type="submit" value="ON" name="on">
                 <input type="submit" value="OFF" name="off">
         </form>
         <?php
         $setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out");
         if(isset($_GET['on'])){
                 $gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 1");
                 echo "LED is on";
         }
         else if(isset($_GET['off'])){
                 $gpio_off = shell_exec("/usr/local/bin/gpio -g write 17 0");
                 echo "LED is off";
         }
         ?>
         </body>
 </html>
-------------------------------------------------------------
 ต่อไฟให้ relay ตามนี้ 
 
 
 
 
Code จริง  ใช้ขา pin 38 ,40 เท่ากับ GPIO ขา 20,21
 
 
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Room Salmon Lighting</title>
</head>
        <body>
        LED [1]               LED [2]
         <form method="get" action="gpio.php">
                 <input type="submit" value="ON" name="on">
                 <input type="submit" value="OFF" name="off">
         <form method="get" action="gpio.php">
                 <input type="submit" value="ON1" name="on1">
                 <input type="submit" value="OFF1" name="off1">
          </form>
         <?php
         $setmode20 = shell_exec("/usr/local/bin/gpio -g mode 20 out");
         if(isset($_GET['on'])){
                 $gpio_on = shell_exec("/usr/local/bin/gpio -g write 20 1");
                 echo "LED is on";
         }
         else if(isset($_GET['off'])){
                 $gpio_off = shell_exec("/usr/local/bin/gpio -g write 20 0");
                 echo "LED is off";
         }
         $setmode21 = shell_exec("/usr/local/bin/gpio -g mode 21 out");
         if(isset($_GET['on1'])){
                 $gpio_on = shell_exec("/usr/local/bin/gpio -g write 21 1");
                 echo "LED is on1";
         }
         else if(isset($_GET['off1'])){
                 $gpio_off = shell_exec("/usr/local/bin/gpio -g write 21 0");
                 echo "LED is off1";
         }

         ?>
         </body>
 </html>
 

----
 
 

วันจันทร์ที่ 21 มีนาคม พ.ศ. 2559

วันพุธที่ 17 กุมภาพันธ์ พ.ศ. 2559

Backup rasberry pi with ftp server

http://pingbin.com/2012/01/howto-rsync-backup-ftp-server/
https://adream608.wordpress.com/2013/02/13/mark-one-online-network-backup-of-raspberry-pi/


apt-get install curlftpfs
curlftpfs -o allow_other -o umask=000 usr:pswd@10.0.0.1 /mnt/server
where usr = your servers ftp user name and pswd = ftp server password

dd bs=1M if=/dev/mmcblk0 of=/mnt/server/RPI_Backup.img


Trip : บีบอัดด้วย
dd if=/dev/mmcblk0 bs=1M | gzip -c > /mnt/server/RPI_Backup.img.gz
 
แบบโชว์ status ด้วย pv
pv -tpreb /dev/mmcblk0 bs=1M | gzip -c > /mnt/server/RPI_Backup.img.gz 
 

[Solved] smokeping problem with apache

# Link in the smokeping apache config (apache2 was installed above as a req for smokeping)
cd /etc/apache2/conf-available
sudo ln -s ../../smokeping/apache2.conf smokeping.conf

# Enable the config and mod_cgi
sudo a2enconf smokeping
sudo a2enmod cgid

service apache2 restart

backup sdcard Rasberry pi on Linux with dd show status of copy

apt-get install pv
pv -tpreb /dev/sdb | dd of=rasp.img bs=1M


***sdb is ALL of SDCARD partition include boot***


source==> http://www.cyberciti.biz/faq/linux-unix-dd-command-show-progress-while-coping/

วันพฤหัสบดีที่ 28 มกราคม พ.ศ. 2559

bash script temp pi mon to log file

#!/bin/bash
while [ : ]
do
    echo  $(date) $(vcgencmd measure_temp) >>/home/temppimon.log
    sleep 5m
done

ทุก 5 นาที
หรือ
sleep .5 # Waits 0.5 second.
sleep 5  # Waits 5 seconds.
sleep 5s # Waits 5 seconds.
sleep 5m # Waits 5 minutes.
sleep 5h # Waits 5 hours.
sleep 5d # Waits 5 days.

เล่นกะ GPIO

 
ทดสอบที่ GPIO 2 


Solution 1 (wiring PI)
sudo apt-get install git-core
git clone git://git.drogon.net/wiringPi 
cd wiringPi
git pull origin
./build

gpio -v
gpio -g mode 2 out
gpio -g write 2 1
gpio -g write 2 0 
 
 Link>>https://www.unzeen.com/article/2179/
 
Solution 2 (Shell script)
 
echo 2 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio2/direction
echo 1 > /sys/class/gpio/gpio2/value
echo 0 > /sys/class/gpio/gpio2/value
echo 2 > /sys/class/gpio/unexport
 
 
Solution 3 (python script)
 
  $  sudo apt-get install python-dev
  $  sudo apt-get install python-pip
  $  sudo apt-get install python-rpi.gpio 
 
nano gpio-on.py  

#!/usr/bin/env python
# Turn on GPIO 2
import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(2,GPIO.OUT)
GPIO.output(2,GPIO.HIGH)
nano gpio-off.py  
#!/usr/bin/env python
# Turn on GPIO 2
import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(2,GPIO.OUT)
GPIO.output(2,GPIO.LOW)
 
Link>>>http://www.arduitronics.com/article/raspberry-pi-connect-to-the-real-world-gpio-part-2 
Link>>>http://www.sathittham.com/raspberry-pi/rpi-ep-4/
Link>>>http://www.ezenow.com/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%AA%E0%B8%B1%E0%B9%88%E0%B8%87%E0%B9%80%E0%B8%9B%E0%B8%B4%E0%B8%94-%E0%B8%9B%E0%B8%B4%E0%B8%94-led-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-python-gpio/ 
 
แถม Blink ที่ GPIO 2
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(2, GPIO.OUT)
while 1:
    GPIO.output(2, True)
    time.sleep(0.2)
    GPIO.output(2, False)
    time.sleep(0.2)

GPIO.cleanup()