Connected Little Boxes Direct Commands

YOu need to add the “direct” tag to your device for direct commands

Making stuff by yourself is all very well, but I find that projects really catch fire (in a good way) when you get other people involved. I’ve been working on Connected Little Boxes for ages and I think it is now almost useful. You can make little devices that can send messages to each other and you can control from the web. There’s a web interface you can use to manage your devices and create control pages for them. It’s all underpinned by MQTT (Message Queue Transport Protocol).

Ross took a look and he reckoned it would be nice to be able to just hit a url and send an arbitrary message over MQTT to a device. So I’ve added it. If you take a look the device edit page above you will see that the cosylight device has a Device URL. If perform a GET from that url with a query string which contains a “text” value the contents of the value are sent over MQTT to the box.

There is no validation or security, so I wouldn’t use it to control my front door. But if you want something very lightweight it provides a neat way of sending commands. If a device is being abused you either disable direct commands or change the url to a contain a different GUID.

If you want to have a go with Connected Little Boxes get in touch and I’ll set you up with a username and a password on the portal.

Merging Connected Little Boxes and the Hull Pixelbot

Two things that have occupied a lot of my time recently have been Connected Little Boxes and the Hull Pixelbot. And now I’m working on combining them. This will create a Connected Little Box which can operate as an autonomous robot. It will also being scripting to the Connected Little Box so that you can create tiny programs for each of the box interfaces. Whatever happens, it’s going to be fun.

Connected Little Boxes at the Hardware Meetup

I’ll bring along a text display too.

I’m bringing a bunch of Connected Little Boxes to the Hardware Meetup next Wednesday. I want to show off the web configuration and deployment and what you can do with QR codes.

If you fancy coming along you can just turn up at Hull MakerSpace on Wednesday 11th of October from around 5:00 pm onwards. I’ll be around with some devices to show off, and even ones that you can take home with you (numbers permitting). It would be lovely to see you.

Connected Little Boxes portal now live

This is probably the biggest thing I’ve ever built..

I’ve finally reached the point where I’m letting people lose on the newly created Connected Little Boxes portal. You can use the portal to set up your Connected Little Box devices and create behaviours for them. If you want to have a go with it, let me know and I’ll see if I can sort something out.

Over the Air Updates for Connected Little Boxes

Groverner Club

I’m adding “over the air” updates to my Connected Little Boxes. I’ve had the button on the device management form for a year or two. Over the last week I’ve been putting some code behind it. Over the air updates are magical. You can ask the device to download and install a new version of its firmware. On the surface it is quite easy to do. Except if, like me, you have a solution that uses nearly all the memory in the device. I’ve come up with a solution. When an update is required the device boots into a special “update” mode where the only element running is the code fetching the new firmware from the server. It is nearly working. Rather exciting.

Connected Little Clock

Use your skill and judgement to work out when this picture was taken

I’ve had a connected little clock in the hall for a while. It used to light up with a pleasingly bright blue display. Then, after a while gaps appeared here and there as the leds seemed to wear out.

I’ve replaced the blue ones with red ones, which I hope will last a lot longer. If you fancy one of your own (which will be remote controlled via the web) I’ll have the new software out soon.

Connected Little Boxes remote control

If you want to change the colour of the “Rob” light in my room you can scan the QR code above and then use the menu that appears to pick a colour. You can also follow this link or click the image.

The site that I’ve built lets you create collections of commands to send to Connected Little Box devices. It also lets you download the firmware into an ESP8266 or ESP32 powered device and then attach it to the Connected Little Boxes network.

I’m going to be making a bunch of videos and releasing all the code for you to play with. It’s going to be fun.

The power of the backend....

I spent a big chunk of today trying to work out why my software was putting two entries into the database whenever a device connected to the system. I’m adding logging so that I can detect if a device is resetting more than it should. After commenting out lumps of code and generally getting very confused I eventually worked out that as well as the test code running on my PC there was of course also a version of my system running in the cloud. So it was responding to device messages and writing to the database alongside the code running on my machine. I think I need separate development and test databases……

Pixel pinning

Last week I made it very easy to load Connected Little Boxes firmware into a device. Today I spent some time making it easy to configure the device too.

The form on the left shows how you configure the connection to the neopixels. The values have been pulled from the device over a serial connection. The user can edit them and then save them back into the device and test it.

I’m going to make a bunch of videos explaining how this all works and then deploy the server for anyone to have a go. Should be fun.

Getting environment variables into code in your web page

