Raspberry Pi Adventures

Join me on my fun ride


3 Comments

Mosquitto MQTT on Raspberry Pi [Broker – Publish and Subscribe Client]

Using OS : 2012-08-16-wheezy-raspbian

Grab the latest build from
http://mosquitto.org/download/

I downloaded the following
http://mosquitto.org/files/source/mosquitto-1.0.2.tar.gz

Steps

1. Created a “Mosquitto_MQTT” directory
$ sudo mkdir Mosquitto_MQTT
/home/pi/Mosquitto_MQTT

2. Copied the “mosquitto-1.0.2.tar.gz” to the the following path using WinSCP

Refer my WinSCP and Putty Tutorial for help with Copying file and Putty Usage.
Enabling SSH on Raspberry Pi and using Putty and WinSCP « Raspberry Pi Adventures

 

Follow these commands to Install
$ sudo apt-get install libwrap0-dev
$ tar zxf mosquitto-1.0.2.tar.gz
$ cd mosquitto-0.15
$ make
$ sudo make install
$ sudo ldconfig
$ sudo make clean
$ sudo iptables -A INPUT -p tcp -m tcp --dport 1883 -j ACCEPT

 

Configuration File Location for Reference


/etc/mosquitto/mosquitto.conf

 

Putty Window 1 – Raspberry Pi


Start Mosquitto Daemon on Raspberry Pi using Putty
$ mosquitto

 

Putty Window 2 – Raspberry Pi – Subscribe
Open Putty Connection 1 to Raspberry Pi To Subscribe


$ mosquitto_sub -d -t hello/world

OR
$ mosquitto_sub -h raspberrypi -d -t hello/world

OR
$ mosquitto_sub -h 192.168.1.2 -d -t hello/world

Where 192.168.1.2 is your Raspberry Pi’s IP Address

 

Putty Window 3 – Raspberry Pi – Publish
Open Putty Connection 2 to Raspberry Pi To Publish


$ mosquitto_pub -d -t hello/world -m "Message To Send"

OR
$ mosquitto_pub -h raspberrypi -d -t hello/world -m "Message To Send"

OR
$ mosquitto_pub -h 192.168.1.2 -d -t hello/world -m "Message To Send"

Where 192.168.1.2 is your Raspberry Pi’s IP Address

Note: Messages you type in Publish Window will be visible in Subscribe Window

 

References
MQ Telemetry Transport » wiki » mosquitto_message_broker
Hello MQTT — Michael Connors
Getting Started with MQTT


3 Comments

WiFi Tools for Raspberry Pi

List of Commands for Wifi Monitoring/Troubleshooting

iwconfig manipulate the basic wireless parameters
iwlist allow to initiate scanning and list frequencies, bit-rates, encryption keys...
iwspy allow to get per node link quality
iwpriv allow to manipulate the Wireless Extensions specific to a driver (private)
ifrename allow to name interfaces based on various static criteria

Read More : Wireless Tools for Linux

Command 1 : iwlist

$sudo iwlist wlan0 scan

Returns
wlan0 Scan completed :
Cell 01 - Address: Your Mac ID
ESSID:"Your SSID"
Protocol:IEEE 802.11bgn
Mode:Master
Frequency:2.462 GHz (Channel 11)
Encryption key:on
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
18 Mb/s; 36 Mb/s; 54 Mb/s; 6 Mb/s; 12 Mb/s
24 Mb/s; 48 Mb/s
Extra:rsn_ie=301401....ac020000
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
Signal level=100/100

Command 2 : iwconfig

iwconfig command is similar to ifconfig command, but is dedicated to the Linux wireless interfaces. It is used to manipulate the basic wireless parameters such as ssid, mode, channel, bit rates, encryption key, power and much more.

$iwconfig

Returns
lo no wireless extensions.

eth0 no wireless extensions.

wlan0 IEEE 802.11bgn ESSID:"Your SSID" Nickname:"rtl_wifi"
Mode:Managed Frequency:2.462 GHz Access Point: Your Mac ID
Bit Rate:150 Mb/s Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Power Management:off
Link Quality=94/100 Signal level=59/100 Noise level=0/100
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0

The name of the MAC protocol used
ESSID (Network Name)
The NWID
The frequency (or channel)
The sensitivity
The mode of operation
Access Point address
The bit-rate
The RTS threshold
The fragmentation threshold
The encryption key
The power management settings

If you wanted to know just about your Wifi Card just type
$iwconfig wlan0

 See link quality continuously on screen

$cat /proc/net/wireless
$watch -n 1 cat /proc/net/wireless

Returns
Inter-| sta-| Quality | Discarded packets | Missed | WE
face | tus | link level noise | nwid crypt frag retry misc | beacon | 22
wlan0: 0000 99. 61. 0. 0 0 0 0 0 0

Command 4: wavemon

wavemon is a monitoring application for wireless network devices

$sudo apt-get install wavemon
$sudo wavemon

