Sunday, April 12, 2015

More Playing with MQTT

With updated software, mosquitto version 1.4.1, it is very easy to connect two Brokers (see problem as suggested on previous post). A few new line in the configuration files is all that is needed. To publish (upload-only) my Broker's Topics to the public Broker at, I used the following.

Content of: /etc/mosquitto/conf.d/bridge.conf

connection iotPublic
topic # out 0 ""

Out-bound topics have "" pre-pended, currently I do not allow or receive data from directly by my Broker. If I want a topic, I subscribe directly with an application (mosquitto_sub).

My own local Brokers (in three different physical locations) exchange data from the two lesser Brokers in bidirectional fashion. Brokers do not have to be hierarchical, they can be peers. In my case I chose to configure the "bridge" on what I consider the lesser Brokers.

connection remote1
address <remote broker IPA>
topic # both 0

As a test, I created a "JoyStick" control publisher, when the joysticks are moved, all Brokers receive the data, much faster than I expected. Performance is very good. Eventually, I will control remote servos to direct (point) Raspberry PI Cameras.

You can subscribe to my testing with:

$ mosquitto_sub -v -h -t ''

Note: Mosquitto MQTT Brokers can publish any kind of data, including Web Pages and Photos.

I am just learning and having FUN with MQTT !


Esp8266 With 0.1 Inch Header

In preparation for programming my Esp8266 and the Internet of Things (IoT), I have installed a 0.1 inch header. The connector pad on the Esp8266 are 2mm and therefore a lot of lead bending was necessary.

I think this was my first soldering project that required full 15X Microscope magnification. The Esp8266-Esp11 board is much smaller than implied from the ebay photos (a previous post). The on-line diagrams and documentation are correct, but in your hand it is very small.

Esp8266-Esp11 with
0.1 Inch Header Installed
I have on order the programming interface, which should be received soon. I will use the Esp8266 with the installed header for use on Protoboards, actual projects will use direct solder to matting "Castellated Pads" on custom PCB's.
Esp8266-Esp11 Pin Layout

For my later reference, I have included the pin diagram.


Tuesday, April 7, 2015

MQTT - Internet of Things (IoT) TimeService

I am still playing with the Internet of Things (IoT) and MQTT.

I have implemented a simple TimeService, so each of my (future) devices can subscribe to-and-know the correct current time. This script is more complex than needed, but shown here as an example of what can easily be done with a simple script.

#! /bin/bash
# A mosquitto Time Server
# Author: Eldon Brown -

    # Usage: progname [-v] [-p TopicPrefix] [-h BrokerHostAddress] [other mosquitto options]

    # Check for Verbose Debug Option
    case "$1" in
        (-v):; set -xv; shift 1 ;;

    # Set Topic and Service and then add "Prefix" to Topic if desired
    TOPIC="Time/`date +%Z`"
    case "$1" in
        (-p):; TOPIC="$2/${TOPIC}"; SERVICE="$2/${SERVICE}"; shift 2 ;;

    HOST='' # Assume Local Host
    case "$1" in
        (-h):; HOST="$1 $2"; shift 2 ;;

    mosquitto_pub -r ${HOST} -q 1 -t "${SERVICE}" -m 1 $*
    trap "mosquitto_pub -r ${HOST} -q 1 -t \"${SERVICE}\" -m 0 $*; exit 0" SIGHUP SIGINT SIGTERM

    while true

        sleep `date '+(60-%S) %% 10' | bc` # Provide on 10 sec intervals

        date '+%s %Y/%m/%d %H:%M:%S'

        sleep 2          # To avoid multiple reports for the same second

    done |

    mosquitto_pub ${HOST} -t "${TOPIC}" -l $*

# End

For a while I will "publish" this time, as a service on a the public MQTT Broker, at:

You can connect and see the results by executing:

$ mosquitto_sub -h -v -t '' -t '' 

The -t 'client/#' topic is retained (-r) by the Broker and will report that the TimeService is active (1), or not (0).

Just for fun, You can subscribe to everything on the MQTT Broker, but be prepared to be Over Whelmed with data!

$ mosquitto_sub -h -v -t '#' 

So, you ask: Just how does MQTT fit into my Ham Radio plans?

I plan to implement "remote control" of radios (among many other things) using MQTT.

More information to follow.


Saturday, April 4, 2015

MQTT - Bridge Work-a-Round

I was using a very OLD version of "mosquitto" which did not support Bridges well, I am hoping the current version will work better.