This is one of my “I’m putting something into the blog so that I can find it in a couple of years when I need to do this again” posts. I’m doing some work on the Connected Little Boxes website and I've been deploying the latest version. This one automatically configures a device by downloading setting information from the cloud. Code running inside the browser gets the settings from the server and then sends them into the device. To make this work the code in the browser needs to know the url of the server based data source. When I’m developing the program this will be on the localhost (my pc) and when the code is deployed the data source is the server in the cloud.

I’ve put this information in an environment variable. I have a local .env file that holds the local address. I’ve then put the deployed host address in the environment variable in the cloud. This works a treat, but I do have one problem. How do I get the value of this environment variable into the JavaScript code running in the browser? I’m using an Express web page to hold the web page source and I can embed JavaScript into the HTML but I don’t seem to be able to embed JavaScript elements into the <script> parts of the page. Probably because doing this kind if thing might disrupt the space-time continuum. So, I’ve done this… Below you can see the statement that renders the createDevice.ejs page. I pass this statement the HOST_ADDRESS environment variable that I want to feed into the JavaScript code in the createDevice.ejs page:

res.render("createDevice.ejs", { name: res.user.name, host: process.env.HOST_ADDRESS });

When the page is loaded the name and host variables are loaded with values supplied to the render method. Now, I pick those up inside the HTML and pass them into the page initialise function:

<body onload= "doStart('<%= host %>');" >

The HTML above specifies that a function called dostart will be called, and supplied with the value of host as a parameter. This is the environment variable that I want to use as the base url for my server requests.

function doStart(host) {
    console.log("starting");
    hostAddress = host;
    settingsURL = hostAddress + "createDevice/networkSettings.json"

    selectStage(stages.ConnectUSB);
  }

Above is the doStart function. It sets hostAddress with the base url for all requests and then uses this value to build the settingsURL that is used to fetch settings information from the host. It works a treat. When I run the application on my local PC the url is set to the local host and when it runs in the cloud the address is set to the cloud location. There is probably a much easier way of doing this which I don’t know about, but I’m still quite pleased with making this work myself.

Making lots of WiFi

I’m trying to track down the cause of my network problems at the Bonus Arena on Monday. One possibility is that a large number of available WiFi connections might cause the joining software to run out of memory.

So today I tried to make a large number of access points using a box full of ESP8266 devices. I got up to 14 access points and my software still worked fine. I think I’m going to have to go into town with a system and have a proper play to find out what is going on.

Making a node.js Cloud Application in Azure

I solved my Heroku problem from yesterday. I’d added some new .env setting values but not copied them into the Heroku application. So when the app woke up on the server it instantly fell over because lots of things were not set properly. The app was soon working fine, but it did have one problem. Heroku turns an application off if it has not been used for a while. This is usually fine. It will be started next time someone visits the site. However, at the moment my app also monitors MQTT and registers devices when they connect, so I need to have it running all the time. You can stop an inactive app from being switched off, but this involves spending money on a paid service which, being a Yorkshireman, I’m not keen on.

Instead I thought I’d try hosting the application on Azure, where I have some credits (not that I expect it to cost a lot). I followed this tutorial (or at least the second half of it) and in no time at all I had something that didn’t work. Oh well. The error was interesting. Azure didn’t know where to start. I was a bit confused because exactly the same code was running fine on Heroku. It turns out that I needed to add a start element to the settings in package.json:

"scripts": {
    "devStart": "nodemon server.js",
    "start":"node server.js"
  },

I think that Heroku just finds the nearest .js file and runs it to start an application if one is not specified, whereas Azure is a bit more careful. Anyhoo, after this I now have a management interface for all my devices.

This is the control panel for one of my little boxes. I can modify the device settings, see when it was last connected and send it commands to do stuff.

It really is incredibly easy to make your own node applications and deploy them like this. If you don’t care about app timeouts you can build and deploy something entirely for free. The integration of the process in to Visual Studio is very impressive.

I put the app onto a paid subscription (around 10 pounds a month) and then twiddled the application settings to make it always on. Great fun.

Connected Little Boxes servo pulse

I’ve added a new feature to the Connected Little Boxes software. You can now ask a servo to move to a certain position, stay their for a specified length of time and then move back to its previous position. This makes it much easier to create devices where you want to open a lock or wave a flag.

{"process":"servo","command":"pulseservopos","value":1,"pulselen":2.5}

The command above will move the servo to the end of its travel (the value 1) and hold it there for 2.5 seconds before returning it to its original position.