IOT SETUP - RASPBERRY PI SETUP AND UPGRADES

This page logs my setup and ongoing experimentation for development of 'Internet of Things',
specifically using the Raspberry Pi.

Setting up a new Raspberry Pi:

This section describes the steps in setting up a new Raspberry PI.

  • Go to the RASPIAN download page at RASPIAN (currently Ver 4.19)
  • Download "Raspbian Buster with desktop and recommended software" ZIP file.
  • .... Note where the File ( eg: "2020-02-13-raspbian-buster-full.zip") is downloaded to
  • .... - usually the 'Downloads' directory - leave it 'zipped' for now.
  • Insert and Format your microSD card to FAT32
  • Download the image writer program 'Etcher' from Etcher
  • .... - (Ensure it is correct Version for your 'Operating System' )
  • Choose 'Save File'.
  • .... Locate where this File is downloaded to (usually 'Downloads' directory)
  • Create a working directory (eg. "G:\Raspberry-Pi") and drag both files there.
  • Find the Raspian image Zip file and Unzip it to an "img" file (You may need to use 7Zip)
  • Double click the 'Etcher-Setup-xxx' application - it will install and run immediately.
  • In the 'Etcher' box click 'Select image' - choose eg. "2020-02-13-raspbian-buster-full.img"
  • In the 'Etcher' box (check SD drive info) and click 'Flash'.
  • ... wait for it to complete 'flashing', and complete the 100% verify.
  • Connect a Screen, Keyboard and Mouse and 'Insert' Raspian microSD card...
  • Power up, and wait for boot-up completion...
  • ... When the Raspberry Pi Graphical Scrren is displayed ...
  • Click the mouse on the "Command Box" on the top bar..
  • ... then update your distribution ...
  • Refer to Raspberry Pi Update Learning Resources
  • sudo apt-get update
  • ---
  • .. Remote Putty does not work ..Raspberry changed something since November 2016..
    .. here is the noob instruction to get this problem fixed..
  • sudo su
  • raspi-config
  • 1) Choose first 'update' (to this application)
  • 2) In Advanced Options -> expand_root file system
  • 3) Interfacing Options -> ssh [enable]
  • 4) change Localization Options->Locale ->[en_AU.UTF-8 UTF-8]
  • ..... This is important for MySQL sort order later (Accept the en_GB.UTF-8 default).....
  • 5) and while you still here, it's good to change the timezone as well
  • --- Localization Options->Timezone -> Australia -> Melbourne
  • ...Don't reboot just yet...
  • Lookup the IP Address so you can use a PuTTY window.
  • sudo ifconfig
  • Note "eth0" specifically to get the IP Address.
  • Open a PuTTY window for that IP address
  • Setting A Fixed IP Address...

  • In the PuTTY command window get the current configuration
  • sudo ifconfig
  • Note "eth0" specifically
  • Must set up interface eth0: in config file.
  • inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0
    ... see this article for Jessie... Refer to Setting Static IP
  • sudo nano /etc/dhcpcd.conf
  • ... Go to the end of the file and add these lines...
    ... This presumes and Address of 192.168.1.21 (change to preferred values)...
    ... To copy a line in 'Nano' first 'Cut' (Ctrl+K) and 'Uncut' (Ctrl+U) twice...
  • To exit the editor, press ctrl+x
    To save your changes press the letter “Y” then hit enter
  • Shut down Raspberry Pi ('sudo shutdown -h now') and power off and on to Restart
  • Don't forget you need to change your PuTTY address to new IP
  • Changing the 'Hostname' from 'raspberrypi' to a unique name...

  • In the PuTTY command window run the 'Configuration Tool'
  • run... sudo raspi-config
  • ... then select "2 Network Options" then "1 Hostname"
  • ... Change the Hostname to "Pi-20" and 'tab' to "[OK]" and Enter.
  • ... When asked if 'Ok to Reboot?' say '[OK]'.

Installing Mosquitto on the the Raspberry Pi:

First you should update your distribution:
  • sudo apt-get update
Install pre-requisite software (THESE STEPS ARE PROBABLY NOT REQUIRED):
Where prompted about memory usage answer Yes Enter.
  • sudo apt-get install libssl-dev
  • sudo apt-get install cmake
  • sudo apt-get install libc-ares-dev
  • sudo apt-get install uuid-dev
  • sudo apt-get install daemon
  • sudo apt-get update
  • sudo apt-get install mosquitto
In 'putty' run the following commands to ensure that 'Mosquitto' is running and listening on Port 1883,
  • service mosquitto status
  • netstat -tln
A useful tool for testing Mosquito and MQTT is MQTT SPY which can be installed on a Windows Desktop Computer.
It is quite powerful but requires that a recent version of Java be installed and active.
.

Setting the Connection Details in "mqqt-spy" for Raspberry Pi:
... Chrome MQTT SPY

Subscribing to MQTT messages

.

