Showing posts with label RPi. Show all posts
Showing posts with label RPi. Show all posts

Friday, 29 November 2013

Raspberry Pi Windows Shared folders, Samba/CIFS client,

Another post that I has lying around in scratch book status for ages, so time to finalise it. This post is based on version 3.6.11+, most of my Raspi is unchanged an very stock standard, so I would assume mounting your drive should work using my instructions below.

SAMBA was originally SMB Server - but the name had to be changed due to SMB Server being an actual product. SMB was the predecessor to CIFS. SMB "server message block" and CIFS "common internet file system" are protocols. Samba implements CIFS network protocol. This is what allows Samba to communicate with (newer) MS Windows systems. Typically you will see it referred to SMB/CIFS. However, CIFS is the extension of the SMB protocol so if someone is sharing out SMB via Samba to a legacy system still using NetBIOS it will typically connect to the Samba server via port 137, 138, 139 and CIFS is strictly port 445 (You will see this is you spin up wireshark on a test machine). 

First of all, verify if the cifs module is installed

pi@raspberrypi ~ $ dpkg-query -S cifs-utils
cifs-utils: /usr/share/doc/cifs-utils
cifs-utils: /usr/share/doc/cifs-utils/changelog.gz
cifs-utils: /usr/share/doc/cifs-utils/NEWS.Debian.gz
cifs-utils: /usr/share/doc/cifs-utils/README
cifs-utils: /usr/share/doc/cifs-utils/changelog.Debian.gz
cifs-utils: /usr/share/doc/cifs-utils/copyright


To verify if the samba software has been installed,  by issuing:

pi@raspberrypi ~ $ dpkg -l | grep samba-common
ii  samba-common      2:3.6.6-6+deb7u1      all common files used by both the Samba server and client

Or issue   dpkg -p samba-common  to check its dependencies. 


First all, you will create a mount point, this is nothing more then a directory that will contain the contents of the shared drive or folder once it is mounted.

Do this by creating a directory, this cold be in your home folder or where ever you want, I have chose to use /mnt/ to keep things consistent:



mkdir /mnt/TPLINK_NAS1

Now mount the drive to the mount point for example:


mount -t cifs -o sec=none //10.19.19.102/volume1/cams/front1 /mnt/TPLINK_NAS1


As you will notice I have used the sec=none switch, this because there is an issue with Raspian, as of version 3.10.19, that causes problems when using username and password. Or so is the consensus on the raspi.org forum:

Source:
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=66&t=60699&p=459637#p459637

What this does is actually explicitly link the /volume1/cams/front1 directory to mnt/TPLINK_NAS, which means everythging that gets dumped into the mount point, essentially gets dumped onto the share. Very much like mapping shares in Windows, but better.


Permanent shares at start up. Well of course the above mount command lasts till reboot, or otherwise explicitly unmounted. In order to mound a share to a mount point at start up. the place to do this is:


/etc/fstab

I have edited fstab similar to the mount command, as per below

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p5  /boot           vfat    defaults          0       2
/dev/mmcblk0p6  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that
//10.19.19.102/volume1/cams/front1 /mnt/TPLINK_NAS1 cifs guest,users,uid=1000,auto,_netdev 0 0

To verify If your mount is functioning, issue:

cat /proc/mounts


Goodluck

Sources:

Full book on Samba:

http://www.samba.org/samba/docs/using_samba/ch00.html



https://wiki.samba.org/index.php/Mounting_samba_shares_from_a_unix_client



http://rasspberrypi.wordpress.com/2012/09/04/mounting-and-automounting-windows-shares-on-raspberry-pi/



Raspberry pi, NTP



NTP comes preloaded and preconfigured as part of Raspbian. I found the only thing I had to change was my time zone, as by default it is set to UTC, which is most useless for most people on this planet.

But first a few things on ntp. First of all check if it is running and if it is able to contact any of the ntp servers in the predefined pools. Do this by issuing:


sudo ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*timeserver3.int .GPS.            1 u   24   64    1   45.420   -0.104   1.546
 dns1-ha.au.syra 41.12.6.160      2 u   23   64    1   96.005    2.503   3.844
 ns1.mel.bkb.net 192.189.54.33    3 u   22   64    1   32.453    2.264   2.255


 ds1.zagbot.com  74.189.58.78     2 u   22   64    1   46.616   -0.014   1.141


The way these ntp servers above are picked is in accordance with the NTP server pools configured in /etc/ntp.conf

If you decide to make change to the ntp.conf file, please restart the ntp service to have these changes take effect:

/etc/init.d/ntp restart

OK, so now, how to change the local timezone? In the /etc/ directory, there is a symbolic link, called localtime, that points to the actual  localised time zone  (see below).

lrwxrwxrwx  1 root root      39 Nov 28 23:27 localtime -> /usr/share/zoneinfo/Australia/Melbourne

In my case I am using Melbourne, Australia (because Sydney sucks big hairy monkey balls). You can go to the /usr/share/zoneinfo/ directory and see which geographical part of the world applies to you, then drill into it, until you find the applicable timezone. Easy stuff.

You can also use tzselect to determine your timezone, but note that tzselect has nothing to do with permanently localising your timezone!!! 

pi@raspberrypi /usr/bin $ tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
 1) Africa
 2) Americas
 3) Antarctica
 4) Arctic Ocean
 5) Asia
 6) Atlantic Ocean
 7) Australia
 8) Europe
 9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 7
Please select one of the following time zone regions.
1) Lord Howe Island                      8) Queensland - most locations
2) Macquarie Island                      9) Queensland - Holiday Islands
3) Tasmania - most locations            10) South Australia
4) Tasmania - King Island               11) Northern Territory
5) Victoria                             12) Western Australia - most locations
6) New South Wales - most locations     13) Western Australia - Eucla area
7) New South Wales - Yancowinna
#? 5

