The IoTBox was born out of the realisation that we needed a physical “tool” to show how we can interact with other systems – such as IBM Maximo. We have always talked about how easy it is to integrate – but how could we prove it?.

The IoTBox started with the ability to use REST calls to update systems with temperature readings. This was useful, but hardly IoT!. Next, MQTT support was added – the temperature can be sent, along with Button presses to an MQTT broker and the RGB LED and screen can be changed with MQTT messages. This, combined with Node Red, allows us to manipulate messages, create alerts and provide ‘intelligence’ to the small processor in the IoTBox.

However, although we can talk to our servers and pcs across the Internet – this is not really cloud based.

With this in mind, I decided to also add the ability for the IoTBox to talk with IBM’s Internet of Things Foundation. This cloud offering is free to use for development and includes services such as Node Red, Real Time Analytics, Time Series databases and of course – Watson!.

The IoTF Real Time Analytics Team have made some great enhancements recently: The ability to create alerts from sensor values – this includes E-mail, Node Red calls and now IFTTT integration!.

The IoTBox will use both modes of IoTF – Quickstart (no registration required) and Registered (allows the full use of IoTF).

The new IoTF Registered mode allows the LED and OLED screen to be controlled by the IoTF cloud.

For example, a cloud based Maximo offering can create a work order based on a temperature reading from the IoTBox. The LED on the IoTBox could turn blue and a message on the screen will alert the user to the new work order number.

This is now very easy to do!. In the following post, I will detail the full steps required to connect to IBM’s IoTF cloud service.

I have switched from my Tado system to the new British Gas Hive system (https://www.hivehome.com) as the control unit is much more wife friendly.

The Tado system (at the time) did not have an official API so I had to build an integration into NodeRed to link it with my Home Automation system. The Tado system was very good at determining whether we were home or not, and switching the heating off when not needed.

The Hive system only sends a message when leaving or approaching home (at present) and without an API you cannot interact with it.

I found some great information on a forum which enabled me to build a Python application to pull key information from the Hive system and publish it to MQTT. This is based on a hive2emoncms application and updated to use the new API calls.

The current version will read values from Hive – the next will allow the control of Hive Active via MQTT!.

When power is applied to the IoTBox, it will try to connect to the stored WiFi access point and will show the IP address on the screen if successful. The screen will show an error message if it cannot connect.

The IoTBox uses two WiFi modes simultaneously:

Client Mode = It will connect to an Access Point.

Access Point Mode = It will behave as an Access Point.

To configure the IoTBox, look for an open network with the same ID as shown on the OLED display, it will be similar to “iotbox00fcf9ab”.

When connected, your PC/Mac or Phone will have an address of 192.168.4.2 and the IoTBox menu will be found at http://192.168.4.1.

The first thing to do is to upgrade to the latest version of the IoTBox firmware. For this, you will need to be connected to an external Access Point chosen on the WiFi settings page and then select OTA Upgrade. The IoTBox will download the updated firmware and then reboot into the new version.

The ESP8266 on the IoTBox is configured as two slots. The OTA firmware is downloaded and stored in the other slot. If it has downloaded correctly, it will reboot into the other slot. You may switch back to the old versiion by using the Switch ROM menu option.

If you have configured something that is causing an issue with the IoTBox, you can reset it using the button (wired to GPIO0). The button on the IoTBox has three functions:

If the button is held down while powering on, you can update the firmware on the chip with a programmer. This is only required when putting the initial firmware on the chip.

If the button is pressed for more than 0.5 seconds and less than 10 seconds (2 seconds is ideal), a message is sent to the button MQTT topic.

If the button is pressed for more than 10 seconds, the settings are cleared to the default values. You will need to set the WiFi and MQTT parameters again.

MQTT Topics

IoTBox has an MQTT v3.1 client built into the firmware and is the main way of communicating to other systems. When MQTT is enabled, it will try to connect every 10 seconds and when successful, it will post “online’ to the LWT topic.

The following topics are supported:

Note: MQTT can use wildcards, such as ‘+’. This means that a subscription to ‘+/out/led/1’ will pick up data for ‘iotbox00112233/out/led/1’ and ‘iotbox56229922/out/led/1’. This is useful when sending the same information to many devices.

LED: For the example shown above, the IoTBox is listening on:

+/out/led/1

+/out/led/2

+/out/led/3

A payload of ‘0’ or ‘1’ to these topics switches the LED colour (red, green or blue) off or on. This will likely change in the future to support PWM and a single Topic.

DISPLAY: For the example shown above, the IoTBox is listening on:

+/out/display/0

+/out/display/1

+/out/display/2

+/out/display/3

+/out/display/4

A payload of upto 20 characters will be displayed on lines 3-8 on the OLED screen. Useful for notifications and information.

BUTTON: A button press creates a payload of ‘1’ on the Topic.

TEMPERATURE: Readings from the sensor (DS18B20 or DHT22) are sent every 10 seconds to this topic.

HUMIDITY: Readings from a DHT22 (if connected) are sent every 10 seconds).

