Showing posts with label Raspberry Pi. Show all posts
Showing posts with label Raspberry Pi. Show all posts

Wednesday, 3 February 2016

Raspberry Pi - Static IP Address

For some reason, the configuration of static IP addresses in /etc/network/interfaces in the manner I've been using since Redhat 4.0 back in the mid to late 90s no longer works on the recent Raspbian Jessie images for the Raspberry Pi.

I've not researched why, I think its related to the GUI tools. I only use the cmd line and never even boot a GUI on so have come to the conclusion life is too short. So its time to learn something new again, but once you know where it is configured it isn't too difficult.

The configuration is now performed in the file /etc/dhcpcd.conf with the follow entries being added:-

  interface eth0
  static ip_address=192.168.0.10/24
  static routers=192.168.0.1
  static domain_name_servers=208.67.222.222 208.67.220.220


Obviously you need to change the details above to reflect your particular network.

The DNS servers listed are for the OpenDNS servers

Its as easy as Pi, just I quiet liked my old Pi.

Monday, 11 January 2016

Perl - CPAN shell

Brief guide to setting up CPAN shell to easily install Perl modules.

    sudo perl -MCPAN -e shell

If this fails with error message "Can't locate local/lib.pm in @INC" or make not found, either way you may need to install supporting tools. In a debian world this is as easy as:-

    sudo apt-get install build-essential liblocal-lib-perl

Once in the Perl CPAN shell its a good idea to update the shell:-

    sudo perl -MCPAN -e shell
    install CPAN
    reload cpan

Finally to install a module such as Net::Telnet simply:-

    sudo perl -MCPAN -e shell
    install Net::Telnet

Thats all for now.

Monday, 23 February 2015

Raspberry Pi - SMS Texting using 3G dongle

The problem I'm having to solve is that the 3G Dongle isn't being recognised as a serial port, it is being recognised as a storage device. Even though the description obtained from lsusb clearly identifies it as a modem.

  root@rasp-storage:~# 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 1a40:0101 Terminus Technology Inc. 4-Port HUB
  Bus 001 Device 005: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
  Bus 001 Device 006: ID 12d1:1446 Huawei Technologies Co., Ltd. E1552/E1800/E173 (HSPA modem)

Anyway, before we get started ensure the system is up to date. I'm using the latest Raspian so its a simple case of:

  apt-get update
  apt-get upgrade


The tool we are going to be using is called usb-modeswitch.

  root@rasp-storage:~# apt-cache search modeswitch 
  usb-modeswitch - mode switching tool for controlling "flip flop" USB devices
  usb-modeswitch-data - mode switching data for usb-modeswitch
  root@rasp-storage:~# apt-get install usb-modeswitch usb-modeswitch-data


I found the information for the usb_modeswitch elements by googling the "Huawei E173 modem", the details below are unlikely to work on other 3G modems. Create a file named 12d1:1446 under /etc/usb_modeswitch.d/ which contains:

  DefaultVendor=0x12d1
  DefaultProduct=0x1446
  MessageContent="55534243123456780000000000000011062000000100000000000000000000" 


Create a file /usr/local/sbin/3gmodemswitch containing.

  usb_modeswitch -I -W -c /etc/usb_modeswitch.d/12d1\:1446

Create a file /etc/udev/rules.d/99-3gmodem.rules which contains:

  ACTION=="add", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1446", RUN+="/usr/local/sbin/3gmodemswitch"

So when the modem is plugged in, udev rules pick it up and execute the 3gmodemswitch script, which in turn calls usb_modeswitch. If we have a look at the output from lsusb now, we see:


  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 009: ID 12d1:1506 Huawei Technologies Co., Ltd. E398 LTE/UMTS/GSM Modem/Networkcard
  Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
  Bus 001 Device 004: ID 0781:5571 SanDisk Corp.
  Bus 001 Device 005: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
  Bus 001 Device 006: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
  root@rasp-sms:/etc/usb_modeswitch.d#


I was able to reboot, and do a complete power down restart, and the modem continued to be recognized as a 3G modem. It should be noted I have in the past experienced an issue where the root filesystem was not on the SD card, but a USB drive. However when starting the Pi in that configuration sometimes the built in storage of the 3G modem was identified as SDA rather than the USB thumb drive. To fix this situation I made sure to use the root=PARTUUID=XXXXX notation in the /boot/cmdline.txt file. Finally, install smstools using:

  apt-get install smstools