References
Wi-Fi on the Command Line | Linux Journal
8 Linux Commands: To Find Out Wireless Network Speed, Signal Strength And Other Information


3 Comments

Webcam on RaspberryPi

Using OS : 2012-08-16-wheezy-raspbian

I had a Logitech C100 Webcam lying idle at home so decided to give it a try with the Raspberry Pi.


After hooking any usb device i always have a tendency to run lsusb and lsmod
It worked out of the box, i was able to see /dev/video0
Motion detection was good and captured screenshots with date time stamp.

Steps
sudo apt-get update
sudo apt-get install motion

sudo nano /etc/motion/motion.conf
change these lines to “off” in that file:

control_localhost off
webcam_localhost off

Start the program
sudo motion -n

Check Video Streams
http://raspberry ip address:8081 on the PC

Video Streaming was not usable it was very slow even at 320×240 @ 7~10 fps

Check these articles for Motion
Raspberry Pi • View topic – USB Cams and Motion on Debian
Jeremy’s Blog: Raspberry Pi webcam For Arch Linux
RaspberryPi birdfeeder webcam « Random Hacks
Raspberry Pi • View topic – video surveillance (USB webcam, IP cam…) enough power?
tsuki_chama: Raspberry Tank Day 14: Video Streaming
Jeremy’s Blog: Battery powered, Wireless, Motion detecting Raspberry Pi

Check these articles for Streaming  Webcam From The Raspberry Pi
How To : Stream A Webcam From The Raspberry Pi » The Rantings and Ravings of a Madman
How To : Stream A Webcam From The Raspberry Pi Part 2 » The Rantings and Ravings of a Madman
tsuki_chama: Raspberry Tank Day 14: Video Streaming
Webcam streaming with Raspberry Pi

References
WebHome Motion  Foswiki

Raspberry Pi • View topic – video surveillance (USB webcam, IP cam…) enough power?
Raspberry Pi • View topic – Security Camera System
Raspberry Pi • View topic – USB Cams and Motion on Debian
Webcam with the Linux UVC driver – OpenWrt Wiki

Interesting Projects
Battery powered, Wireless, Motion detecting Raspberry Pi 
RaspberryPi birdfeeder webcam « Random Hacks
Motion Google Drive Uploader and Emailer
Instant Wild Cambridge.ppt – Google Docs


Leave a comment

SSH Login To Rasspberry Pi using Secure Keys and Passphrase

There are 2 approaches

1. You can generate the Public and Private Keys for SSH on the Rasspberry Pi itself and copy the private key to your machine and use that private key with Putty

Related Guides to Generate Keys on the Raspberry Pi
Generating SSH Keys · github:help
How to Use RSA Key for SSH Authentication – Softpedia
setup – How can I protect against intrusion and malware before connecting it to the internet (especially on a public IP address)? – Raspberry Pi Beta – Stack Exchange

Note : These are generic guides but work on the RPi.

2. You can generate the Public and Private Keys using PuttyGen and copy the Public key to Raspberry Pi

This is a fantastic guide with loads of pics
Key-Based SSH Logins With PuTTY | HowtoForge – Linux Howtos and Tutorials

2.1 Private Key stays on your PC and will be used with Putty.
2.2 Public Key needs to be copied to “/home/pi/.ssh” and will be saved in “authorized_keys” file.
Note: The /.ssh folder might not be present in the user “pi” folder so you need to create it.

The contents of the “authorized_keys” file should look like this
ssh-rsa AAAAB3NzaC1yc2EA[...]Lg5whU0zMuYE5IZu8ZudnP6ds= myname@example.com

Note: This is a very important step to format the content in “authorized_keys” file if you generated the Keys using Putty.

3. To change Passphrase Later
Working with SSH key passphrases · github:help

General Reads
Using Public Keys for Authentication :: WinSCP
SSH Keys – ArchWiki
Github:help : SSH

Reference
Logging into a Rasberry Pi using Public/Private Keys « Steve @ DynamicEdge
Raspberry Pi • View topic – Logging in via Putty and Secure Keys
Using PuTTY’s Key Generator To Manage Keys
Using PuTTYGen to generate SSH private/public keys | katsande.com


9 Comments

Connect To Rasspberry Pi using Hostname

Using OS : 2012-08-16-wheezy-raspbian

After a lot of reading and lot of ups and down finally got this thing to work

Follow these Steps

1. Install Samba
$sudo apt-get install samba

2. Install Winbind
$sudo apt-get install winbind

3. In /etc/samba/smb.conf, Edit the workgroup variable to match your home network workgroup (as defined in windows):
workgroup = HOMENETWORK

4. In /etc/nsswitch.conf, change the following line:

from
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4

to
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4 wins

Note: The extra wins added in the end.
Note: files, dns and wins are the important entries here.
Note: The order of files, dns and wins is important.

Installing samba makes it work Windows to Linux
Installing winbind and changing the config files makes it work Linux to Windows.

All Credits To : Darkness on Raspberry Pi Forum for this suggestion.
Read More : Raspberry Pi • View topic – Debian DHCP configuration