LAST WILL & TESTAMENT: When the IoTBox is connected to MQTT, a payload of ‘online’ is sent to this Topic. The MQTT server will send ‘offline’ if it does not receive a heartbeat from IoTBox.

The best way of exploring how IoTBox uses these Topics is to use the MQTT-SPY application found at MQTT-SPY Homepage.

Here are the pinouts that are defined in the firmware for the IoTBox based on the ESP12 adapter board shown below. It is possible to solder directly to the ESP chip if space is tight but you will need to take into account the various pull ups (eg CH_PD) if you do so.

In order to do the initial programming and testing of the module, install the VCC, GND, GPIO0 cables and pins for TX and RX. If you are using a larger box, you may use jumper pins for all of the connections.

push to make switch (optional:held high via 10k resistor?). Other side of switch is at GND

gpio14

D5

to I2C – SDA screen

gpio12

D6

resistor 150 ohm to led = BLUE

gpio13

D7

resistor 150 ohm to led = GREEN

vcc

3.3 volts (NOT 5v!)

gpio16

D0

n/c

Wake

ch_pd

n/c (held high on the breakout board)

adc

A0

n/c

Potentiometer / Light detection

reset

n/c

(Corrected Pins for the colours Blue and Green)

You will need to do an initial flash of the IoTBox chip which will then allow you to do the upgrades from the built in menu. Connect a 3.3v USB FTDI programmer to TX/RX and GND. Connect GPIO0 to GND and then power up the module from a source that supports around 300ma (do not power from the FTDI module).
Here is the commandline to flash the esp8266, (please remember that the esp8266 is 3.3v only – the 5v usb interfaces will kill it!)

(All on one line, may need python2.7 installed for esptool.exe. My USB programmer is using COM2)

Here is the final parts list for the IoTBox. Each item links to the version that I used. They may link to multipacks (I built 30-35 IoTBoxes) but you only need 1 unless noted.

The final IoTBox

During the beta testing I have tried and killed many boxes and components to get this far. Hopefully it will save you some time and expense. Note that many items came via China to reduce the unit price.

I took my idea to a few people – the inventors of NodeRed and a couple of members of the team and they thought that the idea was sound – produce a simple IoTBox that we can use in demonstrations to show how connected devices can make use of our products. I was then asked “Can we have 30 ready in a few weeks?”. I had better work fast!.

The IoTBox is a small 5x5cm device with an OLED screen that displays MQTT messages, an RGB LED to show MQTT messages as a status colour, a button that triggers an MQTT message and a waterproof temperature sensor that sends MQTT messages and/or a REST call. It can be updated “OTA” and is powered by the USB connector.

These articles will show you how to build one.

Background to IoTBox

Back in December 2014, I started to look at a new Wifi chip that had just been released as a means of Internet enabling various Arduino projects that I had been thinking about. I soon realised that this processor (the ESP8266) was actual more powerful than the Arduino and much much cheaper.

I use Node Red and MQTT around the house for a simple home automation system. After getting Tado installed, I wondered how easy it would be to link it in. Actually, it is very easy:

This flow pulls info from the Tado site every minute and creates MQTT messages for my other flows to pick up. As I have other wireless temperature nodes around the house, I could spot that the heating is on and a window is open by looking at temperature differences around the house.