To experiment with the Internet-of-Things (IoT), while waiting to receive my Esp8266's (see previous post), I have enlisted my Raspberry PI's into playing the part of a remote data collection device. My Desktop Workstation is the Control Point and the Master MQTT Message Broker.

Originally I had planned to use a Master/Slave Bridged Broker configuration, where the Workstation would be the Master, and the Raspberry PI's would be a Bridged Slave Brokers, and they would collect data and messages from the Esp8266's.

But, I have not been able to get the "mosquitto" Bridged Broker configuration to work as documented :-(

I have a work-a-round; I will temporary use an "ssh tunnel" to directly collect messages from the Raspberry PI's.

At each Raspberry PI's, an "ssh tunnel" is created for "port 1883" (the MQTT port), and therefore the Master Broker is directly available to the Raspberry PI's. A side benefit of is; the "tunnel" is compressed and encrypted.

On Raspberry PI:

$ ssh -CnNTf -L 1883:localhost:1883 <master workstation IPA>

With this setup, I can conduct; tests for camera servo control, send SMS messages to the Cell Phone, and other experiments (see previous posts).


Friday, April 3, 2015

The Internet-of-Things and MQTT

UPDATED: 2015/04/07
To include mosquitto2sms status via mqtt

The Internet Hobby Electronics world is ABLAZE with Esp8266 excitement.  These Ebay $3.00 modules are being used to create some very interesting Internet-of-Things (IoT) projects. Search Google and Youtube for Esp8266.

To make interesting projects, code can be downloaded into the processor on the Esp8266, or it can be connected to a processor like the Arduino. In either case, access to the Internet for a Hobby Project is very exciting.

One way to provide status and/or control to/from the Esp8266 is via a (little known) protocol called "MQTT", which provides simple and small processor code footprint. Actually, it is not unknown, Facebook uses it !

For Raspberry PI and Linux people, there are downloadable commands that implement MQTT, the package that contain these are "mosquitto" and "mosquitto-clients"

$ sudo apt-get install mosquitto mosquitto-clients

With "mosquitto" and the "curl" command (see previous post), I implemented a mosquitto2sms gateway, as:


#! /bin/bash
# Author: Eldon R Brown - WA0UWH

 # Usage: mosquitto2sms [-h BrokerHostAddress] []

 # set -xv   # For Debug

 mosquitto_sub -v -t 'ToSMS/#' $* |

 sed -u -n 's/^ToSMS\/\([0-9][0-9]\+\) /\1 /p' |         # Extract just the phone Number and Message

 while read phone mesg

  # echo -e "\n\n${phone} ${mesg}"  # For Debug
  curl -d "number=${phone}" -d "message=${mesg}" 2>&1 |
  grep -q true &&
  mosquitto_pub -t "ToSMS/${phone}/Stat" -m 1 $* ||
  mosquitto_pub -t "ToSMS/${phone}/Stat" -m 0 $*


# End

On another system, or any MQTT device, a simple message can be easily sent to a Cell Phone. Example as shown is from Raspberry PI.

mosquitto_pub -q 1 -t ToSMS/2025551212 -m 'Test Message'

To watch (or monitor) all of the activity on the messaging system, execute the following (i.e., subscribe to all):

mosquitto_sub -v -t '+/#'

 I am anxiously awaiting the arrival of my ebay Esp8266's, . . . only a few more days !


Wednesday, April 1, 2015

Sending SMS from the Raspberry PI

Yesterday my friend Larry - KB7KMO was in my Shop, we both have need for Status and/or Alarm Messaging from the Raspberry PI, a casual google searches did not provide much easy help. There is/was much information on how to do it with very long and complex configurations, but we wanted something simple.

After Larry left, and after several hours (actually more than a few) of research, I have found a free service that can be used to send a "SMS" messages from the Raspberry PI to a Cell Phone, using the "curl" command.

Obviously, An Internet connection is needed for the PI, and the "curl" command must be installed (if not already).

$ sudo apt-get install curl

The free SMS service is provided by "" (thanks, textbelt !).

There are limitations to the "" service; no more than 75 messages sent per day from a single IP Address, and no more than 3 messages per 3 minutes can be sent to a single Cell Phone number. For most typical use, this should not be a problem.

Note: the SMS messages received by the Cell Phone will be delivered from "".

Usage: on the command line or shell script:

$ curl -d "number=AAAPPPNNNN" -d "message=This is a test message"

Where "AAAPPPNNNN" is the: Cell Phone Number, AreaCode, Prefix, and Number.

Note: the words "number=" and "message=" must be used as shown.

For Canada and International use see: Web page.

- Have Fun with PI Messaging !


Tuesday, March 31, 2015

Esp8266 - The Intenet-of-Things

My friend Larry - KB7KMO put me onto a new interesting and inexpensive device, - the Esp8266. The breakout board is available on ebay and others for only a few bucks ( <$5.00, the prices seem to vary all over the map).

Currently there are several Rev's available (e.g., -ESP03, -ESP04, through -ESP12). I have Esp8266-ESP11 and Exp8266-ESP12 on order. I will know more about what the Rev's really mean later. Found: see Link.

Apparently the device is relatively NEW, forums are starting to fill with; information, example code, and projects.

Esp8266 is WIFI Device with a Digital Interface

The Esp8266 can be used to add WIFI to any processor with just a few lines of code. Many of the standard processors (i.e. Arduino) have support libraries already available.

Or Better YET !

The Esp8266 is a processor in it own right. There is a specially constructed GitHup repository with the new (1.6.1) Arduino IDE configuration the can be used to download and run code directly on the Esp8266 board. (see the GitHub Readme file)

The number of I/O's is a little lacking on the Esp8266, but for Networked Device for checking; a simple temperature, a water level, or alarming circuit, which reports status via Text Message, this is a great little part. As a stand-alone device, the one or two digital pins may be enough for some projects, just plan for multiple devices.

The Exp8266 can be configured as a simple Web Server, Web Client, Access Point, send Text Messages, and much-much more.

I think this is going to be a fascinating part for our Ham Radio and Hobby projects, this will make them all a part of the Internet-of-Things.

More info to follow, on how I will be using this part, I am very excited.


Tuesday, March 24, 2015

More Tasks for the Raspberry

As shown in the previous post, I have been working with the Raspberry PI 2 Computer Board. Thus far I have Connect a Camera and Servos to point the camera. In time, this will become a Roving Robot (more on that in a future post).

Also, I have been waiting for the Raspberry to grow large enough to run the OpenCPN Navigation software for my Boat. Previously, it was ran on a LapTop (which is now old and klunky).

Previous hardware Raspberry PI configurations (A, B, B+) did not have enough RAM nor CPU speed to make any of that that really possible. The Raspberry PI 2, with its 2x RAM, 4x Processors (which provide about 6x Speed). is a good match for the Boat's Navigation requirement. I do not have all of the details worked out yet, but it appears do able (that will be a subject of another blog post).

To make Boat Navigation and Rover Robot possible I need a network connection between the Raspberry PI and my Tablet. The boat navigation software runs on the PI and displayed on the Tablet. The PI will be in the Roving Robot with Camera display and Controls at my Tablet.

There are several pieces of software need to make all of this possible, most are readily available.  The Center piece is the  WIFI Access Point, with it I can connect Tablet directly (ah, . .  via WIFI) to the Raspberry PI, and when the PI is connected to my home Internet (i.e., during development) I can enjoy normal Internet access. Obviously, on the Boat and while Roving as a Robot, the Internet connection may not be available.

Adafruit has a nice tutorial which is helpful when setting up the Raspberry PI as a WIFI Access Point. With only a little head scratching, I got it and the attending DHCP up and running.  My internal home private is 192.168.2.xx, the new PI private address is 192.168.4.xx.  The PI routers between the two. Once set up, it was easy to attach my Cell Phone and Tablet to the new PI WIFI network.

Access to the devices and files on the Raspberry PI private network from my home network can easily be accoumplished with the "sshuttle" command, "rp22" is the name of my Raspberry.

$ sshuttle -DNHr rp22

The OpenCPN Navigation Software is ran on the PI, in a virtual "vncserver" window. The window is configured to match the aspect ratio (600x900) of the Tablet.

I use "ssh" to access the PI and execute the "vncserver" command. Once set up, what ever is running, will continue to run even when a viewer is disconnected, the next connection just continue the previous session. With the "-alwaysshared" option, multiple viewers can be connected simultaneously. This will be very convenient for both the Boat and the Rover.

$ vncserver -alwaysshared -geometry 600x900 :3

I use "vncviewer" on the Tablet (and/or cell phone) to view the results.

OpenCPN running on The Raspberry PI
and Displayed on the Tablet

As can be seen below with "xosview", the Raspberry PI 2 is just idling along.

System Resource Report
For the Roving Robot I will use the PI to operate the Camera pointing Servos and eventually control wheels. Currently I am streaming the camera's video to my Tablet.

All of this functionality is useful and will be used on several of my projects, including my Minima Transceiver (see many previous posts). I plan to write software to provide a Remote Panel for the Minima.

Boat Camping

During last years Boat Camping trip to the San Juan Islands,  I had 8 adults and their attending kids on board my Boat. Most camped overnight on shore.

They all had there personal devices and after the first night, they all needed to be re-charged. We had a few USB Chargers in the Boat, but there was a line waiting to gain access, I had little time on the charger myself.

For this next year, I plan to install MotorCycle USB Chargers in several places on the Boat. One will be installed on the Bridge, where I can use it with the Tablet and Navigation Software.

MotorCycle USB Charging Ports

More details to follow - while having fun with the Raspberry PI !


A Lurking Raspberry PI 2

I have been playing with the Raspberry PI 2, connecting a PI Camera and Servos to it. To provide articulation, I used an optional 12" Camera Cable for the connection.

After several hours of research I have figured out how to capture and stream images. Recently I have also figured out how to use the Servos Hat (servo adaptor board) via the Adafruit's I2C Libraries.

So with the combination of Camera and Servos, I now have a "Lurking Raspberry PI".

 I have bits and pieces of programs to control the camera and adjust the servos over the Internet, I just need to assemble the pieces together for a convenient Internet controlled system. Most of the programming will be in python, as contributed libraries are readily available.

The Raspberry PI is currently tethered via a Network Cable, and Power Cord.  But, by adding Wheels, (a big) Battery, and WIFI, is should be able to roam as desired.

My goal is complete control from my Tablet (and from any place on the Internet). Currently, simple Servo Commands can be sent via "ssh" and "telnet" on a private Public IP Address, Private Port, and Private Password. Video is also streamed to a Browser, with and a similar network connection. When completed, a single interactive Web Browser session will control the Camera Servos and future Wheel motors.

One of my goals is to, make the "Lurking Raspberry PI" available to the public with limited control, but that will be in the future.

Raspberry PI 2

I added the Servo Hat, and of course the Adafruit Case was full.

Full Case

Note: it appears that I did not have the Raspberry PI completely snapped in place.

There is not a space to mount the Camera and the Case Lid no longer fit on. So, I cut the bottom out of another one of a Ladyada's cases, which with just a little cutting and adjusting fits perfectly stacked (it almost snaps together). But it may not be an easy task for someone with two left (or right) thumbs. To make things easier, I believe Ladyada is planning an extension case similar to this.

Stacked Cases, The Bottom was Removed from Top Case

The removed (cut out) bottom is being used as an insulator between the Raspberry PI and the Servo Hat, otherwise the Servo through hole pins touch the metal HDMI connector, and it helps stabilize the Hat without special screws and spacers. The Nibs were left on the plastic to help hold-up the far side of the Servo Hat. A slot was cut to accommodate the Camera Cable.

Salvaged Case Bottom

The Two Ganged Servos are mounted on the Case cover.

Servos Mounted

The Case is closed and the Camera is installed, now it is almost ready for Action. The Bands ensure that it does NOT spring apart, and provides anti-skid feet.

Ready For Action
It's Lurking, . . . at me?

It looks like I could have use a little shorter 8" Camera Cable, but 12" Camera Cable will work fine.

More details of this project will follow, I plan to post some photos and/or captured video.


Sunday, March 15, 2015

More, CloseUp Tablet Photos

After thinking about the photos taken for the previous post, I was wondering how photos compare; when taken with the Tablet "Magnify App", and when taken through the Microscope Lens with a Tablet or Cell phone Camera?

Here is a photo taken with the Cell Phone Camera (at the Eyepiece Lens) through the Microscope at 15x Power (30x Eyepiece and with a 0.5 Diopter Object Lens).

Cell Phone Photo
through the Microscope Lens
The following photo shows the same area, taken with just the Tablet Camera with the "Magnify App".

Tablet Photo using "Magnify App"
And the same area with just the Normal Tablet Camera.

Tablet Photo using Normal Camera App
The following is the set up, as can be seen, I am just holding the Tablet, using the Microscope LED Ring Light for lighting. The photo was taken with a Cell Phone. The mouse-PCB (the photo subject) is in the spot light.

Set up Configuration
Photo take with Cell Phone
By the sizes of the saved photo files, it is obvious that the Magnify App is using Digital Zoom. but for my blogs the photos are large enough and have enough resolution.

Conclusion: I think until I get a better Microscope Mounted USB Camera, I will be using the Tablet with the "Magnify App" for most of my blog photos.

To make taking photos easier, I plan to build a stand to hold the Tablet steady. The Microscope Ring Light works fine for my photos.