Following which edit the /etc/smsd.conf file and append the following to the bottom (using the correct ttyUSB device:-

  [GSM1]
  #init =
  device = /dev/ttyUSB0
  incoming = yes
  #pin =
  baudrate = 19200


Now when I drop a file into the /var/spool/sms/outgoing/ directory in the format:


  To: 444797575B134

  Hello From My Raspberry Pi. :)

Incidentally the number above is random, furthermore I put a letter B in the text on purpose just to save some poor soul getting unsolicited texts by anyone reading this and simply copying the text.

So with a little more scripting, I now use this Raspberry Pi as a notification server, it polls other devices (predominately network equipment) and services and text's me if there are problems. I can also sent it texts to perform simple actions, but that element is still very much a work in progress.

Hope someone other than myself find this information useful. :)

Thursday, 15 January 2015

Raspberry Pi - Basic Setup

This is the initial setup and configuration I use for Raspberry Pi's. It isn't an all encompassing How-To, more a simple task list to jog my memory along the way:-
  • Download the latest debian based image; Raspbian Latest
  • Write the image to a SD Card.
  • Boot the Raspberry Pi.
  • Run through the raspi-config script that runs automatically.
  • After the Raspberry Pi has booted customize the required elements below.
IP Addressing, change from dynamic to static in /etc/network/interfaces.
  iface eth0 inet dhcp  iface eth0 inet static
    address 192.168.0.10
    netmask 255.255.255.0

    gateway 192.168.0.1

Setup your own user account:
  sudo adduser fred

Enable sudo access on your new account and delete it from pi account:
  sudo visudo

  pi All=(ALL) NOPASSWD: ALL
  fred All=(ALL) NOPASSWD: ALL


Logout as the pi user and log back in as your new use defined above. Once logged back in as your new user remove the pi account if you wish.
  sudo deluser pi

If preferred you can just lock the pi account:
  sudo passwd -l pi


Name Resolution, configure DNS if desired in /etc/resolv.conf you only really need 1 or 2 nameserver entries, the multiple addresses are there for my reference only.
  domain localdomain.com         # Whatever domain name you wish to use
  search localdomain.com         #
  nameserver 8.8.4.4             # Public DNS provided by Google
  nameserver 8.8.8.8             # Public DNS provided by Google
  nameserver 208.67.222.222      # Public DNS provided by opendns
  nameserver 208.67.220.220      # Public DNS provided by opendns
  nameserver 192.168.0.111       # Private hosted DNS server

Finally update using:
  sudo apt-get update
  sudo apt-get dist-upgrade

At this point, I usually shutdown the PI and take a backup of the SD card before moving on to more specific installation and configuration.

Tuesday, 13 January 2015

Raspberry Pi - 1 Wire OWFS i2c bus

In this basic How-To I work through the software configuration steps I use so that the Raspberry Pi can read values from a 1-wire DS18B20 temp sensors. The basic Raspberry Pi is fully operational with the latest fully updated Raspbian image. It is possible to interface directly to the GPIO pins, which I tested on a breadboard before deciding to go with the dedicated add on module (the RPI3v1) from Sheepwalk Electronics, which provides me with a convenient connection options given I have Cat5E wiring throughout my house. Sad I know, but useful none the less. :) The first thing we need to do is to enable the required kernel nodules. To achieve this across reboots insert the lines below in the /etc/modules file:
i2c-bcm2708
i2c-dev
If ic2detect isn't already installed it is available through the standard repository. Whilst we are installing the i2c-tools we will install the owfs and ow-shell packages as well:
sudo apt-get install i2c-tools owfs ow-shell
The command below will probe the i2c bus. Change the value of -y accordingly (0 = RPi-V1 1 = RPi-V2):
pi@rasp-owfs ~ $ sudo i2cdetect -y 0
 0 1 2 3 4 5 6 7 8 9 a b c d e f
 00: -- -- -- -- -- -- -- -- -- -- -- -- --
 10: -- -- -- -- -- -- -- -- -- -- -- -- 1c -- -- --
 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 70: -- -- -- -- -- -- -- --
 pi@rasp-owfs ~ $
Edit the /etc/owfs.conf file as appropriate below:
server: FAKE = DS18S20,DS2405
 #server: FAKE = DS18S20,DS2405
 # Chose appropriate line below based on rev1 or rev2 RPi
 # server: device=/dev/i2c-0
 # server: device=/dev/i2c-1
