Tag Archives: Raspberry Pi

Raspberry Pi

Sparkleshare on Raspberry Pi

This was my process of setting up Sparkleshare, server side on the Raspberry Pi. This guide is basically a dump of the terminal that I noted important points on.

This guide is color coded

My Input on Command Line

My  Notes

Run the Dazzle script via Curl

…from https://www.sparkleshare.org/ under Setting Up a Host.

erick@raspberrypi ~ $ sudo curl https://raw.githubusercontent.com/hbons/Dazzle/master/dazzle.sh \
>   –output /usr/bin/dazzle && chmod +x /usr/bin/dazzle
[sudo] password for erick:
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100  8639  100  8639    0     0   2954      0  0:00:02  0:00:02 –:–:–  4674
chmod: changing permissions of `/usr/bin/dazzle’: Operation not permitted

 Using sudo causes this, so just execute the last line again with sudo…

erick@raspberrypi ~ $ sudo chmod +x /usr/bin/dazzle

Next Run Dazzle Setup

Interesting stuff going on when the project is created, look at the dump to get an idea of what it is doing.
erick@raspberrypi ~ $ sudo dazzle setup
1/4 | Installing the Git package…
-> The Git package has already been installed (version 1.7.10.4).
2/4 | Creating account “storage”…
-> useradd storage –create-home –home /home/storage –system –shell /usr/bin/git-shell –password “*” –user-group
3/4 | Configuring account “storage”…
-> mkdir –parents /home/storage/.ssh
-> touch /home/storage/.ssh/authorized_keys
-> chmod 700 /home/storage/.ssh
-> chmod 600 /home/storage/.ssh/authorized_keys
4/4 | Reloading the SSH config…
-> /etc/init.d/ssh reload

Setup complete!
To create a new project, run “dazzle create PROJECT_NAME”.

Creating a Project called Rasp_Pi_Main_Share

Interesting stuff going on when the project is created, look at the dump to get an idea of what it is doing.

erick@raspberrypi ~ $ sudo dazzle create Rasp_Pi_Main_Share
Creating project “Rasp_Pi_Main_Share”…
-> /usr/bin/git init –bare /home/storage/Rasp_Pi_Main_Share
-> /usr/bin/git config –file /home/storage/Rasp_Pi_Main_Share/config receive.denyNonFastForwards true
-> echo “*.jpg -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.JPG -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.jpeg -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes     -> echo “*.JPEG -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes     -> echo “*.png -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.PNG -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.tiff -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes     -> echo “*.TIFF -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes     -> echo “*.gif -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.GIF -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.psd -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.PSD -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.xcf -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.XCF -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.flac -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes     -> echo “*.FLAC -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes     -> echo “*.mp3 -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.MP3 -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.ogg -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.OGG -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.oga -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.OGA -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.avi -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.AVI -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.mov -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.MOV -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.mpg -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.MPG -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.mpeg -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes     -> echo “*.MPEG -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes     -> echo “*.mkv -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.MKV -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.ogv -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.OGV -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.ogx -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.OGX -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.webm -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes     -> echo “*.WEBM -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes     -> echo “*.zip -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.ZIP -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.gz -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes       -> echo “*.GZ -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes       -> echo “*.bz -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes       -> echo “*.BZ -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes       -> echo “*.xz -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes       -> echo “*.XZ -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes       -> echo “*.bz2 -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.BZ2 -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.rpm -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.RPM -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.deb -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.DEB -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.tgz -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.TGZ -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.rar -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.RAR -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.ace -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.ACE -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.7z -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes       -> echo “*.7Z -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes       -> echo “*.pak -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.PAK -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.msi -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.MSI -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.iso -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.ISO -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.dmg -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes      -> echo “*.DMG -delta” >> /home/storage/Rasp_Pi_Main_Share/info/attributes
-> chown –recursive storage:storage /home/storage
-> chmod –recursive o-rwx /home/storage/Rasp_Pi_Main_Share

Project “Rasp_Pi_Main_Share” was successfully created.
To link up a SparkleShare client, enter the following
details into the “Add Hosted Project…” dialog:

Address: ssh://storage@192.168.1.17:22
Remote Path: /home/storage/Rasp_Pi_Main_Share

To link up (more) computers, use the “dazzle link” command.

Save this info somewhere good!

Address: ssh://storage@192.168.1.17:22
Remote Path: /home/storage/Rasp_Pi_Main_Share

You will need it to hook up clients to the server.

Dazzle Link, Linking clients to server

All that the dazzle link command does is add the key to the authorized_keys in the .ssh folder of the /home/storage directory.

erick@raspberrypi /home/storage $ sudo dazzle link
Paste your Client ID (found in the status icon menu) below and press <ENTER>.

Client ID: ssh-rsa AAAAB3Nza………………………….Plex-790

The client with this ID can now access projects.
Repeat this step to give access to more clients.

 

Optional:Moving this repository to the USB Stick

To get the storage folder off of the SD card and onto the external media, i.e. USB stick in my case…

Move the files…

sudo rsync -rPz /home/storage/Rasp_Pi_Main_Share/ /media/sda/Rasp_Pi_Main_Share/

Mount with bind. Using a symlink might not work here as it might not get followed. I haven’t tried it.

sudo mount --bind /media/sda/Rasp_Pi_Main_Share/ /home/storage/Rasp_Pi_Main_Share/

..this is optional, but with the limited SD card storage on the Raspberry Pi, it makes it much more useful for a shared storage device.

To Install on Client: Linux

To install Sparkleshare on the client Linux computer, Ubuntu/Mint based..

sudo apt-get install sparkleshare

 

 

Penguin

Raspberry Pi Bridge from Wireless to Ethernet

The sky, when the stars rise, the stars fly away, the stars weep.

Setting up a bridge wlan0 to eth0 on a Raspberrypi

This is for an ipv4 Bridge connection between WAN and LAN using a Raspberrypi. Another Linux computer would also work instead of a Raspberrypi. Some of this is basically a dump of note that I took while trying to get this up and running in 2017. This post may be of use to someone who is struggling to get this sort of thing going as some of the sources on the net were not always clear on how to do it and validate it’s operation.


The idea with this plan is to have the R-Pi act as a router and hand out addresses to devices on the network and do a DNS masquerade on the eth0 connection. It will also forward ipV4 packets in BOTH directions, thereby bridging a wired and wireless networks. Note: Devices running on the LAN will require setting up a default route to the gateway on the WLAN to see devices on the WLAN.

Why Setup a wlan0 to eth0 Bridge

I had to do this to allow a connection between a ZTE WiFi hotspot that did not have any Ethernet connection port and a need to connect a set of desktop computers that only have Ethernet ports to the Internet. Essentially I have two networks, one is WiFi, one hardwired and they machines have to be able to reach the Internet and each other from both sides. The Ethernet machines are connected to a switch with a router connected to it acting as an access point, DHCP set to off. This network is on an “island” that needed to be bridge via WLAN to get out to the Internet via the ZTE hotspot.

Install dnsmasq

dnsmasq is a lightweight program that will run as a service that will take care of the DNS and the DHCP functions that are required to make the R-Pi act as a router and bridge.

sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install rpi-update dnsmasq -y
 sudo rpi-update

Static IP on Ethernet Connection

Next, setup a static ip for the dhcp server. Edit /etc/network/interfaces to make the R-Pi reside at a static address on the wired network. In this example it is setup for 192.168.1.17, the typical gateway address for a router on a 192.168.1.0 network, would be 192.168.1.1 which was the gateway at one time on this network. There is nothing magical about the 192.168.1.1 address, a default gateway can exist on any valid address, excluding 192.168.1.0 and 255.

NOTICE THAT THE DEFAULT GATEWAY FOR THE eth0 IS NOT SET! This is important because the default gateway should be grabbed from the WiFi network and not the wired, which in my case is not connected to the Internet. It will go to the Ethernet first by default if there are two default gateways, WLAN and LAN.

Router Settings

If there is a router on the network, it is important to turn off DHCP on it as it does not have to hand out addresses anymore. It should just behave as a switch instead, just forwarding packets in/out of all ports including WiFi if it has it and this option is wanted, then it will function as an AP ( Access Point) as well on it’s own network (192.168.1.0/24 in my case).

 

erick@raspberrypi ~ $ cat /etc/network/interfaces
 auto lo

iface lo inet loopback
 #iface eth0 inet dhcp

iface eth0 inet static
 address 192.168.1.17
 netmask 255.255.255.0
 network 192.168.1.0
 broadcast 192.168.1.255
 #gateway 192.168.1.1
 # nameservers
 dns-nameservers 8.8.8.8 8.8.4.4

allow-hotplug wlan0
 iface wlan0 inet manual
 wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
 iface default inet dhcp

Sanity Check using mtr, a.k.a. My Trace Route

Running mtr shows a direct route to Optiplex-790, running mtr from Optiplex-790 to 192.168.128.1 shows a bounce via the R-pi.

See Appendix 1 for more info.

Configure dnsmasq via /etc/dnsmasq.conf

Copy the rather wordy original to a backup copy and use sudo nano to edit in new details. The listen address will be the same as entered into the /etc/network/interfaces file for the R-Pi now that it is at a static address, mine is at 192.168.1.17 for example. Server is the dns server that dnsmasq will be using to do it’s masquerade magic. This can be a comma separated list. I have Google in there for DNS at 8.8.8.8, but an ISP would do as well. Sometimes the router upstream includes a caching DNS and it can be included as well. If the upstream router does have a caching DNS this helps a bit with lookups as the lookup table will be maintained locally as a cache of frequently visited web addresses. Having a local lookup for DNS has less delays than reaching out on the web for every word address to IP numeric address translation.

Address Reservation

For dncp-range I am choosing from 192.168.1.20-192.168.1.255 as the ones below 20 on my network are kept in reserve for static addresses.

Backup and then edit…

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
 sudo nano /etc/dnsmasq.conf

/etc/dnsmasq.conf example

This is the one that I am using for the R-pi bridge. R-Pi is static on 192.168.1.17. DNS server is Googles 8.8.8.8 and I am reserving addresses from 192.168.1.0-20.

interface=eth0      # Use interface eth0
 listen-address=192.168.1.17 # Explicitly specify the address to listen on
 bind-interfaces      # Bind to the interface to make sure we aren't sending things elsewhere
 server=8.8.8.8       # Forward DNS requests to Google DNS
 domain-needed        # Don't forward short names
 bogus-priv           # Never forward addresses in the non-routed address spaces.
 dhcp-range=192.168.1.20,192.168.1.255,12h # Assign IP addresses between 192.168.1.20,192.168.1.255  with a 12 hour lease time

 

Enable IPv4 forwarding

The R-pi kernel has to be told explicitly to forward IPv4 packets between wlan0 and eth0.

sudo nano /etc/sysctl.conf

Fin and UNCOMMENT the following line

 net.ipv4.ip_forward=1

TO APPLY CHANGE WITHOUT A REBOOT

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

IPTABLES rules update

iptables needs a few rules added to it to cover the DNS masquerading and accepting packets forwarded from wlan0 to eth0 and in the other direction. Execute the following commands to add the rules to iptables.

sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
 sudo iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
 sudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT

iptables will keep it’s info as long as the machine is booted up. Needs a reload when rebooted.

THE STUFF BELOW IS NOT NEEDED AS THE PI HAS A METHOD TO RESTORE THE IPTABLES VIA iptable-save.sh
HAVE NOT DONE THIS YET as of 12/12/2017

sudo sh -c “iptables-save > /etc/iptables.ipv4.nat”

HOOK FILE

sudo nano /lib/dhcpcd/dhcpcd-hooks/70-ipv4-nat

ADD…

iptables-restore < /etc/iptables.ipv4.nat

—————————————————-

 

—————————————————–

On the PC – Optiplex-790

I  set up the main desktop PC as static IP via Edit Connections on the GUI.

Configure Wired Connection 1 as IPv4 Settings, Manual with address as 192.168.1.18 netmask 255.255.255.0 and gateway as the R-pi at 192.168.1.17

DNS servers, the R-pi itself 192.168.1.17 and Google at 8.8.8.8. It might be possible to have 192.168.128.1 as well as that might be a caching DNS on the upstream ZTE WiFi hotspot. It might have a caching DNS server inside of the Sprint Box itself, not sure and requires looking at the specs for it.

Feasibility Test Using a PC as a Bridge

Before I went through the trouble of setting up the R-Pi as a bridge I did a sanity check/prototype by using a PC as a bridge. By taking the WiFi USB dongle and plugging it into the PC, Optiplex-790 running Linux Mint. I was able to test the feasibility out beforehand.

Create shared connection

On an initial test of setting up the network, before digging into the R-pi to do this, I shared the wifi to the eth via editing the Wired Connection 1 and sharing under IPv4 Settings. But it puts it on a 10.42.0.x network. Use the following to change this…

In versions before 1.4.2, 10.42.0.x is hard-coded into NetworkManager. The choice is either upgrade to Ubuntu 17.04, with version 1.4.4, or go the easy way and use the following command from Thomas Haller to set the host IP and class. For my setup it was 192.168.1.18…

nmcli connection modify $CONNECTION_ID +ipv4.addresses 192.168.1.18/24

where $CONNECTION_ID if found via…

 nmcli connection show

… Afterwards, verify with…

nmcli connection show $CONNECTION_ID.

from …
https://askubuntu.com/questions/609645/configure-connection-sharing-with-specific-ip-address

ANY CHANGES MADE TO THE CONNECTION EDITOR REQUIRES A DISCONNECT AND RECONNECT TO APPLY THE CHANGES!!

Uncheck and Recheck Enable Networking

erick@OptiPlex-790 ~ $ nmcli connection show
 NAME                   UUID                                  TYPE             DEVICE
 Wired connection 1     1a2d9768-104d-3714-814c-57ea2faff63b  802-3-ethernet   eno1
 NETGEAR63              13f543ac-ea4b-455e-9ff7-9e0ecaddb139  802-11-wireless  --
 SprintHotspot2.4-BA3A  b85d60f9-5875-4eaa-a0c0-df43d174c869  802-11-wireless  --
...Verification that the change took hold after setting via nmcli connection modify command...
 erick@OptiPlex-790 ~ $ nmcli connection show 1a2d9768-104d-3714-814c-57ea2faff63b
 connection.id:                          Wired connection 1
 connection.uuid:                        1a2d9768-104d-3714-814c-57ea2faff63b
 connection.interface-name:              --
 connection.type:                        802-3-ethernet
 connection.autoconnect:                 yes
 connection.autoconnect-priority:        -999
 connection.timestamp:                   1513298233
 connection.read-only:                   no
 connection.permissions:
 connection.zone:                        --
 connection.master:                      --
 connection.slave-type:                  --
 connection.autoconnect-slaves:          -1 (default)
 connection.secondaries:
 connection.gateway-ping-timeout:        0
 connection.metered:                     unknown
 connection.lldp:                        -1 (default)
 802-3-ethernet.port:                    --
 802-3-ethernet.speed:                   0
 802-3-ethernet.duplex:                  full
 802-3-ethernet.auto-negotiate:          yes
 802-3-ethernet.mac-address:             18:03:73:D1:52:FC
 802-3-ethernet.cloned-mac-address:      --
 802-3-ethernet.mac-address-blacklist:
 802-3-ethernet.mtu:                     auto
 802-3-ethernet.s390-subchannels:
 802-3-ethernet.s390-nettype:            --
 802-3-ethernet.s390-options:
 802-3-ethernet.wake-on-lan:             1 (default)
 802-3-ethernet.wake-on-lan-password:    --
 ipv4.method:                            manual
 ipv4.dns:                               192.168.1.17,8.8.8.8
 ipv4.dns-search:
 ipv4.dns-options:                       (default)
 ipv4.dns-priority:                      0
  ipv4.addresses:                         192.168.1.18/24
 ipv4.gateway:                           192.168.1.17
 ipv4.routes:
 ipv4.route-metric:                      -1
 ipv4.ignore-auto-routes:                no
 ipv4.ignore-auto-dns:                   no
 ipv4.dhcp-client-id:                    --
 ipv4.dhcp-timeout:                      0
 ipv4.dhcp-send-hostname:                yes
 ipv4.dhcp-hostname:                     --
 ipv4.dhcp-fqdn:                         --
 ipv4.never-default:                     no
 ipv4.may-fail:                          yes
 ipv4.dad-timeout:                       -1 (default)
 ipv6.method:                            auto
 ipv6.dns:
 ipv6.dns-search:
 ipv6.dns-options:                       (default)
 ipv6.dns-priority:                      0
 ipv6.addresses:
 ipv6.gateway:                           --
 ipv6.routes:
 ipv6.route-metric:                      -1
 ipv6.ignore-auto-routes:                no
 ipv6.ignore-auto-dns:                   no
 ipv6.never-default:                     no
 ipv6.may-fail:                          yes
 ipv6.ip6-privacy:                       0 (disabled)
 ipv6.addr-gen-mode:                     stable-privacy
 ipv6.dhcp-send-hostname:                yes
 ipv6.dhcp-hostname:                     --
 GENERAL.NAME:                           Wired connection 1
 GENERAL.UUID:                           1a2d9768-104d-3714-814c-57ea2faff63b
 GENERAL.DEVICES:                        eno1
 GENERAL.STATE:                          activated
 GENERAL.DEFAULT:                        yes
 GENERAL.DEFAULT6:                       no
 GENERAL.VPN:                            no
 GENERAL.ZONE:                           --
 GENERAL.DBUS-PATH:                      /org/freedesktop/NetworkManager/ActiveConnection/14
 GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/Settings/1
 GENERAL.SPEC-OBJECT:                    /
 GENERAL.MASTER-PATH:                    --
  IP4.ADDRESS[1]:                         192.168.1.18/24
 IP4.GATEWAY:                            192.168.1.17
 IP4.ROUTE[1]:                           dst = 169.254.0.0/16, nh = 0.0.0.0, mt = 1000
 IP4.DNS[1]:                             192.168.1.17
 IP4.DNS[2]:                             8.8.8.8
 IP6.ADDRESS[1]:                         fe80::7abb:ec07:22dc:c7bd/64
 IP6.GATEWAY:

Looking at the ZTE WiFi Hotspot as seen from the Optiplex-790

erick@OptiPlex-790 ~ $ nmcli connection show b85d60f9-5875-4eaa-a0c0-df43d174c869
 connection.id:                          SprintHotspot2.4-BA3A
 connection.uuid:                        b85d60f9-5875-4eaa-a0c0-df43d174c869
 connection.interface-name:              --
 connection.type:                        802-11-wireless
 connection.autoconnect:                 yes
 connection.autoconnect-priority:        0
 connection.timestamp:                   1513128371
 connection.read-only:                   no
 connection.permissions:
 connection.zone:                        --
 connection.master:                      --
 connection.slave-type:                  --
 connection.autoconnect-slaves:          -1 (default)
 connection.secondaries:
 connection.gateway-ping-timeout:        0
 connection.metered:                     unknown
 connection.lldp:                        -1 (default)
 802-11-wireless.ssid:                   SprintHotspot2.4-B838

802-11-wireless.mode:                   infrastructure
 802-11-wireless.band:                   --
 802-11-wireless.channel:                0
 802-11-wireless.bssid:                  --
 802-11-wireless.rate:                   0
 802-11-wireless.tx-power:               0
 802-11-wireless.mac-address:            08:86:3B:04:85:88
 802-11-wireless.cloned-mac-address:     --
 802-11-wireless.mac-address-blacklist:
 802-11-wireless.mac-address-randomization:default
 802-11-wireless.mtu:                    auto
 802-11-wireless.seen-bssids:            34:69:87:BB:B8:38
 802-11-wireless.hidden:                 no
 802-11-wireless.powersave:              default (0)
 802-11-wireless-security.key-mgmt:      wpa-psk
 802-11-wireless-security.wep-tx-keyidx: 0
 802-11-wireless-security.auth-alg:      --
 802-11-wireless-security.proto:
 802-11-wireless-security.pairwise:
 802-11-wireless-security.group:
 802-11-wireless-security.leap-username: --
 802-11-wireless-security.wep-key0:      <hidden>
 802-11-wireless-security.wep-key1:      <hidden>
 802-11-wireless-security.wep-key2:      <hidden>
 802-11-wireless-security.wep-key3:      <hidden>
 802-11-wireless-security.wep-key-flags: 0 (none)
 802-11-wireless-security.wep-key-type:  0 (unknown)
 802-11-wireless-security.psk:           <hidden>
 802-11-wireless-security.psk-flags:     0 (none)
 802-11-wireless-security.leap-password: <hidden>
 802-11-wireless-security.leap-password-flags:0 (none)
 ipv4.method:                            auto
 ipv4.dns:                               8.8.8.8,8.8.4.4
 ipv4.dns-search:
 ipv4.dns-options:                       (default)
 ipv4.dns-priority:                      0
 ipv4.addresses:
 ipv4.gateway:                           --
 ipv4.routes:
 ipv4.route-metric:                      -1
 ipv4.ignore-auto-routes:                no
 ipv4.ignore-auto-dns:                   no
 ipv4.dhcp-client-id:                    --
 ipv4.dhcp-timeout:                      0
 ipv4.dhcp-send-hostname:                yes
 ipv4.dhcp-hostname:                     --
 ipv4.dhcp-fqdn:                         --
 ipv4.never-default:                     no
 ipv4.may-fail:                          yes
 ipv4.dad-timeout:                       -1 (default)
 ipv6.method:                            auto
 ipv6.dns:
 ipv6.dns-search:
 ipv6.dns-options:                       (default)
 ipv6.dns-priority:                      0
 ipv6.addresses:
 ipv6.gateway:                           --
 ipv6.routes:
 ipv6.route-metric:                      -1
 ipv6.ignore-auto-routes:                no
 ipv6.ignore-auto-dns:                   no
 ipv6.never-default:                     no
 ipv6.may-fail:                          yes
 ipv6.ip6-privacy:                       0 (disabled)
 ipv6.addr-gen-mode:                     stable-privacy
 ipv6.dhcp-send-hostname:                yes
 ipv6.dhcp-hostname:                     --


Note: Needed to Add a Route on a Machine Connected to Raspberry Pi via Ethernet

I needed to add a route to the rpi to get to the 192.168.1.0/24 network.

I THOUGHT that this had worked automatically initially. It seemed that I could at least get to the pi at http://raspberrypi and 192.168.1.17.

But really a route is needed to the 192.168.1.0/24 network via the raspberrypi.rputer on 192.168.128.X

sudo route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.128.46

there is a helper file for this in ~/bin add-route-to-192.168.1.0.sh

erick@media-pc ~/Music $ route
 Kernel IP routing table
 Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
 default         192.168.128.1   0.0.0.0         UG    600    0        0 wlx08863b02838f
 link-local      *               255.255.0.0     U     1000   0        0 wlx08863b02838f
 192.168.1.0     raspberrypi.rou 255.255.255.0   UG    0      0        0 wlx08863b02838f
 192.168.128.0   *               255.255.255.0   U     600    0        0 wlx08863b02838f

using mtr to a device on the 192.168.1.0 network confirms hw packets are routed through!

————————————————————————————–

NETSTAT VERY HELPFUL

netstat –help
usage: netstat [-vWeenNcCF] [<Af>] -r         netstat {-V|–version|-h|–help}
netstat [-vWnNcaeol] [<Socket> …]
netstat { [-vWeenNac] -i | [-cWnNe] -M | -s }

-r, –route              display routing table
-i, –interfaces         display interface table
-g, –groups             display multicast group memberships
-s, –statistics         display networking statistics (like SNMP)
-M, –masquerade         display masqueraded connections

-v, –verbose            be verbose
-W, –wide               don’t truncate IP addresses
-n, –numeric            don’t resolve names
–numeric-hosts          don’t resolve host names
–numeric-ports          don’t resolve port names
–numeric-users          don’t resolve user names
-N, –symbolic           resolve hardware names
-e, –extend             display other/more information
-p, –programs           display PID/Program name for sockets
-c, –continuous         continuous listing

-l, –listening          display listening server sockets
-a, –all, –listening   display all sockets (default: connected)
-o, –timers             display timers
-F, –fib                display Forwarding Information Base (default)
-C, –cache              display routing cache instead of FIB

<Socket>={-t|–tcp} {-u|–udp} {-w|–raw} {-x|–unix} –ax25 –ipx –netrom
<AF>=Use ‘-6|-4’ or ‘-A <af>’ or ‘–<af>’; default: inet
List of possible address families (which support routing):
inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
x25 (CCITT X.25)

—————————————————————————————

APPENDIX 1:

https://raspberrypi.stackexchange.com/questions/8010/internet-access-via-1-of-2-network-interfaces

You need to verify that you DO NOT have a default gateway set on your ETH0 interface. It has probably been assigned by DHCP, so you may have to address it statically, edit your router configuration. You will also need to verify that you have a default gateway on your WLAN interface.

Post the output of ip route show when both interfaces are connected for more detailed response.

You also need to ensure that your two routers are on different subnets. For example, the network connected to ETH0 could be 192.168.1.0 255.255.255.0, and WLAN0 could be 192.168.0.0 255.255.255.0, but they have to be on different networks. More on subnet mask

Finally you may want to read up on local routing for Debian systems.

Sorry I can’t be more specific, but there could be a book written to explain this topic. If you get stuck, or have a more specific question after doing a little reading, please let me know. I would be happy to help.

EDIT: Based on the added ip route show, you need to re-address one of your networks so the pi knows they are not connected. You may still have gateway issues, but that is where you need to start.
shareimprove this answer

edited Jun 18 ’13 at 16:13

answered Jun 17 ’13 at 22:38
Butters
1,339522

add a comment
up vote
3
down vote

eth0 is always preferred interface over wireless, you will need to issue command route -n to see your routes and then probably change default routing using:

$ sudo route add default gw 192.168.1.1 wlan0

just use correct address for your wireless router.

Raspberry Pi WiFi via USB device

Setting WiFi up via the command line on Raspberry Pi, using a USB Wireless Adapter

These are notes on how to setup WiFi on the Raspberry Pi. The R-Pi is a model 2 running Raspbian 4.1.19+.

In my case and in the example that follows, the Raspberry Pi is connected to an Ethernet network, static IP at 192.168.1.17. This is the address that  I am logging in via SSH to get to the command line to configure the USB WiFi. Adapter.

USB WiFi Adapters

Two USB Wifi’s were tried a Belkin N300 and an Edimax EW7811Un. Both use the Realtek RTL8192CU chip and work well with the R-pi. Initial testing was with the Belkin and the output from this device is used in this post for the command line examples.

Edimax EW7811Un 150Mbps 11n WiFi USB Adapter, it is nano size and has a blue activity light. It works well, can’t imagine how small the antenna is in there and how they get RF to work out OK with these sub wavelength antennas!

NOTE: Originally the adapters were tried by plugging them into a powered USB hub which plugged into the R-pi. This allows for hot-plugging. If a device is hot-plugged directly into the R-Pi it will force a reboot, at least on the one that I have (R-Pi Model 2B). This is probably due to an inrush current that pulls down the power bus momentarily, I am guessing. The powered USB hub isolates the R-Pi from the devices connected to it as far as power is concerned and things will hot plug fine using it. I did realize later on that when I plugged the USB WiFi adapter directly into the R-Pi, I got more stable behavior with it. As in less strange dropouts of the WiFi from the network. It maintains a network connection better for me at least, plugged in directly.

Initial Testing

The first steps involve checking to see that the adapter is detected, registered and the correct device driver is loaded. They are just confirmation that all is well. They can be skipped and then ran later if problems arise and troubleshooting is needed.

Plug in USB WiFi adapter and run a lsusb and dmesg…

lsusb
erick@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 2101:8500 ActionStar 
Bus 001 Device 005: ID 2101:8501 ActionStar 
Bus 001 Device 006: ID 154b:005b PNY 
Bus 001 Device 008: ID 050d:2103 Belkin Components F7D2102 802.11n N300 Micro Wireless Adapter v3000 [Realtek RTL8192CU]
Bus 001 Device 007: ID 174c:1153 ASMedia Technology Inc.

The device shows up fine using lsusb. Now on to dmesg to see if the correct driver loaded…

[156238.694964] usb 1-1.3.3: new high-speed USB device number 8 using dwc_otg
[156238.797146] usb 1-1.3.3: New USB device found, idVendor=050d, idProduct=2103
[156238.797188] usb 1-1.3.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[156238.797207] usb 1-1.3.3: Product: Belkin Wireless Adapter
[156238.797225] usb 1-1.3.3: Manufacturer: Realtek
[156238.797242] usb 1-1.3.3: SerialNumber: 00e04c000001
[156239.201673] usbcore: registered new interface driver rtl8192cu

Kernel driver rtl8192cu is loaded, all should be well with the adapter!

lsmod

The following lsmod was run and it confirms the kernel module is loaded for the 8192cu driver. It is just added confirmation that all is well.

 

erick@raspberrypi ~ $ lsmod
 Module                  Size  Used by
 xt_state                1434  1
 ipt_MASQUERADE          1220  1
 nf_nat_masquerade_ipv4     2814  1 ipt_MASQUERADE
 iptable_nat             2120  1
 nf_nat_ipv4             6162  1 iptable_nat
 nf_nat                 17132  2 nf_nat_ipv4,nf_nat_masquerade_ipv4
 8192cu                556175  0
 nfsd                  263815  11
 nf_conntrack_ipv4      14388  3
 nf_defrag_ipv4          1766  1 nf_conntrack_ipv4
 xt_conntrack            3420  1
 nf_conntrack           95316  6 nf_nat,xt_state,nf_nat_ipv4,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_ipv4
 iptable_filter          1698  1
 ip_tables              12362  2 iptable_filter,iptable_nat
 x_tables               18590  5 ip_tables,ipt_MASQUERADE,xt_state,xt_conntrack,iptable_filter
 i2c_dev                 6386  4
 snd_bcm2835            22502  0
 snd_pcm                92861  1 snd_bcm2835
 snd_seq                58152  0
 snd_seq_device          5142  1 snd_seq
 snd_timer              22156  2 snd_pcm,snd_seq
 snd                    67534  5 snd_bcm2835,snd_timer,snd_pcm,snd_seq,snd_seq_device
 sg                     20575  0
 i2c_bcm2708             5988  0
 bcm2835_gpiomem         3703  0
 bcm2835_rng             2207  0
 uio_pdrv_genirq         3526  0
 uio                    10078  1 uio_pdrv_genirq

 

Setup the WiFi Connection

In this example this is a WPA type of security. I know the SSID and password and just put them into the wpa_supplicant configuration file. If you need to see what WiFi nodes are available on the network consider using the scan …

( IF Needed )

sudo iwlist wlan0 scan

Check /etc/network/interfaces

Check to see that the section exists in the file that will allow the USB apapter to hot plug and also the wpa-roam line that points to the wpa_supplicant.conf file where the SSID and password will be stored in the next step.

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

…any changes to the interfaces file will require a reboot or a restart of networking to take effect, via….

 sudo service networking restart

If you are running the R-Pi headless it will disconnect from SSH and will require a re-login. If a mistake is made in the interfaces file, it might not come back and require connecting a keyboard and monitor to reconnect. The good news about having both a running eth0 and wlan0 is that if you make a mistake in only one of them it will be possible to connect via the other one. Less chances of being totally locked out by a small typo in the interfaces file. Sometimes a restart of network services will cause a non-recoverable dropout which requires a reboot to get an SSH connection going again.

Config wpa_supplicant
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Go to the bottom of the file and add the following type of entry, putting in the correct SSID and pwd:

network={
 ssid="SprintHotspot2.4-example"
 psk="thepassword"
 }

Save and Exit

Then execute the follow to apply the new configuration….
wpa_cli -i wlan0 reconfigure

TEST IT:

ifconfig wlan0

 

Results show that the interface is up and and running

erick@raspberrypi ~/Music/music-test $ ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr 74:df:e0:e0:0e:e0  
          inet addr:192.168.128.46  Bcast:192.168.128.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4023854 errors:0 dropped:1664207 overruns:0 frame:0
          TX packets:2955774 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:3003299485 (2.7 GiB)  TX bytes:1956045437 (1.8 GiB)

It should be working at this stage. Trying to reach the net using something like ping google.com should give good results. If not more troubleshooting is required. I had to do the next step to get it to reach the net on the wireless network as it was trying to use the Ethernet connection to the router to get out, set as the default gateway, which was not hooked up to the web at all. Just a router at 192.168.1.1 and no WAN port connection.

Additional Step

The following bit may or may not apply for everyone. But, I am adding here as it was not obvious at the moment I got WiFi up. I had to think on it a bit! Basically a default route has to exist that takes it to a gateway to the Internet.

IN ORDER TO GET PI OUT ON INTERNET NEEDED TO DO A

sudo route add default gw 192.168.128.1 wlan0

As there was no route out and it must pick eth0 by priority! Needs a route to the Sprint Box that I am connected to the net on the 192.168.128.0 network.

THE ABOVE WOULD HAVE TO HAPPEN ON EVERY REBOOT OR NETWORK REFRESH! Or just get rid of default gateway on ETH0 and it might just pick up the gateway on the wlan0 all of the time! If both are dhcp the eth0 gateway will always  be treated as preferred, so going static will get rid of it as I was planning on using this R-pi as a bridge from LAN to WLAN! This required editing /etc/network/interfaces to remove the 192.168.1.1 router as a gateway. The router was reconfigured by turning off DHCP on it, effectively making it an access point for WiFi. Essentially it becomes another path to the Internet along with the WiFi hotspot.

erick@raspberrypi ~ $ route -n
 Kernel IP routing table
 Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
 0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
 192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
 192.168.128.0   0.0.0.0         255.255.255.0   U     0      0        0 wlan0
 erick@raspberrypi ~ $ sudo route add default gw 192.168.128.1 wlan0
 erick@raspberrypi ~ $ route -n
 Kernel IP routing table
 Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
 0.0.0.0         192.168.128.1   0.0.0.0         UG    0      0        0 wlan0
 0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
 192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
 192.168.128.0   0.0.0.0         255.255.255.0   U     0      0        0 wlan0
SHOWS UP IN /etc/resolv.conf as well….
erick@raspberrypi ~ $ cat /etc/resolv.conf
 domain router
 search router
 nameserver 192.168.128.1

 

ip show route as well…
erick@raspberrypi ~ $ ip route show
 default via 192.168.128.1 dev wlan0
 default via 192.168.1.1 dev eth0
 192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.17
 192.168.128.0/24 dev wlan0  proto kernel  scope link  src 192.168.128.46

 /etc/network/interfaces

The following /etc/network/interfaces file was edited to make the wlan0 connection which connected to the Internet work for the R-Pi.

Note the eth0 connection is setup static on the 192.168.1.0 wired network. The wlan0 connection is set for dhcp on the 192.168.128.0. The default gateway at 192.168.1.1 ( the router ) is commented out to allow the default to fall on the 192.168.128.1 WiFi router, which is a ZTE WiFi hotspot, basically a repeater from 4G LTE cell to WiFi.

Note the wpa-roam points to the wpa_supplicant file that has the SSID and password entered earlier in this post to get the WiFi going.

erick@raspberrypi ~/Music/music-test $ sudo cat /etc/network/interfaces
[sudo] password for erick: 
auto lo

iface lo inet loopback
#iface eth0 inet dhcp

iface eth0 inet static
address 192.168.1.17
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
# Remove gateway to see if it fails-over to wlan0 gateway on 192.168.128.1 12242017
# gateway 192.168.1.1
# nameservers
dns-nameservers 8.8.8.8 8.8.4.4

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

ALL UP AND RUNNING OK

Running ip a shows all interfaces. Note that the R-pi is connected to wlan0 on the 192.168.128.46 address and eth0 is connected at 192.168.1.17, both networks are now available.

erick@raspberrypi ~ $ ip a
 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 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
 valid_lft forever preferred_lft forever
 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
 link/ether b8:2a:eb:2a:a4:2a brd ff:ff:ff:ff:ff:ff
 inet 192.168.1.17/24 brd 192.168.1.255 scope global eth0
 valid_lft forever preferred_lft forever
 3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
 link/ether 08:8a:3c:ba:83:8a
 brd ff:ff:ff:ff:ff:ff
 inet 192.168.128.46/24 brd 192.168.128.255 scope global wlan0
 valid_lft forever preferred_lft forever

The connection to the WiFi node can be confirmed via iwconfig wlan0…

erick@raspberrypi ~ $ iwconfig wlan0    

 IEEE 802.11bg  ESSID:"SprintHotspot2.4-example"  Nickname:"<WIFI@REALTEK>"
 Mode:Managed  Frequency:2.452 GHz  Access Point: 34:3A:87:3A:BA:3A
 Bit Rate:54 Mb/s   Sensitivity:0/0
 Retry:off   RTS thr:off   Fragment thr:off
 Power Management:off
 Link Quality=100/100  Signal level=63/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

lo        no wireless extensions.

eth0      no wireless extensions.

 

Script to check and re-connect WiFi on Raspberry Pi

After having occasional dropouts of the Raspberry Pi Wifi ( after I started using it as a bridge) and having to ifup the wlan0 manually, I considered making a script to automate it. But, a little searching online found this elegant solution to the problem.

mharizanov/WiFiCheck

https://gist.github.com/mharizanov/5325450

USB Stick Fix for NTFS filesystem on Raspberry Pi

I’ve used USB sticks on the Raspberry Pi before, many times. So I plugged one in for some extra storage. It let me write once and then went into r/o mode. What the hell! Pulled it, plugged it into the PC, no problem. Plugged it into a Windows 7 machine, it complained about drive errors and fixed it. Try again, no luck. So I gave up for a while, it was full of Music that I play through the Sockso Music Server, so no big deal, but I really do want to use it for external storage as the SD card will fill up eventually. Plus I would like to use it as more storage for ftp as well and possibly for Sparkleshare which I intend to install.

One more look

It turns out that at some point while fiddling with the USB drive, I formatted it NTFS. I believe that I tried to format it ext4 and then ext2, neither worked. So I used a WIndows machine to make it NTFS, so it would work.

The issue is that the Rasp Pi does not come with NTFS support out of the box. So I needed to  install ntfsprogs to get it to work OK….

sudo apt-get install nfsprogs

Otherwise it immediately goes to read only. I have not tested but I assume nfsprogs also installs tools to check NTFS file-systems.

To mount my USB stick, I Need to execute …

sudo mount -t ntfs -o rw,uid=erick,gid=erick /dev/sda1 /media/sda/

Symlinks for Sockso Music Server

I have a symlink for music in my Music dir (/home/erick/Music. Set it to, main-collection -> /media/sda/Music/ , in this manner it points to the music collection on the usb stick and Sockso happily finds the music. Sockso does not like spaces in filenames!

 

 

Using mount with bind to access usb drive via vsFTP

I have a USB stick plugged into my Raspberry Pi for external storage, mostly to put music on for the Sockso Music Server to get at. But I wanted to use it a bit more for generic storage. FTP is great, you can get to it from any machine and the command line for it is the same on Win or Linux. So I can walk up to any machine, not have to install a thing and reach into a folder with FTP.

For instance, I have an infected Windows Machine, I don’t dare stick a USB stick in it. Instead I go to the command line, ftp to the Raspberry Pi and grab the tools I need from there.

The Issue

The issue was that I tried to symlink from the ftp directory to the USB drive. vsFTP will not follow symlinks for security reasons.

The Solution

Mount the directory you want under the FTP directory using bind. /media/sda is the USB stick mount point and the whole thing gets mounted under the FTP dir using…

sudo mount --bind /media/sda/ /home/ftpuser/usb-drive/

Resources

FTP on Raspberry Pi. An easy way to make shared folders

Alternatives to FTP

https://radu.cotescu.com/vsftpd-and-symbolic-links/

avconv replaces ffmpeg for Video/Audio Conversion

Recently I wanted to convert an AVI file to an m4v on Linux Mint 17.3. I tried to use ffmpeg, it’s not there. I can’t isntall it…hmmm. So I did some digging, it has been replaced by avconv. To get avconv….

sudo apt-get install libav-tools

To use

Online, I read that there are some syntax differences between ffmpeg and avconv, so I was reluctant to just symlink pointing ffmpeg to avconv and have scripts break.

But I did a quick test taking a good guess…

avconv -i timelapse-wx-station-4-08-to-7-12-2016.avi timelapse-wx-station-4-08-to-7-12-2016.m4v

…and, it worked. Got me a much smaller file than the AVI and worked it’s magic in a short minute or two.

Video of Weather Station from April 8,2016 to July 12,2016

This was what I was testing out with the conversion. Video taken by using fswebcam to gather a still shot of my weather station once per hour on the Raspberry Pi. Once per day the shots are rolled up into an AVI video and stored in a tmp folder which is mounted in RAM. Well the RAM folder does fill up after a while and I copied the file off and saved it on my desktop. This video shows the weather changing from spring to summer.

Resources

http://askubuntu.com/questions/432542/is-ffmpeg-missing-from-the-official-repositories-in-14-04

 

Sockso Music Server on Linux

The Sockso Music Server is very functional and quite easy to set up in standalone or daemon mode. It is cross platform as it only depends on a Java runtime environment being installed on the target computer.

Recently I loaded it on my desktop which runs Lubuntu 14.04. I tested it out on the desktop before loading it onto my Ubuntu  server PC, which holds my music repository.

  • I will outline installing the Java run time environment needed to run Sockso on an Ubuntu machine
  • The Sockso install procedure
  • Getting it to run as a daemon
  • Getting it to find your music
  • At the bottom of the page I will have some links to resources that I followed and will provide information for running Sockso on other platforms.

The Sockso install procedure

It is not so much an install like compiling/installing, apt-get or adding a package. It is a simple old school download and drop files in a directory install.

  1. Download the Sockso zip file.  You can do steps 2 and 3 while waiting for  the download!
  2. Create /usr/share/sockso directory as root or via sudo so all files are set to root:root. ( sudo mkdir /usr/share/sockso )
  3. Create Sockso data directory /var/sockso as root or via sudo. ( sudo mkdir /var/sockso )  If sockso is terminated uncleanly, the files in this directory can get corrupted and it will need to be rebuilt
  4. Extract the files to /usr/share/sockso/ ( sudo unzip sockso-1.5.3.zip -d /usr/share/sockso/ ) I am not 100% on my unzip usage, so this command actually made a sockso-1.5.3 folder under /usr/share/sockso. Then I needed to use sudo mv .. to move all the files and dirs up one level.

 

Install Java

On my server that runs headless I performed the following after I typed in java on the command line and it told me that it was missing. It usually resides at /usr/bin/java in a Debian/Ubuntu type of file system. If it is installed it will dump out a help file. Using the command which java will also tell you if it is installed…

The program 'java' can be found in the following packages:
 * default-jre
 * gcj-4.6-jre-headless
 * openjdk-6-jre-headless
 * gcj-4.5-jre-headless
 * openjdk-7-jre-headless
Try: sudo apt-get install <selected package>

I went for version 6 headless for starters. I am not sure what the difference between all the versions are, but version 6 worked for me.

erick@ubuntuserver:/tmp$ sudo apt-get install openjdk-6-jre-headless
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  ca-certificates-java icedtea-6-jre-cacao icedtea-6-jre-jamvm java-common
  libnspr4 libnss3 libnss3-1d openjdk-6-jre-lib tzdata-java
Suggested packages:
  default-jre equivs libnss-mdns sun-java6-fonts ttf-dejavu-extra
  fonts-ipafont-gothic fonts-ipafont-mincho ttf-wqy-microhei ttf-wqy-zenhei
  ttf-indic-fonts-core ttf-telugu-fonts ttf-oriya-fonts ttf-kannada-fonts
  ttf-bengali-fonts
The following NEW packages will be installed:
  ca-certificates-java icedtea-6-jre-cacao icedtea-6-jre-jamvm java-common
  libnspr4 libnss3 libnss3-1d openjdk-6-jre-headless openjdk-6-jre-lib
  tzdata-java
0 upgraded, 10 newly installed, 0 to remove and 5 not upgraded.
Need to get 44.2 MB of archives.

 

…and so on as it installed.

Reading Java Version

If you already have java and want to view the version…

java -version

…will get you the version, such as listed on my desktop PC…

erick@Precision-WorkStation-530-MT:/var/sockso$ java -version
java version "1.7.0_91"
OpenJDK Runtime Environment (IcedTea 2.6.3) (7u91-2.6.3-0ubuntu0.14.04.1)
OpenJDK Client VM (build 24.91-b01, mixed mode, sharing)

Test run

Before making it run as a daemon I wanted to test drive it. So the following command will start it up…

sudo sh /usr/share/sockso/linux.sh --nogui --datadir /var/sockso

When you terminate it, try to shut it down clean via a sigterm when you kill the process. I have read that killing it uncleanly can screw up the data directory ( /var/sockso ). Then you have to empty the directory and rebuild it’s contents. I haven’t had it screw up the directory yet.

Running Sockso as a daemon

Running Sockso as a daemon is an advantage when you are running on a server. It will startup when the machine starts and the machine will take care of closing it down cleanly upon shutdown.

Perl script for running sockso as a daemon

After moving the Sockso files to the proper location there will be a Perl file at /usr/share/sockso/scripts/init.d/sockso

Copy the sockso run file written in perl from…

 /usr/share/sockso/scripts/init.d/sockso

…to…

/etc/init.d/sockso

…using…

sudo cp /usr/share/sockso/scripts/init.d/sockso /etc/init.d/sockso

 

Edit the file and change the directory at the top of the file to point to where sockso is installed ( /usr/share/sockso ).

Also make it executable.

sudo nano /etc/init.d/sockso

sudo chmod +x /etc/init.d/sockso

Now that it is in the init.d directory, the following should work…

sockso (start|stop|restart)

Remember to change the directory at the top of the sockso to point to the /usr/share/sockso dir.

 

Starting Sockso on boot

Follow the Steps 4,5,6 on this blog post…

https://samiux.wordpress.com/2009/07/17/howto-sockso-1-1-8-music-server-on-ubuntu-9-04-server/

I have a copy here as a PDF –> sockso-start-on-boot , just in case the link above disappears.

 

Sockso Command Prompt

Sockso comes with it’s own command prompt to administer it. help will list the commands. You can use the Sockso command line to add music to Sockso’s collections, add and delete users and perform other maintenance to it.

There is also a management webpage where you can perform the same functions as via the command line.

Finding Music

There is a command line mode for sockso where you can point it to certain directories to index music from.

Run sockso to bring up it’s command line. At it;s command line use coladd and then the path to the folder that your music is in to add it. It takes a while to do this, it is indexing it into a database so be patient. You can add multiple directories into it’s collections. If you add music to a directory in the collection, sockso will find it and add it. By default it scans directories in it’s collections every 30 minutes. I’ve tested it and it is pretty cool, dump in some music and a little while later, it’s there like magic.

coladd /home/username/Music

collist will list all the collections. coldel deletes collections.

colscan will force a scan for new collections that have been added.

Symbolic Links to Music Folder

The sockso coladd command has issues with spaces in directory names. What I have done is made a bunch of symbolic links using ln -s directory of music directory-of-music. This makes it easy to see where all the music is and sockso just has to deal with my Music directory and if I add or remove music it will figure it out on it’s own. I show an example below in the Raspberry Pi section.

Sockso on Raspberry Pi

I just ( April 2016 ) installed Sockso on my Raspberry Pi. I got the idea of sticking a USB stick into one of it’s open ports and dump my music repository on it. Them with sockso I can get to it whenever I want. Previously I had it set up on my main server that I have to use Wake on LAN to start up when I am not at home. Having Sockso on the Rasp Pi allows me to get at it instantly and saves energy by not having to run a full fledged server just to play music remotely.

Below is a tree of the Music directory that I created under my home directory. As can be seen there are symlinks without spaces that point to locations on the usb stick, mounted at /media/sda.

erick@raspberrypi ~/Music $ tree -L 1
.
├── main-collection -> /media/sda/music
└── renee-ipod-music -> /media/sda/Renee's iPod/iTunes_Control/Music/

The USB stick is formatted it’s default way that it came, FAT32. I use pmount /dev/sda1 /media/sda to mount it. In this was it is mounted not as root, it is mounted by my user, so all files are easily accessed by my own user, locally and remotely using NFS or SSHFS. In this way I can add and remove files easily.

 

 Users

In Sockso there is a concept of users. You can have multiple people logged in and have personalized settings. You can even authorize uploads by setting that option.

Adding users at the Sockso command line works similar to adding users in Linux.

useradd NAME PASS EMAIL ISADMIN 1/0     Adds a new user

Commands:
userlist                                Lists the users
useradd NAME PASS EMAIL ISADMIN 1/0     Adds a new user
userdel ID                              Deletes a user
useradmin ID ISADMIN 1/0                Sets a user to be admin/non-admin
useractive ID ISACTIVE (1/0)            Toggles users between being active or not
coladd PATH                             Adds a folder to the collection
coldel PATH                             Removes a folder from the collection
collist                                 Lists the folders in the collection
colscan DIR (optional)                  Start a collection scan
propset NAME VALUE                      Sets a property
propdel NAME                            Deletes a property
proplist FILTER                         Lists properties
version                                 Show version information
exit                                    Exit Sockso


 

Resources

Where to get Sockso, it’s official site

http://sockso.pu-gh.com/

This site is a bit dated but still helpful.

https://samiux.wordpress.com/2009/07/17/howto-sockso-1-1-8-music-server-on-ubuntu-9-04-server/

Sockso Read Me

Requirements
————

Sockso should come packaged with everything it needs to run,
all you have to do is have Java installed on your computer.
You can download the latest Java version for free from
the Sun website at: http://www.java.com

To run Sockso under Windows just double click “Run Sockso”.
Easy!

“Linux”
——-

If you’re running Linux or something similiar then you may
just be able to double click the “linux.sh” shell script.
If this doesn’t work for you then you can run this script
from a terminal with:

$> sh linux.sh

Feedback
——–

If you’ve used Sockso then I’d love to hear what you think, so
please send me some email at: rod(at symbol)pu-gh(dot)com

Running as daemon
—————–
Usage: sockso (start|stop|restart)

 

 

 

 

 

sSMTP Installing and Configuration and Use Tips

Recently I was looking at creating a method of sending a warning email when ever my house temperature went below a threshold. I remembered that sSMTP was a simple way to send automated emails and CRON emails. I have some simple notes on what I did.

Installation

Very easy, just use apt-get from the command line…

sudo apt-get install ssmtp

Configuring

The configuration file (/etc/ssmtp/ssmtp.conf) can be edited using any test editor you typically use.

 

Config at /etc/ssmtp/ssmtp.conf

Below is my config file with the critical info blocked out. Lines in Red are what I modded to get ssmtp working for me.

The key pieces to get it working for me at least were…

hostname = My ISP’s domain

root = my complete email that I use at the ISP

mailhub = I looked it up in Thunderbird, it is the smtp.myispsdomain.net part.

AuthUser=my complete email that I use at the ISP. It might be different for you. Years ago it used to be just the user name part of email without the domain.

AuthPass = The password that goes along with my email.

I commented out the defaults for the ones that existed in the code.

The config file is a bit ugly after I touched it but I was trying to get this up and running quick and didn’t clean it up. But, hey it works!

 

#
 # Config file for sSMTP sendmail
 #
 # The person who gets all mail for userids < 1000
 # Make this empty to disable rewriting.
 #root=postmaster  <--- comment out
 
# The place where the mail goes. The actual machine name is required no
 # MX records are consulted. Commonly mailhosts are named mail.domain.com
  #mailhub=mail <-- comment out
 
# Where will the mail seem to come from?
 #rewriteDomain=
# The full hostname
 #hostname=raspberrypi <--- I was testing and kill this, failed to work
 # hostname has to be the mail domain! Or else it complains about
  # the raspberrypi part! The STMP server at frontier does that is.
  hostname=myispdomain.net
# Are users allowed to set their own From: address?
 # YES - Allow the user to specify their own From: address
 # NO - Use the system generated From: address
 #FromLineOverride=YES <-- Commented out and set below, I was testing!
# New Code put here 11302015
  root=me@myispdomain.net
  mailhub=smtp.myispdomain.net
AuthUser=me@myispdomain.net
AuthPass=myemailpassword
FromLineOverride=YES
#UseSTARTTLS=YES <-- Tried this, I didn't need it for my ISP.

CRON Email

Once installed if you or root on the machine have any CRON jobs, you will start to get email from them. You can stop this by appending …

> /dev/null 2>&1

to the end of the commands that are being run by CRON. Which will cut back on the emails that you will receive.

 Testing

I installed mail utils to allow sending simple messages…

sudo apt-get install mailutils

Then I sent a message via the command line…

echo "Test" | mail -s "Test Subject" me@myispsdomain.net

…and I was able to see it work OK.

Send files via email

If you want to send files you have to install mpack.

sudo apt-get install mpack

 

Then you can send files to your email like this…

mpack -s "Test" /tmp/web/log.txt me@myispsdomain.net

 Command Line Usage

If you execute ssmtp with an email address it will let you create an email from the command line. Which is good for quick emails to for example remind yourself of something, or send a snippet of code to yourself. You edit the email in the form of the example below and hit Ctrl-D when done and then it will send out.
ssmtp recipient_email@example.com
The following is an example right off the command line. Note the one line of space after the Subject, this is a must have…
erick@raspberrypi ~ $ ssmtp me@myispdomain.net
To:me@myispdomain.net
From:me@myispdomain.net
Subject:This is a test of ssmtp from the command line!

Hello there this is a test of the ssmtp from the command line tool. It could be used to send a reminder or small snips of code. Use Ctrl-D when you are done.

It is called up by using ssmtp emailtosendto@domain.com

Bye,
Me

Example of Sending CPU Temp Warning Emails

When I am away from home I can infer if my house is running to cold, which may indicate a problem with the furnace. The Raspberry Pi is light loaded, usually just idling, so the CPU temperature tracks the room temperature, with an offset. When I am away, I set the house thermostat at 47 degrees F. If it drops below this value the CPU temperature of the Raspberry Pi will drop below 34 degrees Celsius. So I can just have it send me an email if this happens. Then I can double check a log that is created of the temperature reading to see what is going on. Also I run a webcam pointed at an actual thermometer for a sanity check, this is logged by using fswebcam to take an hourly snapshot. So I have my bases covered for the most part. Obviously if the power is out, I am in the dark about the temperature, because the whole thing is down! Solving that is a future project.

Below is the snippet of code from a shell script that sits in /etc/cron.hourly that handles the warning emails that are sent to 2 addresses. variables mailaddr and mailaddr2.

temp is the CPU temperature in Celsius as an integer stripped using cut from the thermal_zone0 reading.

minimum and maximum are my temperature thresholds. I don’t care much about maximum but I have it set at 65 Deg. C. just in case.

# Read the temp and cut it to grab leftmost 2 characters, integer Temp
temp="`cat /sys/class/thermal/thermal_zone0/temp | cut -c1-2`"
#echo $temp

# Mail if about or below the limits
if (( $temp > $maximum )); then
   #echo "above"
   echo "Rasp Pi CPU Temp = $temp. " | mail -s "Rasp Pi HIGH CPU Temp > $maximum" $mailaddr
   echo "Rasp Pi CPU Temp = $temp. " | mail -s "Rasp Pi HIGH CPU Temp > $maximum" $mailaddr2

elif (( $temp < $minimum )); then
   #echo "below"
   echo "Rasp Pi CPU Temp = $temp. " | mail -s "Rasp Pi LOW CPU Temp < $minimum" $mailaddr
   echo "Rasp Pi CPU Temp = $temp. " | mail -s "Rasp Pi LOW CPU Temp < $minimum" $mailaddr2

fi

Boot Email

I want to know if an when the Raspberry Pi I run 24/7 ever reboots due to a power outage, so I have it send me an email. The line of code below handles it and is in the root crontab. I have it sleep for 180 seconds first, then send the email. This allows the cascaded routers which I have the Pi connected to and the cable modem, time to come on line.

@reboot sleep 180 && echo "Rasp Pi Rebooted" | mail -s "Rasp Pi Reboot!" me@myispsdomain.net

I also log boots in a file that I can view online, just to keep track in one record.

@reboot date >> /var/www/bootlog.txt

Keeping track of boots helps for instance if I am away from home and the power goes out. If I get the email that the Pi rebooted, I can check to see how long the power was down and what the temperature of the house is to see if all is well.

Every hour I take a time/date stamped webcam snapshot of a thermometer so I can just look to see how many are missing and have a rough estimate of how long the power was out and how cold the house got and verify that it is getting warmer because the furnace is on!

In the future I will connect a BME280 sensor to the Raspberry Pi that will be able to read ambient room temperature directly, along with humidity and barometric pressure. So I won’t have to infer the house temperature via the CPU temperature.

Resources

This is the page I used to configure ssmtp on the Rasp Pi.

http://www.raspberry-projects.com/pi/software_utilities/email/ssmtp-to-send-emails

Users, Groups and Sudo

One thing that I did once I got my Raspberry Pi up and running is to add a user account, other than the pi account that is there by default. I have an erick account on my machines, so why not have one on the pi.

useradd

So under the default pi prompt I used the useradd command to add erick as a user. I figured that I would not login as pi and gave pi a strong password.

useradd -m erick

This will prompt for a password and make a user directory under homes by default. It also fills the directory with files and directories based on the /etc/skel directory.

Lots of Options for useradd

Usage: useradd [options] LOGIN

Options:
-b, –base-dir BASE_DIR       base directory for the home directory of the
new account
-c, –comment COMMENT         GECOS field of the new account
-d, –home-dir HOME_DIR       home directory of the new account
-D, –defaults                print or change default useradd configuration
-e, –expiredate EXPIRE_DATE  expiration date of the new account
-f, –inactive INACTIVE       password inactivity period of the new account
-g, –gid GROUP               name or ID of the primary group of the new
account
-G, –groups GROUPS           list of supplementary groups of the new
account
-h, –help                    display this help message and exit
-k, –skel SKEL_DIR           use this alternative skeleton directory
-K, –key KEY=VALUE           override /etc/login.defs defaults
-l, –no-log-init             do not add the user to the lastlog and
faillog databases
-m, –create-home             create the user’s home directory
-M, –no-create-home          do not create the user’s home directory
-N, –no-user-group           do not create a group with the same name as
the user
-o, –non-unique              allow to create users with duplicate
(non-unique) UID
-p, –password PASSWORD       encrypted password of the new account
-r, –system                  create a system account
-s, –shell SHELL             login shell of the new account
-u, –uid UID                 user ID of the new account
-U, –user-group              create a group with the same name as the user
-Z, –selinux-user SEUSER     use a specific SEUSER for the SELinux user mapping

 

Once I was able to log in under my new account, I tried setting up fswebcam to collect some timelapse video and then I had my first hitch. I needed to be part of the video group to run fswebcam.

id

The id command ran from the command line…

id username

…will list not only the user and group ID of the user UID and GID. But all of the groups that he user belongs to. It has the options -u, -g, -G. -u lists the UID alone, -g is the users GID alone and -G lists all the group ID’s that the user belongs to.

usermod

I was not part of the video group so I would have to add myself, but I was not part of the admin group either so I was not able to even run sudo.

So with a quick logout to the pi user, I was able to add myself to the admin group.

sudo usermod -a -G admin erick

The sudoers file

If you run sudo visudo, it will open the /etc/sudoers.tmp file. At the bottom of this file there is a line that explains that accounts added to the admin group are allowed to run sudo.

# Members of the admin group may gain root privileges
 %admin ALL=(ALL) ALL

Now that I can sudo from my own account, I can login back in as erick and run…

sudo usermod -a -G video erick

…to add myself to the video group. Now I was off and running with using fswebcam under my account.

NFS and Users

With users there is the notion of the name and then there is the numerical UID. NFS uses the numerical UID to map across machines. If you plan on using NFS on multiple machines, it pays to keep the UID’s lined up between them. For example, if you set up 2 Linux machines from scratch, there will be a user at UID 1000, that would be you, whatever you called it by name. The first user is at 1000. If you use NFS to mount a directory from one machine to another, no problem it all lines up. The user at UID 1000 is the same on both machines, permissions work out, files can be moved back and forth, no problems.

But if like with the example of the Raspberry Pi above. User pi is created on the NOOBS Disk when you load the Raspberian option. It is at UID 1000 and GID 1000. So if you add and other user for yourself, guess what it appears at UID 1001. Something to keep in mind when using NFS. You can use NFS in a way that will get around this using the methods laid out in the NFS post.

But it is much easier to try to keep all of the name and UID’s lined up from the beginning and not have to worry about the trickiness business. Even it means adding a user to the Raspberry Pi and then moving the UID of the pi user to some other UID and yourself to UID 1000, GID 1000 if that will line it up with your other machines on the network.