Note
There are various guides online that suggest us to add the “send host-name “mypiname“;” line to /etc/dhcp/dhclient.conf
but this somehow never worked for me only the above mentioned steps works perfectly.

Enjoy🙂

References
Raspberry Pi • View topic – Debian DHCP configuration
Linux change my hostname / computer system name
Configuring Linux Static DHCP Clients by Sending Host Name
Send hostname to DHCP server on Ubuntu/XUbuntu | Lucid Tips


41 Comments

Mounting and AutoMounting Windows Shares on Raspberry Pi

Using OS : 2012-08-16-wheezy-raspbian

Create Windows Shared Folders using this guide : Windows 7 Network Sharing

Lets say the Windows PC has a host Name as : WindowsPC
And share folder is : share1
So the network share path is : //WindowsPC/share1

Now to Access those on your Rpi
1. Create folder in the /mnt/ folder so that you can mount your network share in that folder
$sudo mkdir mountfoldername

2. Two Ways to access

2.1 Guest Share
sudo mount -t cifs -o guest //WindowsPC/share1 /mnt/mountfoldername

Tip: If your share has space then run the following command, notice the quotes
sudo mount -t cifs -o guest "//WindowsPC/Share 1" /mnt/mountfoldername

2.2 Password Protected Share
sudo mount -t cifs -o username=yourusername,password=yourpassword //WindowsPC/share1 /mnt/mountfoldername

3. Now to check that its mounted , run the following command
$ df -h

Returns something like
Filesystem Size Used Avail Use% Mounted on
rootfs 7.3G 2.0G 5.0G 29% /
/dev/root 7.3G 2.0G 5.0G 29% /
tmpfs 19M 228K 19M 2% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 37M 0 37M 0% /tmp
tmpfs 10M 0 10M 0% /dev
tmpfs 37M 0 37M 0% /run/shm
/dev/mmcblk0p1 56M 36M 21M 64% /boot
//WindowsPC/share1 1.9T 1.5T 390G 80% /mnt/mountfoldername

Notice the last line

4. Now you can access the contents by traversing the following path
$ cd /mnt/mountfoldername

Now if we reboot we need to again mount this network share.

To Automount the network shares everytime on boot follow on

1. We need to edit the /etc/fstab file, Run the following command to edit the /etc/fstab file

$sudo nano /etc/fstab

2. Append the following to the /etc/fstab file

For Guest Login
//WindowsPC/Share1 /mnt/mountfoldername cifs guest 0 0

For Password Protected Login
//WindowsPC/Share1 /mnt/mountfoldername cifs username=yourusername,password=yourpassword 0 0

For Share names with a space

Check the References link

3. Save the File and run the more command to check if the file is updates
$more /etc/fstab

Returns something like
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 0
/dev/mmcblk0p2 / ext4 defaults,noatime 0 0
# a swapfile is not a swap partition, so no using swapon|off from here on, use dphys-swapfile swap[on|off] for that
//WindowsPC/Share1 /mnt/mountfoldername cifs guest 0 0

4. Now Reboot and check that your network share is auto mounted with the following command
$ df -h

Returns

Filesystem Size Used Avail Use% Mounted on
rootfs 7.3G 2.0G 5.0G 29% /
/dev/root 7.3G 2.0G 5.0G 29% /
tmpfs 19M 228K 19M 2% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 37M 0 37M 0% /tmp
tmpfs 10M 0 10M 0% /dev
tmpfs 37M 0 37M 0% /run/shm
/dev/mmcblk0p1 56M 36M 21M 64% /boot
//WindowsPC/Share1 1.9T 1.5T 390G 80% /mnt/mountfoldername

Notice the last line here

To UnMount

$sudo umount //WindowsPC/Share1

Done🙂

References
Samba: HowTo Mount a CIFS Network Share [AKA Map Network Drive] in openSUSE 11 plus FAQs
Linux Mount CIFS shares that contain spaces in their share name
samba – Mounting a share with spaces in FreeBSD fstab – Server Fault


1 Comment

View Hostname and IP Address of Raspberry Pi

To View Host Name

pi@raspberrypi ~ $ hostname

Returns
raspberrypi

 

To View IP Address

pi@raspberrypi ~ $ ip addr

Returns
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether b8:27:eb:90:aa:d6 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 10:bf:48:50:4d:08 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.208/24 brd 192.168.1.255 scope global wlan0

OR

pi@raspberrypi ~ $ ifconfig

Returns
eth0 Link encap:Ethernet HWaddr b8:27:eb:90:aa:d6
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)


lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

wlan0 Link encap:Ethernet HWaddr 10:bf:48:50:4d:08
inet addr:192.168.1.208 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1262 errors:0 dropped:3 overruns:0 frame:0
TX packets:381 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:121349 (118.5 KiB) TX bytes:54742 (53.4 KiB)

Note: I am connected to my RPi using WLAN so it also displays wlan0

 

Enjoy🙂