Introduction: Connect Your Thing to the Cloud for Less Than £4.

"Control my gold LED boots from anywhere in the world!"

I wanted to change the colour of the LEDs in my boots from the web. I did not want to rely on my phone to make it work.

The solution was so cheap (less than £4) that I am now using this method to enchant all my "things".

I use a WeMos D1 Mini to connect to the WiFi. This uses the ESP8266 chip, which I program using an Arduino sketch.

I also use IBM's Watson Internet of Things platform - part of their Bluemix cloud platform. This is available as a free thirty day trial, but you also get some free runtime every month. I program the cloud side with Node-RED - a visual flow / drag and drop method of programming.

This instructable is just about getting the WeMos connected to Neopixels and the cloud. The boots are in a separate intractable.

Parts:

WeMos D1 Mini https://www.wemos.cc/product/d1-mini.html

Neopixel strip of 8 neopixels https://www.adafruit.com/category/168

Wire to connect WeMos to Neopixels

Caution: IBM update their systems regularly. All this worked as at 27th November 2016 - but please be aware changes may happen.

Acknowledgements:

A huge thanks to IBM's Andy Stanford-Clark, a fellow Maker, for his patience as he answered all my "how do I ...?" queries while working through this project. He also wrote the Arduino sketch.

Step 1: Connect Neopixels to WeMos

You need to connect three wires from your neopixels to the WeMos. The Arduino code we use later will assume you have connected a strip of eight neopixels to the WeMos pin labelled D2. If you are using a different number of pixels or different pin, you will need to change the code.

  1. Connect a wire between the +5V of the neopixels and the WeMos.
  2. Connect a wire between the Gnd of the neopixels to the Gnd of the WeMos
  3. Connect a wire between the data In (DIN) of the neopixels to the Pin 4 (D2) of the WeMos

Step 2: ​Using a Cloud Platform As a Service (PaaS)

I usually use a local Pi for the "brain" of my projects. This time I used a cloud Platform as a Service (PaaS). This allows us to develop, run, and manage applications in the cloud. I like to imagine the PaaS as a Raspberry Pi set up and run by gnomes, sitting inside the marshmallow land of the cloud. There are many PaaS providers. I use IBM's Bluemix. First you need to create an account:

1 Create a free 30 day trial of Bluemix here. This also gives you a free IBMid. The IBMid provides access to various IBM tools, including IBM applications, service trials, communities, support and on-line purchasing.

2 Check your email to confirm the Bluemix account creation. This may take up to an hour.

3 Log in to http://bluemix.net with your user-id and password.

Step 3: Add a Node-RED Application

You are now ready to make a Node-RED application:

1 Click on "Catalog" on the upper right side of the Bluemix page https://console.ng.bluemix.net/dashboard/applications/.

2 Click on "Boilerplates" which is under Apps in the left hand menu bar.

3 Search for and click on the "Internet of Things Platform Starter". This has pre-assembled services that work together - a Node-RED instance, a Node.js server, a Cloudant database for Node-RED to store configuration data, and the Watson IoT Platform service so you can connect devices to Bluemix. You do not need to know about these individual parts.

4 In the "App Name" box, name your application. This must be something unique. If you choose myapp, your application will be located at http://myapp.mybluemix.net. There can only be one “myapp” application registered in IBM Bluemix. Add your initials in front of the name if it is already taken by someone else.

5 Click on Create to create the application instance. This can take up to ten minutes.

6 Click on "Runtime" (left hand menu).

7 Change the "MB MEMORY PER INSTANCE" down to 256 and click "save". This reduces your usage of Bluemix - useful for after the 30 day trial.

8 Anyone can look at your application at http://myapp.mybluemix.net if they guess the name. To put a password on it click on the "Environment Variables" tab in the middle top of the Runtime Page. Scroll down to "User Defined".

9 Click add. In the "NAME" box, put "NODE_RED_USERNAME" (without the quotes, but with the capitals and under_scores). In the "VALUE" box put the username you want to use. Do not use your IBMid here. Click add. In the "NAME" box put "NODE_RED_PASSWORD" (without the quotes) - in the "VALUE" box add your chosen password (do not use your IBMid password). Click "save". Restart your application by clicking the circular arrow labelled "restart". This takes a few minutes, so watch for the green indicator that says it is running.

10 Click on View App, then on "go to your node-RED flow editor" Enter the username and password you just set up.

Step 4: ​Node-RED Flow on Bluemix Part 1

1 There is already a flow in your Node-RED application. Add another flow by clicking the "+" in the top right hand corner of the flow sheet. You can then double click "Flow 1" and delete it.

2 Add an inject node - drag it from the left hand menu bar into the main page. It will then be called "timestamp". Drag an IBMIoT output node into the flow. It has a grey pimple on the left hand side. Connect the two by dragging a line between the grey pimples.

3 Double click the Inject node, change the Payload type to string from the pull-down list and enter "#00ff00". Name the node "Green".

4 Press the big red "Deploy" button in the top right to save the flow. You may get an message saying "The workspace contains some nodes that are not properly configured:" and "Are you sure you want to deploy?". If so, click "Confirm deploy". You will configure it properly later.

Your WeMos needs to be able to communicate with your Bluemix account. You therefore need to add it as a device. Leave the Node-RED window open, and in another window, go to the Bluemix Services dashboard again.

Step 5: ​Adding a Device Part 1

