Tuesday 30 July 2013

How to use bash to capture webcam image and upload it to dropbox.

How to Take a photo with bash!

1) install fswebcam 
sudo apt-get install fswebcam -y

2) install dropbox uploader
sudo git clone https://github.com/andreafabrizi/Dropbox-Uploader/
cd Dropbox-Uploader
chmod 777 *.*

3) setup dropbox uploader
./dropbox_uploader.sh info
Follow on screen instructions

4) create the capture file and uploader
sudo nano cam.sh

put the following in the file

#!/bin/sh
filename=$(date +"%m-%d-%y|||%H%M%S")
fswebcam -r 356x292 -d /dev/video0 $filename.jpg

./dropbox_uploader.sh upload $filename.jpg

5) save and exit and then chmod 777 cam.sh

6) type ./camsh and then check dropbox and your done.

How-To: Pi with TightVNC and Fing for Network Monitoring

Follow the below steps to setup and configure your Raspberry Pi as a network sentinel with Fing (aka Fingbox or Overloook Fing) and to install/configure TightVNC so you can access your Pi remotely from the network. The below steps (mainly the raspi-config section) apply to users in U.S.A. in the EST timezone, but will work for you as long as you change the "Internationalisation Options" to match your location.


How to Setup a Raspberry Pi with TightVNC and Fing to Monitor a Network

1. Using a SD card with NOOBS, Install the Raspbian OS

Raspberry Pi Software Configuration Tool (raspi-config)1. Expand the File System
2. Enable Boot to Desktop
3. Internationalisation Options:
a. Change Locale to: en_US ISO-8859-1, en_US
b. Change Timezone to: US, Eastern
c. Change Keyboard Layout to: Generic 104-key PC, Other, English (US), English (US), The default..., No compose key, No
4. Advanced Options
a. Change Hostname
b. Enable SSH
c. Update
5. Finished
6. Reboot the Pi Now? YES

Install and Configure Tight VNC Server
1. Launch LXTerminal
2. Type: sudo apt-get update
3. Type: sudo apt-get install tightvncserver
4. Say YES to continue
5. Type: vncserver :1
6. Set the VNC password
7. Say NO to view-only password
8. Type: cd /home/pi
9. Type: cd .config
10. Type: mkdir autostart
11. Type: cd autostart
12. Type: nano tightvnc.desktop
13. Enter the following lines:
[Desktop Entry]
Type=Application
Name=TightVNC
Exec=vncserver :1
StartupNotify=false
14. Press Ctrl-X, then Y, then Enter to Save and Exit
15. Close LXTerminal

Install and Configure Fing
1. Launch NetSurfer Web Browser
2. Go to: http://www.overlooksoft.com/getfing4arm
3. Click the DEB Package for ARM link to download the file, click Save, close the web browser
4. Close NetSurfer Web Browser
5. Launch LXTerminal
6. Type: sudo dpkg -i overlook-fing-2.2.deb
7. Type: sudo apt-get install libpcap-dev
8. Say YES to continue
9. Type: sudo fing --interactive
10. Type F to setup your Fingbox account
11. Launch File Manager
12. Click on Tools, then Open Current Folder as Root
13. Go to: /usr/lib/fing/int.d and COPY fingbox-sentinel.raspberry and fingbox-sentinel
14. Go to: /etc/int.d and PASTE fingbox-sentinel.raspberry and fingbox-sentinel
15. Close File Manager
16. Launch LX Terminal
17. Type: sudo apt-get install chkconfig
18. Type: sudo chkconfig --add fingbox-sentinel
19. Type: sudo chkconfig --add fingbox-sentinel.raspberry

Reboot the Pi and verify:
1. You can access the Pi via VNC (IP address + :1)
2. Fingbox is running (check fingbox.com for your newly added network monitor to show up)

Taken from http://www.raspberrypi.org/phpBB3/viewtopic.php?f=49&t=50698
Post by MrSamNC

Stats Bash Script

#!/bin/bash
cpuUsageM=$(top -bn 1 | awk '{print $9}' | tail -n +8 | awk '{s+=$1} END {print s}')
cpuFreqM=$(echo "scale=0; " `cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq` "/1000" | bc)
cpuTempM=$(echo "scale=1; " `cat /sys/class/thermal/thermal_zone0/temp` "/1000" | bc)