Once connected you should Subscribe to "#" (means 'all' messages).
.
You will then see any 'Subscribed Messages' appear in the lower box.
.
You can confirm it by typing anything into the "Publish Message" "Topic" and "Data" box and press "Publish".

If 'Mosquito' is working on the Raspberry Pi the text should appear in the "Messages" window.

Chrome MQTT SPY

To be able to make effective use of the data being returned from "Internet Things" some form of configurable Web based application is required. There are a number of applications but 'OpenHAB' seems to fulfill most of the requirements, and is available for Raspberry Pi.

.

Installing OpenHAB on the the Raspberry Pi:

The following instructions from...

Easily install openHAB on a Raspberry Pi

This post shares the process I use to install openHAB, the “vendor and technology agnostic open source automation software for your home,” on a Raspberry Pi 2. While I use the Raspberry Pi 2, this process should work on any variant. After scouring the web, I found multiple tutorials, but none worked for me exclusively. After much experimentation, my process became an amalgam of several online resources.

My tutorial assumes you have a working Raspberry Pi running the Raspian Operating System with Internet connectivity. I connect to the Raspberry Pi remotely using SSH on my Mac, but you can use the Terminal to follow these steps directly on the Raspberry Pi.

Verify Java Version

openHAB makes extensive use of Java and version 1.6 or higher is required. The first step is to ensure our Raspberry Pi includes a recent version of Java.

java -version

The Raspberry Pi will present the version of Java installed as shown below.

java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode)

In my case, I have an install version of 1.8.0_65. I’m good to go. If your version does not meet the requirement, use the following commands in the terminal:

sudo apt-get update

This will update your Raspbian (Debian) packages. Type the following:

sudo apt-get dist-upgrade

After a bit of time, the Raspian OS will update; including Java.

Add the openHAB repositories

We can install openHAB from a download, but being able to install from the apt-get package manager makes the install easier and allows easy updates. Before we can use apt-get we will add the openHAB repositories to Raspian.

First we download the repository key:

wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | sudo apt-key add -

We now add the repository to our apt sources list:

echo "deb http://dl.bintray.com/openhab/apt-repo stable main" | sudo tee /etc/apt/sources.list.d/openhab.list

With the new repository in our list, we update our list of available applications:

sudo apt-get update

No errors should display and we are now ready to install openHAB from the repository.

Install openHAB

The command below will install openHAB on the Raspberry Pi.

sudo apt-get install openhab-runtime

Start the openHAB server

If all went according to plan, we can now run the openHAB server:

sudo /etc/init.d/openhab start

The Raspberry Pi will display the following to verify server operation:

[ ok ] Starting openhab (via systemctl): openhab.service.

openHAB Status

Check the status of the openHAB installation with the command below:

sudo /etc/init.d/openhab status

Stop the openHAB server

Use the command below to stop the server:

sudo /etc/init.d/openhab stop

The Raspberry Pi will display the following to verify the server has stopped:

[ ok ] Stopping openhab (via systemctl): openhab.service.

Just the start…

The install is just the start of my openHAB journey. As I learn to control my home with openHAB and the Raspberry Pi, I will continue to add additional instructions. For now, if this install process works for you, please drop a comment below and let me know. I’m looking forward to my openHAB experiments.