The following information has been given:

        Australia
        Victoria

Therefore TZ='Australia/Melbourne' will be used.
Local time is now:      Thu Nov 28 23:08:38 EST 2013.
Universal Time is now:  Thu Nov 28 12:08:38 UTC 2013.
Is the above information OK?
1) Yes
2) No
#? 1

You can make this change permanent for yourself by appending the line
        TZ='Australia/Melbourne'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Australia/Melbourne



So the last thing to do is to link the /etc/localtime to the timezone you want:


sudo ln -sf /usr/share/zoneinfo/Australia/Melbourne /etc/localtime


To verify if it has worked, issue:

lrwxrwxrwx  1 root root      39 Nov 28 23:27 localtime -> /usr/share/zoneinfo/Australia/Melbourne


Halleee!

Saturday, 23 November 2013

Raspberry pi setting up wireless


Wireless on a raspberry pi. Written while is was setting up a wireless motion camera. I am a network guy so as a raspberry pi starter; I am on some familiar territory. First thing to do after you plugged in the the wireless dongle, is to check if it is being recognized. To do this issue:


lsusb

pi@raspberrypi ~ $ lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter

As you can see in the output above, my wireless dongle has the Ralink 5370 chipset in it. The chipset is important, more important than the dongle's type. This because manufacturers sometimes change chipsets, without proper notice. 
If you wireless dongle is not get recognized  don't continue on yet, and sort that out first. Try a powered hub for instance. If you are already using a powered hub, try another computer to make sure it does work (particularly when its a new dongle).

DRIVERS/MODULES

I decided to check the compatibility of my dongle (Deal Extreme, special cheap peace of %^& for a cheap arse);

http://elinux.org/RPi_USB_Wi-Fi_Adapters


Now check the modules that are loaded. For this, issue:

lsmod 

In my case this gave me the following output:

pi@raspberrypi ~ $ lsmod
Module                  Size  Used by
snd_bcm2835            16432  0
snd_pcm                77728  1 snd_bcm2835
snd_seq                53482  0
snd_timer              20110  2 snd_pcm,snd_seq
snd_seq_device          6462  1 snd_seq
snd                    58744  5 snd_bcm2835,snd_timer,snd_pcm,snd_seq,snd_seq_device
snd_page_alloc          5169  1 snd_pcm
arc4                    1684  2
rt2800usb              14948  0
rt2800lib              55359  1 rt2800usb
crc_ccitt               1530  1 rt2800lib
rt2x00usb              11240  1 rt2800usb
rt2x00lib              42342  3 rt2x00usb,rt2800lib,rt2800usb
mac80211              273979  3 rt2x00lib,rt2x00usb,rt2800lib
cfg80211              184390  2 mac80211,rt2x00lib
rfkill                 18298  2 cfg80211
leds_gpio               2243  0

led_class               3570  2 leds_gpio,rt2x00lib

Because the rt2800usb module was loaded, I decided to configure the interface and see if it would associate with my access point. 

CONFIGURE INTERFACE

Once you have ascertained that the stick is recognised and the module is loaded, configure the interface.

sudo nano /etc/network/interfaces


For example:

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0

auto wlan0      <----start up interface at boot
iface wlan0 inet dhcp
   wpa-ssid "ssid"
        wpa-psk "password"
     wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf


(Including the "  " )



With the wpa-roam command, you can configure multiple SSIDs in one single place through the wpa_supplicant.conf file. If your Pi is not going to be roaming between different SSIDs, or will roam and stay withing the same SSID, then there is no need to configure this file, and all configuration can be done in your /etc/network/interfaces file.



Because I prefer not to use DHCP on my pi's (for easier SSH access). Here is the config for a static IP address:


iface wlan0 inet static
address 10.88.33.241
netmask 255.255.255.0
gateway 10.88.33.1
broadcast 10.88.33.255
wpa-ssid "El_Pendejo"
wpa-key-mgmt WPA-PSK
wpa-group TKIP
wpa-psk "Pietjepuk!"

 To manually bounce the interface:

 sudo ifdown wlan0 && sudo ifup wlan0

WPA2
Now, if you can, configure WPA2, as it is more secure. First thing do do, is check if your access point is actually set up to support WPA2 (which most do nowadays)

pi@raspberrypi ~ $ sudo iwlist wlan0 scan
wlan0     Scan completed :
          Cell 01 - Address: 90:F6:52:F6:11:2D
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=49/70  Signal level=-61 dBm
                    Encryption key:on
                    ESSID:"El_Pendejo"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s;6
                              9 Mb/s; 12 Mb/s; 18 Mb/s
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=00000028b9d730c1
                    Extra: Last beacon: 0ms ago
                    IE: Unknown: 000D50756B6B69655F6E65745F3234
                    IE: Unknown: 010882848B960C121824
                    IE: Unknown: 030106
                    IE: Unknown: 2A0100
                     IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (1) : TKIP
                        Authentication Suites (1) : PSK

As you can see from the scan output above my AP supports wpa2 on SSID "El_pendejo".


File/etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel
#ap_scan=0
#update_config=1

network={
        ssid="YourSSID"
        psk="your-secret-key"
        scan_ssid=1
        proto=WPA2
        key_mgmt=WPA-PSK
        group=CCMP TKIP
        pairwise=CCMP TKIP
        priority=5
}


DIAGNOSTICS


To verify the wireless interface's signal strenth, SSID and associated AP issue:


iwconfig



http://wiki.gentoo.org/wiki/Wpa_supplicant