Sunday, 27 May 2018

Stormy


Last night (2018-05-26) starting around 11pm we had a thunderstorm over London.

Now, we get a few thunderstorms over London but this one was pretty spectacular.  From our location, there was about 40 minutes of almost constant thunder and impressive lightning every few seconds.

And the technical angle? I took a video of a few seconds of the storm and uploaded it to YouTube.
This is my first YouTube upload, and second video only to watching an old multimeter.
 

Monday, 21 May 2018

Starting with Docker

Until now, I've not done any work with containers so for a bit of fun I decided to setup my RESTful web server to run with Docker.

As a reminder, this is a simple python server built using web.py running on my Raspberry Pi Zero.

Step 1: Install Docker on Raspberry Pi
First up, install Docker. To do this, run these commands:

curl -sSL https://get.docker.com/sh

Set it up to start automatically on a reboot 

sudo systemctl enable docker:

Now add the pi user to the docker group, this means there'll be no need to use sudo in future:

sudo usermod -aG docker pi

Reboot, and then run:

docker run hello-world

pi@raspberrypi:~/Server $ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.


Success!

Step 2: Build Web server Image
The directory where the Dockerfile and build files is contained is called the context. The Dockerfile is a simple text file that contains the commands necessary to build the customised image.

All files used to build the image must be in the directory tree with this folder at its root:

pi@raspberrypi:~/Server $ ls
data  Dockerfile  RestServer.py


The image used to build for the Web server was a based on raspbian for Raspberry pi loaded from the docker hub. So starting from this point, the Dockerfile can be created:

FROM resin/rpi-raspbian:latest
ENTRYPOINT []

RUN apt-get -q update && \
    apt-get -qy install \
    python python-pip

RUN pip install web.py

WORKDIR /app

COPY RestServer.py /app

COPY data /home/pi/data/

CMD ["python", "RestServer.py"]


The script updates and installs python & python-pip before then using that to install web-py. It then setups the necessary directories and copies the python file along with the data folder for local storage.
Finally the CMD starts up the script using python.

This was then built with:

docker build -t rest-server .

Step 4: Run the Web server Container

Now to run the rest-server use this command

docker run -p 8080:8080 rest-server 

The -p argument exposes the 8080 port to external clients

This will start the container in the foreground and attach to stdout.

To run in "Detached" mode, use the -d flag. When starting this will return the long id of the container

Useful commands
Docker documents can be found here


To list the running containers:
docker ps

Open a bash shell into the image:
docker run -t -u rest-server /bin/bash 

List local docker images:
docker image ls

Delete a docker image
docker rmi <image id>

Tuesday, 10 April 2018

The pain of hours long downloads ... failing

I have a TomTom SatNav with which I use the MyDrive Connect Application on Windows 10 to download and update maps.

A Western Europe map comes in at around 3GB but when I attempted to upload this last week the time to complete indicator unfortunately went rapidly up to 12 hours. (This with a 50Mbit broadband connection which was otherwise working perfectly)

So, with that in mind I started investigations. First, the Windows task manager showed the biggest hog of network was Delivery Optimisation Service. Now this was interesting, because I'd already disabled it using the options under:

Settings > Update & security > Windows Update > Advanced options

I've only got one Windows 10 machine so this is a service I don't need. However, there is another instance of the service running using the Microsoft Store. I disabled this by turning off automatic app updates in the Windows Store Settings. Now the downside is I'll have to manually update Store apps so this won't work for everyone. However, given the number of updates pending already, and for some apps I'd never use (Groove Music for example), I'm not too upset. One thing that might be useful though, instead of often vague "What's new in this version", it might also be nice to show exactly what version I've got installed.

Back to the download. This did eventually speed up and ended up taking around 3hours. But when it said complete I got a dreaded no-maps found on my TomTom device, which is an indication the install was corrupted.

For some reason, it came to my mind that the USB cable I'd been using had shown some strange behaviour when I'd been developing with my Android phone so I decided to replace it and try again and, as if by magic, the update completed successfully in minutes.