The above instructions, and other comments, were from...
  • stevencombs.com Installing OpenHAB on the the Raspberry Pi
  • NOTE: After the above process 'Openhab' is installed in ... /usr/share/openhab/configurations/sitemaps

    Installing the 'addons' for 'mqtt':

    The following commands to add the 'addons' were copied from 'Openhab' Website:
    Now we need to install the mqtt 'addons'...:
    • sudo apt-get install openhab-addon-binding-mqtt
    • .
    • ... and for philips hue (if required) ...
    • sudo apt-get install openhab-addon-binding-hue
    • .
    • ---- check if the files are there! ---
    • cd /usr/share/openhab/addons
    • ls -l
    • .... you should see README and two '.jar' files (hue and mqtt)

    Setting up Configurations and Sitemaps

    Now set up the openhab configurations...:
    • cd /usr/share/openhab
    • cd configurations
    • --- Copy default configuration file to config.cfg.
    • sudo cp openhab_default.cfg openhab.cfg
    • --- check to see that the copy exists.
    • ls -l
    • --- Make a backup copy of the configuration file before we edit it.
    • sudo cp openhab.cfg openhab-backup.cfg
    • --- check to see that the all three copies exist.
    • ls -l
    • sudo nano openhab.cfg
    • [Hint!- Use the Nano command (Ctrl-w "#mqtt:") to locate the correct line]
      [Hint!- To copy a line use (Ctrl-k) to cut, and (Ctrl-u) to paste]
      After the following line #mqtt (a new line without the '#')
      ...# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
      after #mqtt: 'broker' .url=tcp:// 'host' :1883 insert the following string
      ... ...
    • mqtt:mymosquitto.url=tcp://localhost:1883
    • ... ...
      After the following lines #mqtt (a new line without the '#')
      ...# Optional. Client id (max 23 chars) to use when connecting to the broker.
      ... ...
    • mqtt:mymosquitto.clientId=openhab
    Then press Ctrl-x and answer 'y' to Save, then ENTER to use the same filename.

    .

    Check the status of the openHAB installation with the command below:

    • sudo /etc/init.d/openhab status
    If 'openhab is active it should be 'stopped'
    • sudo /etc/init.d/openhab stop

    The Raspberry Pi will display the following to verify the server has stopped:

    "[ ok ] Stopping openhab (via systemctl): openhab.service."

    Then 'openhab can be 'started'
    • sudo /etc/init.d/openhab start
    If you already have 'myhome1 files' then view the this new configuration from a browser at
    • http://192.168.1.20:8080/openhab.app?sitemap=myhome1
    • --- Substitute your Raspberry Pi IP address if not '192.168.1.20'
    If you need to set up the 'myhome1' files see the following section.

    Setting up Configurations and Sitemaps for 'myhome1'

    Paradigm Electronics

    WebPage for 'myhome1' under OpenHAB

    .

    This is a first attempt of running 'OpenHAB' on the Raspberry Pi together with the 'Mosquitto Broker'.

    .

    It shows the results of three separate ESP8266 modules; with DHT11 (Temperature and Humidity) sensors.

    .

    The Sensors are in three different rooms: Lounge, Kitchen and Bathroom.

    .

    All the modules 'subscribe' MQTT messages to the 'Mosquitto Broker' under the topics 'lounge/temperature', 'kitchen/temperature' and 'bathroom/temperature'.

    .

    It also subscribes topics 'lounge/humidity' etc for each location.

    .

    . Now we have to create the configuration files for 'myhome1' OpenHAB (sitemap and items).

    .

    .'sitemap' configuration for OpenHAB

    • cd /usr/share/openhab/configurations
    • cd sitemaps
    • sudo nano myhome1.sitemap
    Select all the text in this area, and paste to the editor on Raspberry Pi.

    .

    Don't forget to save 'ctrl-x', 'y', Enter.

    .

    .'items' configuration for OpenHAB

    • cd /usr/share/openhab/configurations
    • cd items
    • sudo nano myhome1.items
    Select all the text in the above area, and paste to the editor on Raspberry Pi.
    Don't forget to save 'ctrl-x', 'y', Enter.

    View the this new configuration from a browser at
    • http://192.168.1.20:8080/openhab.app?sitemap=myhome1
    • --- Substitute your Raspberry Pi IP address if not '192.168.1.20'

Enhancing myhome1 OpenHAB Application:

This page shows how the original 'sitemap' and 'items' files can be enhanced; and includes several examples.
IOT Setup - OpenHAB Enhancements

..

Adding mySQL Server to Raspberry Pi:

In OpenHAB; to provide 'Persistence' (memory of past results) a database of some sort is required. The widely used mySQL is a database that will meet our requirements, and is fully supported by OpenHAB.

..

Creating an ESP8266 MQTT Sender:

This page which is being written will explain the setup of the ESP8266 with a DHT11 (Temperature and Humidity Sensor Module), together with the software 'Arduino Sketch'. ESP8266 Mqtt Sender

..



The websites that I will use for Apache, PHP and PHPadmin ....

EtherCard Useful Links...

General Raspberry Pi Linux Commands and Hints:

This section Lists the useful Linux Commands that I often forget.

    ... Report on Free Space on the SD Card ...
  • df -Bm
  • ... Clear the Putty screen ...
  • clear
  • ... update your distribution ...
  • sudo apt-get update
  • ... To totally shutdown Raspberry Pi...
  • sudo shutdown -h now
  • ... check up on Mosquitto (MQTT Broker) ...
  • service mosquitto status
  • netstat -tln
  • To restart the OpenHAB after each new login (restart of Putty) ...:
  • cd /opt/openhab
  • sudo ./start.sh
  • To modify an OpenHAB Sitemap File ...:
  • cd /opt/openhab
  • cd configurations
  • cd sitemaps
  • sudo nano myhome1.sitemap
  • ... Don't forget to save 'ctrl-x', 'y', Enter.
    To modify an OpenHAB Items File ...:
  • cd /opt/openhab
  • cd configurations
  • cd items
  • sudo nano myhome1.sitemap
  • To List the Files in the MySQL directory on the Hard Disk ...:
  • sudo ls -l /mnt/usbdrive/mysql
  • To test the command line mysql with user='openhab' password='openhab'...
  • mysql -p -u openhab
  • show databases;
  • use openhab;
  • SHOW COLUMNS FROM Item1;
  • show tables in openhab;
  • SHOW TABLE STATUS FROM db_name;
  • quit;
Last updated: 05-AUG-2023 9:36AM.
©2004-2014 Paradigm Electronics
Home | About Paradigm Electronics | Products & Services | Contact us | Site map | Useful Links | Client | ANMF test | Android | Ham Data | Logout |