1 Go to the Bluemix Services dashboard (https://console.ng.bluemix.net/dashboard/services). Be aware, this is not the same as the Applications dashboard (https://console.ng.bluemix.net/dashboard/applications).

2 Click on the "Internet of Things Platform" next to the name of the app you have made. Wait for the page to load.

3 Under "Connect your devices" click on "Launch Dashboard"

Step 6: ​Adding a Device Part 2

1 Add a device - click on Devices on the menu on the left hand side. The icon is a computer chip.

2 Click on "+Add Device".

3 Click "Create device type". This takes you to a new page. Click on "Create device type"

4 Enter a Name, such as "WeMos". Click the "Next" button in the bottom right hand corner.

5 On the next three pages, click Next and Next and Create.

6 Now choose the device type you have just created and click Next.

7 Type a name into the Device ID - such as WeMosBus. Click Next.

8 On the next page click Next

9 On the Security page, let the authentication token by auto-generated by clicking Next

10 Click Add.

11 Copy and paste the Authentication Token to a safe place.

12 Click on the "X" to close the window and return to the Browse Devices view.

Step 7: ​Node-RED Flow on Bluemix Part 2

1. Go back to the Node-RED flow. The web address will be something like "https://MyAppName.mybluemix.net/"

2. Double click the IBMIoT output node.

3. Change Authentication to Bluemix Service.

4. Change Output type to "Device Command"

5. Device type (WeMos) and Device ID (WeMosBus) are the ones you set up earlier.

6. In "Command type" put "command"

7. In "Format" put "text"

8. In "Data" put "{}". (Note: There is no obvious reason for this, you just have to.)

9. QoS leave as 0

10. Name - Something to identify it - e.g. WeMosBus

11. Click Done

12. Click the big red Deploy button at the top right.

Step 8: ​WeMos Code

Now you need to tell the WeMos to talk to the Watson IoT Platform on your Bluemix account.

1 Use the latest open-source Arduino software (IDE). You can download it here: https://www.arduino.cc.

2 The following libraries will also be needed. The instructions to install a library are given here: https://www.arduino.cc/en/Guide/Libraries

"PubSubClient.h" file available at: https://github.com/knolleary/pubsubclient


"Adafruit_NeoPixel.h" file available at: https://github.com/adafruit/Adafruit_NeoPixel/blob/master/Adafruit_NeoPixel.h

You will also need to install the ESP8266 wifi board - follow the instructions at https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/using-arduino-ide

That installed the adafruit-huzzah-esp8266. Now you need to repeat using the board manager to install the WeMos D1.

3 You need to make a change to the PubSubClient.h file. It should be in your Arduino installation in a subdirectory called libraries/PubSubClient/src

4 Open the file using a text editor. Look for "‪#define MQTT_KEEPALIVE 15" and change the 15 to 60. Save the change.

5 Restart the Arduino software.

6 Plug the WeMos into your computer using a USB cable.

7 In the Tools menu:

Select the "WeMos D1 R2 & mini" board in the board manager menu. If it is not there, restart the Arduino software and try again.

Select CPU frequency: 160MHz

Select Flash Size 4M (3M SPIFFS)

Select: Upload speed 115200

Port: Make sure this is the port the WeMos is plugged in to.

8 Download and open the Arduino file NeopixelBMv1.2.ino

9 In the code replace the SSID and password with the wifi details you require.

10 You need to change the BROKER, ClientID and Password - to find what these should be open up the Bluemix Applications Dashboard https://console.ng.bluemix.net/dashboard/applications/

11 Click on the line of your application, but not on the underlined Route.

12 Click on "Connections" on the left hand menu.

13 Click on the "View Credentials" of the IoT Platform iotf-service-standard box. The BROKER information is the bit after the first "mqtt_host":

14 Change the information in the arduino sketch line:

#define BROKER "{org_id}.messaging.internetofthings.ibmcloud.com"

15 To find the CLIENTID go back to the Bluemix window and click on Overview on the left hand menu

16 Scroll down and, under "Connections" click on the -iotf-service listing.

17 Under "Connect your devices" click Launch Dashboard

18 Click on DEVICE-CENTRIC-ANALYTICS.

19 Click on the device you want and on the right hand side there will be the Client ID in the format d:{org_id}:{device_type}:{device_id}

20 Change the information in the arduino sketch line:

#define CLIENTID "d:{org_id}:{device_type}:{device_id}"

21 The password is the authentication token you made for the device.

22 Now save and upload the sketch to the WeMos.

23 The Neopixels should flash magenta when they are trying to connect to the local Wifi and cyan when trying to connect to the IoT Platform and your Bluemix Node-RED flow. Once connected the LEDs turn off.

Step 9: ​TESTING

1 Go back to the Node-RED flow.

2 Click the Inject Node. The Neopixels should turn green.

3 Add another Inject Node. Change the Payload to String and enter #FF0000, name the node "red".

4 Add another Inject Node. Change the Payload to String and enter #0000FF, name the node "blue".

5 Click Deploy

6 Click the different inject nodes. The neopixels will change colour.

CONGRATULATIONS!

You are now controlling the neopixels over the web.

First Time Authors Contest 2016

Participated in the
First Time Authors Contest 2016

IoT Builders Contest

Participated in the
IoT Builders Contest

Arduino Contest 2016

Participated in the
Arduino Contest 2016