Off-The-Shelf Hacker: Run a Portable MQTT Broker with the CHIP Platform
Startups pivot all the time, for any number of different reasons. Conventional thinking says that you should be flexible, agile and able to roll with the changes.
Prototyping your ideas into physical computing stack projects is no different. There’s always uncertainty in making something new. Sometimes you’ll go down rabbit holes or realize you just can’t get there from here. Boards come and go, products go out of production, support never materializes, promised features don’t get into the chips… the list is nearly infinite.
As a result, for my project, started last week, of building a portable MQTT broker, I’m pivoting away from the Artik 10 to the CHIP platform.
I realized that the Artik 10 recently went out of production. The Artik 7 is now the top dog. I don’t have one of those. All is not lost though since I configured the Artik 10 as an access point and then used that hard-earned knowledge to do the same with an on-hand CHIP board.
The Next Thing Co., the CHIP’s parent company, recently came out with the CHIP Pro. It costs $16, is geared for hobbyist/commercial users and looks like it might be in production for a while. Although it has less Flash memory than the CHIP, the board considerably smaller and it has an external antenna connector. I’m exploring the Pro model for the portable, wireless data hub version 2.0 or 3.0.
Life in the hardware fast lane. Let’s roll.
Making the CHIP into an AP
Meanwhile, we can leverage the current CHIP platform for a prototype. The flagship board came with a 1GHz processor, 512MB of RAM, 4GB of Flash storage, WiFi B/G/N, Bluetooth, some digital I/O pins and Linux. Of course, I appreciate that Linux runs in Flash because it actually simplifies the building process. The CHIP also has an integrated on-board antenna, on the module, which will suffice for version 1.0 of the portable data hub.
A key feature of the portable wireless data hub is the ability to act as its own access point (AP). That way, you can have your own little WiFi network, possibly with an MQTT broker running, facilitating messages going back and forth between edge devices, ESP8266 sensors or other nano-Linux microcontroller modules.
I found a public Slack file about making a CHIP into an access point. Following the instructions produces a very basic, certainly unsecured local network to pass messages among WiFi-enabled devices and the CHIP computer.
The steps are pretty straightforward. Here’s a summary.
- Install dnsmasq to allow DHCP connections to the CHIP.
- Edit the /etc/network/interfaces file to set the access point IP address.
- Start the DHCP server.
- Edit the /etc/hostapd.conf file to configure WLAN1 as the access point.
- Start the access point with hostapd.
- Configure AP start on bootup by editing the /lib/systemd/system/hostapd-systemd.service file.
- Use the systemctl command to configure systemd for automatic bootup.
After rebooting the CHIP, you can connect to the access point through a 172.20.1.xxx IP address on your edge device.
I also added a few lines to the /etc/hostapd/hostapd.conf file, to request a network passphrase when an edge device tries to log into the CHIP-based access point. Again, this is very basic and should be fortified for a secure, production environment. For my prototype purposes, a passphrase approach is good enough.
wpa_passphrase=moseshorwitz (choose the passphrase here)
Saving and then rebooting, makes the CHIP ready to rock and roll.
In the “Lightweight Inter-Device Messaging with MQTT” story, from last January, I covered installing and running MQTT on the CHIP. I hadn’t made any major changes to the CHIP, since then, so expected the Mosquitto broker, to just start functioning as soon as it booted.
Sure enough, the CHIP booted correctly and I was able to attach my Linux notebook to the new access point, which I called “drtorq-port-1,” in the hostapd file. Using ifconfig, on the notebook, I also saw that it grabbed a 172.20.0.xxx IP address from the CHIP’s DHCP server. Awesome.
To test MQTT, I opened a new terminal on the notebook and excited the following command line to set up a subscription to the mqtt topic at the CHIP’s IP address.
drtorq-notebook% mosquitto_sub -h 172.20.0.1 -t mqtt
Next, I opened another terminal and ran an MQTT “pub” command line.
drtorq-notebook% mosquitto_pub -h 172.20.0.1 -t mqtt -m test1
As soon as I pressed enter, “test 1” popped up on the mosquitto_sub terminal. I tried it a few more times, with a different ending number, just to make sure.
We can now do a lot of interesting things, like employing multiple ESP8266/PIR sensors and maybe sending messages out to robots/edge devices that light up LED strings or runs a motor. Let your collaborating edge-device imagination go wild.
I actually tried the CHIP/MQTT broker with the old 2400 mAh cell phone battery, that I use for the Raspberry Pi-powered Steampunk Badge. The result was disappointing because the CHIP only ran for a minute or so, then the CHIP’s LEDs all went dark. Maybe it’s pulling too much juice. Will have to investigate and troubleshoot.
I just went out and tried the CHIP in the car. Worked like a charm. That’s with the CHIP hanging from the rear-view mirror and plugged into a car USB adapter. There’s also about 50 feet and four walls in between the CHIP and my Linux notebook. Top that!
So that’s that, a rudimentary portable, wireless data hub prototype made from a CHIP computer. Go forth and build something cool. MQTT has certainly pivoted away from just being the star of the industrial controls crowd.
Feature image via Pixabay.