MongoDB on the Pi

MongoDBI’m busy compiling MongoDB for the Pi and it’s going to take hours apparently – so I figured I’d give you some updates while I’m waiting.

I’ve made some progress with my little ESP8266 board (ESP-12) in terms of deciding how to handle MQTT.  Initially I had a bunch of subscribes to various topics and at some point it hit me.. really, you only need 2… one with your ID (whatever you choose to use) for messages coming in specifically to that one board – and another which does not have an ID attached – i.e. a sort of global incoming message.  The actual message content than then therefore decide what actually happens.  In my case I might want to get the temperature, or turn an output on – or even pass on a message to an Arduino via the serial port.  I’ve done this by coming up with a simple message format not a million miles away from JSON (don’t any purists start on me).  By taking in the message then looping through – I can do several things at once.

So for example lets say this particular ESP8266 unit is ID 999.  I send a message from say the PI to 999/to_esp and the content might be {out1:1;temperature:;ext:”rgb:red=255,green=5,blue=50”}

Let’s break that down… so the first instruction is out1:1; which turns output 1 (GPIO0 on). As it happens I also have it send a message back to confirm that status. The next thing is temperature:; You’ll notice there is no argument there – and that is a request to return the temperature in an MQTT message – which it does. The third item is this.. ext:”rgb:red=255,green=5,blue=50” which does not need a semicolon as it’s the last item in the list… what that says is – here’s an external command to pass to the serial port so that, say an Arduino can handle it.

So what goes out of the serial port after a little dressing is… {rgb:red=255,green=5,blue=50} and I’ve already written the Arduino code to watch for a package coming in the serial line and acting accordingly; In this case it will start a series of high speed pulses out to a port bit to control a 5v serial LED strip WS2812b ….it can do a nice soft fade as it is not taking up any of the ESP8266’s time.

Had I sent the version of the command to the board with no ID, the result would be the same but no return messages would be sent – so that means you can with one command turn everything on or off no matter how many little ESP8266s you have.

NoSQLSo that’s nice but what does it have to do with MongoDB? Well (still compiling and will be for hours – if you want to have a go try this link but don’t blame me if it does not work as I’ve not tested it yet) – I watched a Node-Red demonstration and the guy was using MongoDB which is a “NoSQL” database which basically works on keys – and one of the more notable aspects was that you don’t have to go defining tables etc., you just give it a name for the data you want to store – and store it  – that seemed eminently civilised and so I figured I’d install it on the Pi (a Pi-specific version in the link) – and so with warnings that it will take several hours – that’s what I’m doing. 

I’m constantly amazed at how these very long and involved loading and compilations actually work – I’m always waiting for something to go wrong..

Still standing by my original comments re: ESP boards.. score ESP-12 10, ESP201 0.

More later when the Pi actually does something other than sitting looking busy.

Update: An hour later, accidentally pulled the plug on the Pi – had to start again…… 2 hours later – after many, many warnings but no errors, lots of “deprecated” messages but the install looks to be done.. just some housekeeping to do… late evening:  It works – considering the number of warnings I had my doubts but the mongo connectors in Node Red are working.


4 thoughts on “MongoDB on the Pi

  1. I’ve been following along with your blog and ESP community posts – good job and thanks for sharing!
    your posts remind me of the old Chaos Manor column from Jerry Pournelle.
    A comment on your mqtt design in the ESP…
    btw I’m still using Lua (nodemcu), haven’t made the switch to the native firmware for various reasons.
    Anyway – mqtt…
    I’ve got some ESP01’s with DS18b20 which publish mqtt messages every 30 minutes or so.
    And some ESP12’s with PIR, light, and DHT22 which publish when presence is detected.
    It’s taken some juggling but I’ve gotten the software down small enough to compile and run.

    So far I’ve been powering them with either wall warts or USB battery packs with 1117 regulators.
    My goal is to power them with little 3.7v lipo packs, solder the tiny wire to do deep sleep, and see how long they last.
    With my method -synchronously publishing every so often- I should be able to deep sleep between the publish times. I think.
    The problem that I think I see with your mqtt polling for publication is how do you work in deep sleep with the async nature of the polling to publish?
    would you use the mqtt message level mechanism?

    thanks again for the great source of info!

    1. Believe me – ANYTHING is better than compiling the binaries – thanks for that – will come in handy for my second Pi… that took HOURS

Comments are closed.