You never can tell where a bad USB cable takes you.



Saturday, 30 December 2017

Setting up a new Raspberry Pi (2017 Edition)

Last post of the year and admittedly not all that many in 2017. This one is more of a personal reference of the steps taken to setup a new Raspberry Pi. In this case using the Raspbian Jessie OS.

The version of the Pi used here, the Zero W, includes built-in WiFi.

First steps were performed using a Windows 10 machine.

1. Download image. The one I'm using is the 10th April 2017 Raspbian Jessie image.
2. Get a new Micro SD card and plug into the PC. I have an external USB card reader for this. It should appear as a newly mounted drive.
3. Unzip and flash the .img file to the SD card. I use Etcher. Follow the workflow to select the image, select the drive corresponding to the SD card and then Flash.
4. Disconnect the external drive and insert the Micro SD into the Raspberry Pi.

Now I plugged the Raspberry Pi into a TV via HDMI (an HDMI to Micro HDMI connector is required for the Zero) and switched on. At this point you should see it boot and start the windows.

5. Next, the important step, change the default password. Open a command window and use the pwd command.
6. From the same command prompt, enter sudo raspi-config. Select the Advanced Options and Expand Filesystem. This ensures the whole of the SD card is available to the Pi.
7. In the same tool, enable SSH and VNC. This is because I want to remotely logon to the machine from elsewhere on my network.
8. Now reboot.
9. After the machine has restarted I connect to the network using WiFi. I used the UI from Raspbian to do this.
10. Now I can get the latest updates of the OS, sudo apt-get update followed by sudo apt-get upgrade.
11. For the purposes of my network, I want to use a static IP address, rather than use one assigned by DHCP. To do this edit /etc/dhcpcd.conf and add the following lines to the bottom, assuming the router IP is 192.168.0.1 and we want to setup our static IP to 129.168.0.207

   interface wlan0

   static ip_address=192.168.0.207/24
   static routers=192.168.0.1
   static domain_name_servers=192.168.0.1
 
12. Connect to the network share. From the command line it's possible to do this using:

    sudo mount -t cifs -o guest //ip.of.nas/Public /home/pi/NAS

I want to be able to connect automatically on start up. To do this requires a couple of steps, first add the following to the end of /etc/fstab

  //ip.of.nas/Public /home/pi/NAS cifs guest 0 0

However the problem with this as it stands is this step is run before connection to the network at boot time. To fix, open raspi-config, select boot options and Wait for network at boot.
13. Finally reboot. The Raspberry Pi setup is now complete.

Saturday, 18 November 2017

Stepping it up a gear

Having previously played with a Servo, I bought a cheap stepper motor to see how easy it is to use with the Arduino.

Stepper motors have multiple electromagnets arranged around the central shaft. These electromagnets can be controlled in a specific way that allows the shaft to rotate, or step, a fixed amount. Typically steppers are controlled with a driver circuit. A microcontroller such as the Arduino can do this.

The motor is a 28BYJ-48 with a ULN2003 motor driver chip. This is a unipolar stepper with 5 wires.


A unipolar stepper has one winding with a "center tap" per phase. The center tap is a contact made half way along the winding. In the 5 wire stepper, the center tap is joined to a common wire.



Wiring the stepper as below and and using the stepper_oneRevolution sketch from the Arduino examples didn't work out of the box. Instead of revolving clockwise and anticlockwise it always rotated in the same sense.

So, to get it working I followed the steps on this Instructables tutorial



Here is the Arduino and Stepper put together:
Next step is to include this with the Raspberry Pi for some more interesting applications.

Wednesday, 6 September 2017

Fixing Linux Mint WiFi

With Windows 10 completely breaking in a fresh and exciting (not to mention unfixable) way on a laptop earlier in the year I decided to wipe it and install Linux Mint

