Landing on two Feet

feetSometimes I really do land on 2 feet.  So the ESP/MQTT rig now appears bulletproof and in a timely fashion the Raspberry Pi appears just in the nick of time. All I need is an easy to use Mosquitto/Node-Red setup and …. what should appear but a link to this …

I can see it’s going to be a busy weekend of discovery.

I was wondering how to make the thing programmable without having to blow the flash – and it hit me tonight… give the unit a default unit number to prefix any subscribes… and… use MQTT messages to rewrite the default unit number and any other info – and reboot!! Easy (well, of course, it won’t be).

That’s enough for one day.


26 thoughts on “Landing on two Feet

  1. I'm not sure I follow - are you talking about re-configuring it upon each reboot via messages sent via MQTT? Maybe a unique topic for each node where the node publishes a 'configure me' message when it connects, a configuration server then responds with a series of messages published to the same topic? Kind of like a device specific DHCP server.

    1. /node123/stg/io - msg for port setup, automatic subscribe on sturtup
      /node123/stg/rule - msg for setup logic, automatic subscribe on sturtup
      /node123/cmd/in - write status
      /node123/cmd/out - waint command

  2. Pete,

    Don't forget to make sure the version you try to run is compiled for the new RPi 2. By the looks of their download page they only support the original RPi.

    1. Yes Adam, as a Pi UTTER NEWBY I will be counting on others for guidance - OH and guess what, RS just sent me an email to say that due to unprecedented interest there could be a delay... pity they could not have managed that BEFORE they got me all wound up.. I'll give it a couple of days and beyond that they can keep it.

      1. The Raspberry Pi 2 was officially launched this week, with alot of press, so I expect there's been a small avalanche of initial orders.

        It won't be as bad as the launch of the original Raspberry PI, when some customers waited months...

      2. Don't worry Pete, I'm completely new to this as well so I'm in the same boat.

        I went with a Beagle Bone Black in the end as it seemed much more capable than the Rpi (this was before the announcement of the new version that is, DOH). It's not as well connected as the Pi's but with a 1GHz A8 and 512MB DDR3 it will be more than capable of running MQTT and OpenHAB and a few other things in the back of a cupboard somewhere.

        It also has 4GB of EMMC on board and works straight out of the box which is a bonus.

        As a side note you may be interested in this MQTTwarn if you haven't seen it already. Looks pretty Awesome.

    2. Adam

      On the RS Pi2 web page it states 'Backward application hardware and software compatibility has been maintained with the Raspberry Pi 1 Model A+/B+. "

  3. I like the direction you have taken with this system. I am trying to develop something very similar.
    I am wondering how you plan to store the data collected from the MQTT broker?
    I have installed mosquitto on my NAS box but have yet to make the leap to get the payload data into a database.
    On the thingbox, node red at least supports database connections, not that I have tested this either yet.
    I also wondered if you had a need in your system to use the esp8266 modules as soft-access points that other ESP modules could connect to?
    or, is a 'back bone' wifi network absolutely required?
    My particular use would have these spread over a wide area.

    1. The data coming out of the MQTT broker: Well, the time info is used to update a 32 bit timer in the ESP to maintain time, the dawn and dusk info along with on-off settings are written to FLASH (if they have changed). I've simply adapted the existing flash storage used in the MQTT software though I plan to re-write that shortly thanks to another reader who suggested a better way to maximise the number of writes. The bit I'm missing right now is the control, feedback and graphing. I'm pondering using openHab for the first two and the developer of MQTT-Spy is looking to introduce simple graphing soon - though I am surprised at the lack of simple services to go from MQTT directly to graphs. If you want to put the data into a database - and I must stress I've not tried this particular function, it would appear that node-red is one way to do that. There was indeed a project that one guy was working on to make a mesh network of ESP8266s which would have been another way.. but I don't think that's going anywhere - similarly the other MQTT project I noted hasn't been updated for ages and it was not complete. So right now, in order to send messages freely from one ESP to another and to other systems, the MQTT code seems the best bet. In my setup a backbone WIFI setup is necessary.. I'd prefer not but then, if there was no WIFI router you'd have no way to get to the outside world!! The only thing I've not touched up to now is using the ESPs to send MQTT back and forth to an Arduino. For example we still don't have code that works reliably on the ESPs to run serial LEDS - that needs some tight assembly code. I have all of that on Arduino but what I have done is to send incoming messages out of the serial in this format... {red:12;green:255;blue:0} and it's quiet easy for the Arduino to pull that info out of other status serial info... what I don't have is serial into the board to allow for an Arduino to send MQTT messages out. All in good time. Right now I want to get some kind of mobile interface going to start using these boards for real control. I have at this point only one issue, when my MQTT server stopped running for the first time yesterday, I thought it might be my WIFI router... so I reset that - and during that process, the ESP board crashed... I have no idea why and I've been unable to replicate it since. I'm currently in London monitoring the kit on my laptop with MQTT-SPY and the little board back home is sending out temperature every 5 seconds absolutely without a hitch but clearly I need to be able to replicate that crash in case there is a remaining bug in the MQTT code.

  4. So - any PI experts here?? Given that I want to run Mosquitto, Node-Red and a PHP page using CRON or similar scheduler - and given that I'll receive a box in the post with nothing on it.. what's the best starting point - ie version of operating system, basic necessities? The box will end up in the loft with a battery backup so I want to be able to remotely access via a Windows PC... thoughts?


      Download the noobs image from the raspberry pi site, you'll need a micro SD card 8-16Gb should do you for quite a while :), although I've used 2Gb in the past, depends on how much stuff you want on it.

      A nice case off ebay should be ordered to keep it protected, any model b+ case should do.


      1. For cross platform gui remote access, you can't really go wrong with team-viewer.

        You can, of course, use ssh to communicate with the pi, although this is command line, and we all know your thoughts on that 😛

      2. Downloading the noob setup and the formatter, got the 16gig card.... concerned about the revelation that the new board is an A7 and wondering therefore if the existing setup is going to work..

        1. Pete I just found this

          "However while the new board will need an ARMv7 kernel and modules, user space binaries built for ARMv6 can continue to be used, which means that the new board is fully software compatible with existing Raspberry Pi distributions of Linux.

          So from today you should be able to ‘apt-get upgrade’ on an existing Raspbian installation to add an ARMv7 kernel to your distribution. The SD card can then be used — assuming it’s a Micro SD Card — to boot either a first or second generation Pi. Card images, along with a new NOOBS image, will also be posted that support both boards"

          This is from an interesting article here

          So you should be safe with the NOOBS image.

  5. Bill

    The backwards compatibility with regards to software mean programs and scripts that run on the OS.

    The OS however has to be compiled to run on a specific Processor (think trying to run any version of 64bit Windows on an old Pentium 32 bit processor, it just will not work). The old Pi had an ARM 11 processor whereas the Pi2 has an A7, completely different architectures. I am by no means an expert in these things but I am pretty sure I am correct on this, perhaps someone more learned in such things could confirm.


    I e-mailed the guys at Digital Airways (Thingbox) regarding adding support for the Beagle Bone Black and also asked about the Pi2, he said they would support the Pi2 but was quite rude with regards to the BBB.

    You should have a look at the Beagle Bone Black, it works straight away without any SD card needed and has some pretty cool features;
    BoneScript is a Node.js library specifically optimized for the Beagle family and featuring familiar Arduino function calls, exported to the browser.
    Cloud 9 Web IDE

  6. Pete,

    I've been following you blog posts and like many others I am embarking on a similar project. I currently have several Home Automation sensors and nodes that are bases on arduino + rfm12b transceivers all controlled by Openhab as an controller. I have since been moving my architecture to use MQTT as the transmission protocol with Node-Red translating serial messages to MQTT pub/subs.

    This post caught my attention as I have been working on a ESP8266 node that is controlled by MQTT but wanted it to also be dynamically configurable so I didnt have to mod code. My nodes all perform similar task, they either post temp/humidity, control a PWM source (led strips), post the status of GPIO (motion sensors etc).

    So far I have my design is still very much a work in progress, but what I have is similar to what you suggested. A new node boots up with a Device_ID of 99 and a default base path of /new/ and it subscribes to a bunch of topics under this base path for the GPIO's

    I can then send an MQTT message to /new/99/cfg/setBasePath with a new base path such as /home/bedroom/ and then send a message to /new/99/cfg/setDeviceID with a new node like 2 followed by a message to /new/99/cfg/reset which reboots the device. Once it is rebooted it comes back up but subscribes to topics using the new base path and device is ie. /home/bedroom/cfg/...

    Next I am trying to work out how to use the JSON library, so I can send a MQTT message with a json body to configure the pub/sub settings for the GPIO pins ie. PWM, Normal GPIO, Sub or Pub.

    Hope that makes sense.


    1. It does and I like it - I think that's next on the cards for my setup.... and when you figure out how to use the json library would you let me know as that's something I've been putting off. Yup... like it...

      1. haha I will do, although my C is very rusty. It's been many years since I have coded in C so it's taking awhile to come back to me. My fall back plan is an individual cfg topic for each GPIO that I want to configure. But that gets pretty ugly.

        Also regarding the Rpi, Installing Mosquitto, Node_Red and Openhab isn't that tricky, you will need to get your hands a little dirty with the command line. But it's not hard, just start with the noobs rasparian image and you can find heaps of guides if you're not familiar with Linux.

    2. When you come up with a solution for all the pins, please do share, the setup is a nightmare not helped by overly complicated looking defines. I'm at a total loss as to why the higher up pins don't respond to the same commands as 0,2,4 and 5. Other nice thing for me would be if someone set up the serial input as the time will come when I'll want to pass some commands onto an Arduino and get something back to send status info back out from the Arduino. I wonder how many of us are re-inventing the wheel here.

    3. Ok I've implemented the numbering system (on the train from London, no mean feat I can tell you as the train is bouncing all of the place), works a treat... erm but I've realised I have no idea what the C command is to reboot the board... want to give me a hint?

      1. yup here you go

        os_sprintf(subTopic, "%s%s%s", sysCfg.base_path, sysCfg.device_id,"/cfg/reset");
        if (os_strcmp(topicBuf,subTopic)==0) {
        INFO("Receive Config MSG: %s, data: %s \r\n", topicBuf, dataBuf);

    1. Thank you. At this rate I'm not seeing the new Raspberry turning up soon - RS Components website promised next day delivery, they've failed to manage that, THEN sent an email out with no real info on and the tracker just says "order in progress". They used to be a reliable company (if a tad expensive - no, a LOT expensive).

Comments are closed.