Assuming everything is operational and configured correctly, restart the service and check to see the connected 1-wire sensors are being read.
pi@rasp-owfs ~ $ sudo service owserver restart
[ ok ] Restarting 1-Wire TCP Server: owserver.
pi@rasp-owfs ~ $
pi@rasp-owfs ~ $
pi@rasp-owfs ~ $ owdir
 /28.BAB11E050000
 /28.69EF1E050000
 /bus.7
 /bus.6
 /bus.5
 /bus.4
 /bus.3
 /bus.2
 /bus.1
 /bus.0
 /uncached
 /settings
 /system
 /statistics
 /structure
 /simultaneous
 /alarm
pi@rasp-owfs ~ $
pi@rasp-owfs ~ $
pi@rasp-owfs ~ $ owread /28.BAB11E050000/temperature ;echo
23.9375
pi@rasp-owfs ~ $ owread /28.69EF1E050000/temperature; echo
23.9375
pi@rasp-owfs ~ $
We have now got 2 sensors plugged in and being read, they even agree and report the same temperature, which given they are next to each other is hardly surprising. Wouldn't it be good though to change the long hexidecimal strings so we can refer to the sensors using a location name. Fortunately with a bit more editing that's exactly what we can do. Work out which one you wish to name first by simply removing the other one. When we down run the owdir command the only one listed will be that of the one to rename.
pi@rasp-owfs ~ $ owdir
 /28.CE1613050000
 /bus.7
 /bus.6
 /bus.5
 /bus.4
 /bus.3
 /bus.2
 /bus.1
 /bus.0
 /uncached
 /settings
 /system
 /statistics
 /structure
 /simultaneous
 /alarm 
pi@rasp-owfs ~ $
The observant may have noticed that this is a different sensor to those addressed before. This is a waterproof one that is mounted outside in a wind sheltered spot. It should be noted though that using this method to create alias breaks the built in web server front end to owserver. If you use that interface such as browsing to http://yourIPaddr:2121, then this isn't for you. I am sure it can be solved, I've just never needed to so haven't looked into it.So to proceed, simply create a owfs.alias file in /etc with the format as below:-
pi@rasp-owfs ~ $ sudo vi /etc/owfs.alias
 28.69EF1E050000 = datacab1
 28.D9301F050000 = lounge1
 28.CC871E050000 = loft1
 28.A8A21E050000 = kitchen1
 28.BAB11E050000 = bedroom2
 28.EB4C1E050000 = bedroom1
 28.1ADE1F050000 = office1
 28.22A61E050000 = garage2
 28.CE1613050000 = outside
Now the alias file has been created, we need to instruct the owserver to use those names. Simply edit the /etc/init.d/owserver file find the section below (not far from the top) :-
d_start() {
 [ -d $PIDDIR ] || {
 mkdir -m 0775 -p $PIDDIR
 chown root:root $PIDDIR >/dev/null 2>&1
 }
 start-stop-daemon --start --quiet --oknodo --exec $DAEMON -- -c $CONFFILE \
 --pid-file $PIDFILE
 # ensure the daemon has been started
 sleep 1
 pidofproc -p $PIDFILE $DAEMON >/dev/null
 }
Under the start-stop-daemon section we need to change it to as shown below for it to use the alias file we created earlier.
start-stop-daemon --start --quiet --oknodo --exec $DAEMON -- -c $CONFFILE \
 -a /etc/owfs.alias --pid-file $PIDFILE
Once we have updated, either reboot the RPi or, issue the following command:-
sudo /etc/init.d/owserver restart
Personally I would recommend a reboot, but either should work as shown below.
pi@rasp-owfs ~ $ owdir
 /outside
 /bedroom2
 /datacab1
 /bus.7
 /bus.6
 /bus.5
 /bus.4
 /bus.3
 /bus.2
 /bus.1
 /bus.0
 /uncached
 /settings
 /system
 /statistics
 /structure
 /simultaneous
 /alarm
 pi@rasp-owfs ~ $
 pi@rasp-owfs ~ $ owread /outside/fasttemp;echo
 3
 pi@rasp-owfs ~ $ owread /outside/temperature;echo
 3.1875
 pi@rasp-owfs ~ $
That's all folks. Feel free to leave a comment.