This was all very straightforward but as the laptop in question is a 6 year old Dell to get the WiFi working I needed to install a new driver.

From the Ubuntu wiki the command:

lspci -vvnn | grep -A 9 Network

Gave this output:
 
Network controller [0280]: Broadcom Corporation BCM4312 802.11b/g LP-PHY [14e4:4315] (rev 01)

4315 is not listed in the above link but using this successfully got the WiFi working:

sudo apt-get install firmware-b43-installer

Now, all this worked very well for some weeks until after a restart the WiFi decided not to connect at all.

I looked at the logs from

cat /var/log/syslog

Sep  5 20:42:27 jonathan-Inspiron-1764 avahi-daemon[926]: Registering new address record for fe80::9a27:20f7:ee67:8a6a on wlan0.*.
Sep  5 20:42:28 jonathan-Inspiron-1764 dhclient[5211]: DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 5 (xid=0x600e0419)
Sep  5 20:42:33 jonathan-Inspiron-1764 dhclient[5211]: DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 11 (xid=0x600e0419)
Sep  5 20:42:44 jonathan-Inspiron-1764 dhclient[5211]: DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 18 (xid=0x600e0419)
Sep  5 20:43:02 jonathan-Inspiron-1764 dhclient[5211]: DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 16 (xid=0x600e0419)
Sep  5 20:43:10 jonathan-Inspiron-1764 NetworkManager[940]: <warn>  [1504640590.6173] dhcp4 (wlan0): request timed out
Sep  5 20:43:10 jonathan-Inspiron-1764 NetworkManager[940]: <info>  [1504640590.6174] dhcp4 (wlan0): state changed unknown -> timeout
Sep  5 20:43:10 jonathan-Inspiron-1764 NetworkManager[940]: <info>  [1504640590.6338] dhcp4 (wlan0): canceled DHCP transaction, DHCP client pid 5211
Sep  5 20:43:10 jonathan-Inspiron-1764 NetworkManager[940]: <info>  [1504640590.6338] dhcp4 (wlan0): state changed timeout -> done
Sep  5 20:43:10 jonathan-Inspiron-1764 NetworkManager[940]: <info>  [1504640590.6345] device (wlan0): state change: ip-config -> failed (reason 'ip-config-unavailable') [70 120 5]
Sep  5 20:43:10 jonathan-Inspiron-1764 NetworkManager[940]: <info>  [1504640590.6350] manager: NetworkManager state is now DISCONNECTED

Strangely, this seemed to be a symptom of not using the b43 driver. So I decided to try the following:
  • Connect to router by ethernet and update
  • sudo apt-get remove firmware-b43-installer 
  • sudo apt-get install firmware-b43-installer
  • Reboot
This worked and I've been able to post this blog from the now Minty fresh (sorry!) laptop.

Tuesday, 23 May 2017

Birdbox cam odds and ends


Unfortunately, although I did get a few visitors, including Wrens to the Birdbox, none of them decided to setup a nest.



However, I did make a few changes to make life simpler for me. First off, using an old router made life harder than necessary when transferring files or viewing the video output. I played with setting up a network bridge but this proved to be too problematic.
The simple solution was to buy a Wi-Fi Range extender with an Ethernet port. This allowed me to seamlessly add the Pi on the Power over Ethernet to my main home network.


Next, the image processing code used by the motion detection requires the camera output to a device on /dev/video0

This is not setup automatically so to setup the driver enter the following:

sudo modprobe bcm2835-v4l2

To do this automatically after every boot, add the following two lines to the end of the /etc/modules file.

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

snd-bcm2835

# v4l2 driver for Rasberry Pi Cam
bcm2835-v4l2


To copy files between the pi and laptop. I used scp

tar -cvf images.tar *.jpg
scp images.tar username@destination.ip:images.tar
tar -xvf images.tar

And finally, to measure the temperature of CPU. Interesting both in the cold winter nights and hot summer days

/opt/vc/bin/vcgencmd measure_temp