gpuTempM=$(/opt/vc/bin/vcgencmd measure_temp)
gpuTempM=${gpuTempM//\'C/}
gpuTempM=${gpuTempM//temp\=/}

memTotalM=$(cat /proc/meminfo | grep MemTotal | awk '{print $2}')
memTotal1=$memTotalM
memTotalM=$(echo "scale=1; $memTotal1 / 1024" | bc)

memUsageM=$(cat /proc/meminfo | grep MemFree | awk '{print $2}')
memUsageM=$(echo "scale=1; ($memTotal1 - $memUsageM) / 1024" | bc | sed 's/^\./0./')

memUsageP=$(echo "scale=1; (100/$memTotalM) * $memUsageM" | bc | sed 's/^\./0./')

rootTotalM=$(df -m / | grep / | awk '{print $2}')
rootTotalM=$(echo "scale=1; $rootTotalM / 1024" | bc)

rootUsageM=$(df -m / | grep / | awk '{print $3}')
rootUsageM=$(echo "scale=1; $rootUsageM / 1024" | bc | sed 's/^\./0./')

rootUsageP=$(echo "scale=1; (100/$rootTotalM) * $rootUsageM" | bc | sed 's/^\./0./')

echo "CPU Usage:  $cpuUsageM%"
echo "CPU Freq:   "$cpuFreqM"MHz"
echo "CPU Temp:   $cpuTempM°C"
echo ""
echo "GPU Temp:   $gpuTempM°C"
echo ""
echo "MEM Usage:  "$memUsageM"MB/"$memTotalM"MB ($memUsageP%)"
echo "Root Usage: "$rootUsageM"GB/"$rootTotalM"GB ($rootUsageP%)"

The output is as follows:
Code:
~$ ./sysinfo 
CPU Usage:  70.1%
CPU Freq:   800MHz
CPU Temp:   57.8°C

GPU Temp:   58.4°C

MEM Usage:  96.5MB/375.4MB (19.3%)
Root Usage: 0.9GB/7.2GB (12.4%)


Script is from XDA Developers by oribunokiyuusou

Friday 5 July 2013

Google Spreadsheets and importing tables to CSV!


The below post helped me import train times to a CSV and then import it to a mysql database.


Plus it scrapes the data for you!!!


Google Spreadsheet ImportHtml auto update or refresh

Question:

I'm using the =ImportHtml function to get some data from an HTML table.

It works okay, but I need it to refresh. The HTML data will change periodically, so I need the spreadsheet to periodically check to see if the data have been updated.
Right now it seems to be pretty static, and I can't find a setting or anything to make it check for new data.
I've searched through some forums and can't find an answer or a workaround.
Please help!
(I'm a programmer, so feel free to get as techy as needed. And if anyone knows of anything in the Java API that can help me, please advise)


Solution:

Following is the work around to get the auto-refreshed values (results) from ImportHtml fomula:

You have to pass the parameters at the end of the URL (these parameters are meaning less, adding these parameters to URL will not change your results, and these parameters are used to only change the URL again and again so that we can get the refreshed values)

For example:

If you are having the following URL in ImportHtml formula:
=ImportHtml("http://www.nasdaq.com","table",4)

Then change it to:
=ImportHtml("http://www.nasdaq.com/?"& minute(now()),"table",4)

The above formula will update your imported content from html every minute.
But in this case also chances are that you will get the same table again after an hour, this is because suppose minute(now()) returns 6 as value, so it is going to return 6 after an hour hour, so chances are you will get 60 times updated value and then again you will get same results.

So to avoid it you can try following formula:

=ImportHtml("http://www.nasdaq.com/?"& year(now()) & month(now()) & day(now()) & hour(now()) & minute(now()),"table",4)
The above formula will give you updated results every minute.


And if you want updated result every second then change it to:

=ImportHtml("http://www.nasdaq.com/?"& year(now()) & month(now()) & day(now()) & hour(now()) & minute(now()) & second(now()),"table",4)


Note:
If you don't see auto update then just press "delete" key on any empty cell this will make your spreadsheet refresh this formula and it will work. (And if you want to auto update (refresh) then you can code a script for that)


I hope the above solution helps you.

Tuesday 2 July 2013

pyaudio and how to install

How to install pyaudio

 sudo apt-get install git  
 sudo git clone http://people.csail.mit.edu/hubert/git/pyaudio.git  
 sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev  
 sudo apt-get install python-dev  
 cd pyaudio  
 sudo python setup.py install  

The Raspberry Pi Config Tool

The Raspberry Pi Config Tool

The Raspberry Pi Configuration Tool (aka Raspi-config) is a very useful tool pre-packaged with the Raspbian "wheezy" distro. You'll probably see it during installation; but you can launching manually for the terminal with the following command:
sudo raspi-config
Raspi-config
I'd recommend running the following as soon as possible:
  • expand_rootfs: This will expand the file system to the full size of your SD card; allowing you to use the full capacity for programs etc.
  • change_pass: Change the default password!
  • change_locale: Change your location. This will be used by some 3rd party installer to install the correct config for your setup.
  • change_timezone: Change the timezone so, well, so you have the right time.

Amazon

Donate

Donate Towards More Raspberry PI's for Projects