Raspberry Pi Monster Script Part 3

I’ve updated the script – gotten rid of MYSQL – too many questions about SD life – and I have to say, SQLITE3 – though slightly different takes mininal modification of SQL assuming you’re doing things like logging of data and relatively straight-forward queries – it really is worthwhile. Apart from admin there are no passwords as it is not meant for massive, multi-user environment on a big server – it is meant for jobs just like this. The file is a simple file that can be moved about and it works well.  Even my PHP queries took only minutes to change to work with SQLITE3 and recent PHP versions support it directly so no need for extra libraries.

I’ve also taken out RabbitMQ in favour of Mosquitto as I needed websockets compatible with THINGSTUD.IO and RabbitMQ wasn’t having it – so after a lot of messing around I finally got websockets and Mosquitto running together and compatible.

Finally I have added support for speech – SERIAL and GPIO – all of it works. I’ll put Node-Red examples on the blog as time goes on.

“The Script” – has since been updated considerably and you should refer to this article

44 thoughts on “Raspberry Pi Monster Script Part 3

  1. Thanks for the script, it made installing the modules much easier. I followed the instructions in the youtube video by Peter Oakes and everything installs fine. However I am unable to use any of the Johnny5 nodes in Node-red. If I start node red using ‘node-red-start’ and create a flow with a Johnny5 node, the instant I deploy it, node-red will crash with the following error: wiringPiSetup: Must be root (did you forget sudo?) /usr/bin/node-red-pi Aborted nodered.service: main process halted. So I tried starting with ‘sudo node-red-start’ the same thing happens – it crashes. What am I doing wrong?

    1. Personally I’ve not used Johnn5 modules so it would be nice if someone else has the answer. We also now have this PIGPIO stuff….. I tried the i2c on that and it worked.

      1. Tim, does this help:

        As of this writing, node.js (version 0.10.29) and the node-red application come pre-installed on raspbian, however for us to use johnny-five we’ll need to run node-red as the root user.

        Edit the /etc/init.d/nodred script in your favorite text editor on the pi. Switch the line containing USER=pi to USER=root

        In the latest version of raspbian (2016-03-18-raspbian-jessie), the script file is /lib/systemd/system/nodered.service.

        From here: https://github.com/rwaldron/johnny-five/wiki/Getting-started-with-Raspberry-Pi-node-red-and-IoT

        goodlick!

        1. Hang on a minute – doesn’t changing to root make all your flows disappears as you’re no longer the original user?

        2. And the latest version of Raspbian I have only came out weeks ago – does this change anything?

          1. Yes Peter, flows disappear indeed. I couldnt get Node-red i2c working, made a mess of my setup and I’m now trying to get your Monsterscript working. Once I get there I can continue trying, for example to see if the new Raspbian version makes a change…

  2. Hi I’ve come back to this project having just received an OrangePi. I then set about loading the 2 scripts (newer Orange script). I referred back to Pete’s blogs on “monster scripts” as I had done before with the Raspberry but they seem to be edited and no longer have the fools guide as to where to place the 2 files and the command line to run them. Also the link at the bottom of script 2 is dead. Sorry I struggle with linux.

  3. You might want to put

    if [ “$(id -u)” = “0” ]; then
    echo “Sorry, you tried to run this as root tsk, tsk.”
    exit 1
    fi

    at the start which will ensure you don’t start the script with sudo accidentally 😉

    You can also install different versions based on the cpu the Pi has using the following:

    #Run CPUINFO get 3rd bit of revision line if starts with 1000 over voltage so strip out
    #then get first character of whats left
    #http://elinux.org/RPi_HardwareHistory#Board_Revision_History

    PITYPE=$(cat /proc/cpuinfo | grep ‘Revision’ | awk ‘{print $3}’ | sed ‘s/1000//’ | cut -c-1)
    echo $PITYPE

    #If its an a its a RPi2/RPi3
    if [ “$PITYPE” == “a” ]; then
    echo “RPi2/RPi3”
    #add the bits for a RPi2 & RPi3 here
    else
    #its an older pi
    echo “Older RPi”
    #add the bits for a RPi & RPiZero here
    fi

      1. No problem.
        It would also make sense to do the

        “sudo apt-get purge -y wolfram-engine
        sudo apt-get autoremove -y scratch
        sudo apt-get autoremove -y sonic-pi
        sudo apt-get autoremove -y minecraft-pi”

        bit up front as at the moment you are upgrading them (along with everything else on line46) to the latest version to then delete them.

  4. I have spent countless hours trying to get node, nodered, lamp, and webmin to play together on the same RPi2. Insanely, expecting a diffeent outcome, I kept trying every formula I could find, over and over, only to be unsuccessful, repeatedly,

    Then I tried your script.

    It worked! Just worked, first time.

    Thanks for this, I learned a lot too.

    1. Thank you – I too spend endless hours on each bit, failing over and over – and when I finally got it, put it in the script. If come come up with improvements or additions or changes – by all means fire them back in here… the script is a work in progress and will need some alteration for the latest Raspbian recently put out.

  5. Right… I’m so very very sorry, but just spotted on my new PI the writing “model B+…”
    I have somehow clicked the wrong button when ordering it and when it came with shiny new 4 USB ports and micro sd (as compared to my older PI s) I assumed it was the latest and greatest.
    Sorry again for wasting everyone’s time. I feel such a fool!
    John

    1. Don’t worry I’ve made MUCH worse mistakes than that. I’d imagine you’ll get much of that back on EBAY – meaning a new Pi2 will cost very little – trust me – it’s worth it – way more powerful. I just can’t get my head around how much processing I’m getting out of Node-Red (on my new stat) and the Pi2 is not blinking an eye…

  6. root@raspberrypi:~# which node
    /usr/bin/node
    root@raspberrypi:~# sum /usr/bin/node
    32011 9439
    root@raspberrypi:~# shasum -ba 256 /usr/bin/node
    edbcaafb85841c7d26b210d4a5c56752b412d9165696ab08d75d126157f2f2ed */usr/bin/node

    and also…
    root@raspberrypi:~# npm -v
    Segmentation fault

    1. Okay, it looks like you’re both running the same binary but with different results, which would point
      toward a hardware error on John’s system.

      Another couple of checks, please (both Pete and John).

      Please reboot your system and then:-

      – uname -a
      – egrep -i “linux version” /var/log/syslog
      – egrep -i processor /var/log/syslog
      – egrep CPU /var/log/syslog
      – ls -al /usr/bin/node
      – /usr/bin/node -v
      – tail -20 /var/log/syslog

      We might get to the bottom of this eventually. 🙂

  7. I’m at a loss guys – I have 3 different Pi2s using different 16Gig cards…. incidentally I’m setting up Wheezy using Berryboot but that should not make a difference – and I am not getting these issues.

    No reference to node red or npm will occur until the script has run.

    1. Pete,

      It’s not your script. It just seems that John is picking up an different revision of the NodeSource stuff somehow. I would guess that he’s probably on a different continent to you and may be getting directed to an out of date mirror. There may also be a regression problem of some sort with the NodeSource releases.
      It seems pretty clear that node/npm from other versions do work for John and this has certainly been a known problem for RPi users (and other ARM architectures, too) in the past.

      It’s also just possible (although highly unlikely) that John does have a memory hardware problem with his RPi that the NodeSource release version of node/npm just happens to be tickling, but given the history of the segmentation fault bug, I would doubt it.

      John & Pete, how about both of you trying to checksum the NodeSource version of npm which you have on your machines and comparing them? Try running the commands sum and shasum on the node binary:-

      “sum /path/to/node/bin/node”
      “shasum -ba 256 /path/to/node/bin/node”

      …and post the results. That should show whether the binaries are the same.

        1. Pete,

          It doesn’t matter which directory you’re in, but you should use the full path (starting with “/”) to
          the “node” binary. I’m sorry, I don’t have Raspbian on anything and I’m not running Node.js, so
          I don’t actually know the path to the binary myself.

          If you do “which node” it’ll tell you the path to the first “node” command found in your PATH setting, but that might not be the one which you’ve just installed (if, for instance, Raspbian has just decided to include it in their distribution by default).

      1. root@newpi:~# which node
        /usr/bin/node
        root@newpi:~# sum /usr/bin/node
        32011 9439
        root@newpi:~#

        root@newpi:~# shasum -ba 256 /usr/bin/node
        edbcaafb85841c7d26b210d4a5c56752b412d9165696ab08d75d126157f2f2ed */usr/bin/node
        root@newpi:~#

    1. John,

      Conor’s RPi compiled version makes no attempt to set up the node environment. His instructions just basically dump the node directory into /usr/local.

      If you look at Pete’s script, it’s actually downloading a package (the apt-get stuff) which does all of the hard work of locating binaries, libraries and documentation in the right places and installing the start-up script (which is what your error message is complaining about).

      Probably the easiest way to get around this is to use Pete’s script to do the initial part of the installation of the NodeSource package (up to the point where it starts to give segmentation errors) and then manually copy Conor’s RPi compiled “node” and “npm” binaries into place (WARNING – this is not quite as simple as it looks… you’re going to have to copy the library/node_modules directory, too).

      1 – Start with a clean install on your new SD card.
      2 – Run Pete’s script up to the node/npm segmentation point (by which time it
      has already installed the nodesource package).
      3 – Locate the NodeSource bin and library directories which you’ve just
      installed (use “which npm” to locate the bin and then “ls -al /path/to/bin/npm” to find the lib directory).
      4 – Copy and unpack the tar file which you downloaded from Conor’s site into /tmp.
      5 – Overwrite the existing node and npm files in the bin directory with Conor’s versions
      (we’re not bothering to make a backup, as they don’t work anyway).
      6 – Move the original lib/node_modules directory out of the way with
      “mv /path/to/lib/node_modules /path/to/lib/node_modules_ORIG”.
      7 – Copy Conor’s lib/node_modules directory into place with
      “cp -rp /tmp/node-v0.12.1-linux-arm-pi/lib/node_modules /path/to/lib”.
      8 – Restart Pete’s install script from the point where it failed (the node/npm calls).

      Don’t worry, it looks more complicated than it actually is. 🙂

  8. OK in case I’m doing anything daft…
    I’ve changed PSU
    Downloaded 2015-05-05 Raspian Wheezy.img
    Installed on SD card using win32 disk imager
    enabled serial and SPI and expanded memory
    tried npm -v .. command not found
    downloaded script again and ran it

    ——————————————————————————–
    Node-Red Installation
    ——————————————————————————–
    Elapsed Time: 00 hrs 46 mins 42 secs

    Installing Node-Red…
    ./hackitt.sh: line 428: 21140 Segmentation fault npm cache clean
    ./hackitt.sh: line 428: 21141 Segmentation fault npm install bcrypt
    ./hackitt.sh: line 428: 21142 Segmentation fault npm install -g –unsafe-perm node-red
    chmod: cannot access `/etc/init.d/node-red’: No such file or directory
    update-rc.d: using dependency based boot sequencing
    update-rc.d: error: unable to read /etc/init.d/node-red
    [OK]
    ——————————————————————————–
    Node-Red Module Installation
    ——————————————————————————–
    Elapsed Time: 00 hrs 46 mins 48 secs

    Install Node-Red modules…
    ./hackitt.sh: line 436: md: command not found
    ./hackitt.sh: line 437: cd: .node-red: No such file or directory
    ./hackitt.sh: line 479: 21193 Segmentation fault npm install raspi-io
    ./hackitt.sh: line 479: 21194 Segmentation fault npm install node-red-contrib-gpio
    ./hackitt.sh: line 479: 21195 Segmentation fault npm install -g –unsafe-perm node-red-node-serialport

    etc….
    I’m reticent to install a different version as that is likely to throw up other issues for me.
    thanks again
    John

  9. Thinkiing about this I’m wondering if people are all using the same script as I left an older one lying around – it worked of course. Anyway I’ve updated all 3 parts of the blog so there is only one script.

  10. Hi Guys

    Let me clarify – I am using Raspberry Pi2 – I have 3 of them here and I must have put the script (see latest update – just adding bits – was always working) on dozens of times – and although I may have had a site down occasionally, a spelling mistake here and there, I’ve had no node-related issues, no serious errors – ever. For some reason once in a blue moon the node-red password section in insists that the bcrypt module isn’t there – though since I moved things around I’ve not seen that. NOW – here’s a thing, I WAS getting a problem in that an installation using serial would crash after a while. Thankfully I would have two RPis sitting next to each other and I noticed that the Pi’s red light (corner) was on where the other one was not. I checked out Google and it turns out there’s a power sensor there. If you get that red light often – it is not enough power and that can cause issues. I simply used a better usb supply and the problem immediately and completely went away. That is the only thing I would be wary about. People say NodeJs has serial issues… but I say no – it’s working a treat. If you use my script which is far from polished, it all will work. Oh, when I load Debian (Wheezy) the first thing I do with Raspi-Config is to enable serial and SPI…

    Pete.

    1. Hi Pete,

      Great work. I tried your scrip and it worked out without big problems i just had a few ‘perl’ errors related to the setup of the location and language set in default (for some reason it didn’t like that ‘default’ setting) plus an warning while installing NPM (need to check details still – installed yesterday and it took 2 hours for this to run). I’m not sure about the effects of these but till now it does not look like there is any.

      I did however notice this morning something like your the latests remark about the RED led at the back of the PI. I’m using an IPAD 5v power supply that is the biggest i’ve got at the moment but if this is a problem what’s the rated 5V that would be the solution?

      Regards,
      Valdir

      1. Actually I’m still learning here. So here’s what happened. The red LED (for new readers we’re discussing Raspberry Pi 2 here) stayed ON on the first board I managed to get serial running on – and the serial crashed the board. Turns out the main reason it crashed the board was a conflict – the operating system and the SERIAL node both using the serial – however, advice on the web said bad power and that light being on constantly were connected – and sure enough when I put a better power supply on – all my problems went away. However, as I sit here experimenting with my new touch display (blog coming up soon, I’ve had great success with Node-Red and a serial touch display) the red light is flashing – not regularly – but flashing all the time – and the green light is flashing occasionally. I’m having no issues at all with the board. So clearly it’s not THAT clear cut. If anyone knows for absolute sure, comments here would be most welcome. So Raspberry Pi – I’d say at least an amp capability – and Orange Pi, at least 2 amps capability – but that’s just a feeling for now.

  11. John,

    No, it looks like there’s still a bug with the node.js version of npm and ARM processors.

    I’m surprised that no-one else is running into this (or that no-one else is reporting it, but
    given that this is a previously reported issue with npm and given that your RPi doesn’t
    seem to have problems with any other programs, it’s reasonable to assume that this is
    -not- a hardware issue with your system.

    It’s now pretty much up to you how you proceed. You can try replacing the node.js version
    of npm with the iojs version by following the instructions on the iojs.com web site (where you
    downloaded the test package from), or hopefully, someone else here with a Pi running
    Wheezy might chip in and help to identify why your specific system fails …different hardware
    revision, different base revision of Wheezy, different mirror server for your downloads, etc.

    As a start, you need to go back and check that your initial system installation image is exactly
    the same as Pete’s as a base starting point. Do a clean install on your new card using the image
    which he recommends. Before doing anything else at all, try the “npm -v” command again to
    check whether node.js is already installed by default (if it is, it could be the older, buggy
    version, which you’ll need to manually remove).

  12. Hi
    I followed your steps and the response was:
    2.14.3
    I have contacted Newit from whom I bought the PI and they say they are happy to take module back for testing, but is there a hardware problem? I’m afraid I’m out of my depth. thanks
    John

  13. John,

    In the link to issue #44 (above) there’s a suggestion that using iojs might be a
    partial solution. I’m not going to suggest you install it (I have no idea what iojs
    actually is), but you could download the package and run the same tests you just
    did (npm -v) to see whether the issue exists with that version or not. Don’t execute
    the following instructions as root. Do a “cd /tmp” before you start.

    Download https://iojs.org/dist/v3.3.1/iojs-v3.3.1-linux-armv6l.tar.xz into your /tmp
    directory (you can use curl or wget).

    Do “unxz iojs-v3.3.1-linux-armv6l.tar.xz” to decompress.

    Do “tar xvf iojs-v3.3.1-linux-armv6l.tar” to unpack the package. You should now have a new directory
    named iojs-v3.3.1-linux-armv6l. If you list that directory you’ll find there’s a “bin” subdirectory.

    Now try doing “./iojs-v3.3.1-linux-armv6l/bin/npm -v” and see what happens. If it doesn’t give a
    segmentation fault it probably means that you’re being bitten by the same bug that’s described in
    the #44 link. If it does give a segmentation fault it probably means you have a hardware problem.

    Other Readers:- If you’re seeing the same problem as John, please leave a note here. If you’re running
    “wheezy” on a Raspberry-Pi and have a few minutes to spare, please try the download
    of iojs (-into- /tmp) and let us know what the results of the “./iojs-v3.3.1-linux-armv6l/bin/npm -v”
    command are for you.

  14. I’ve just tried a brand new “PNY” card and get:
    pi@raspberrypi ~ $ node -v
    Segmentation fault
    pi@raspberrypi ~ $ npm -v
    Segmentation fault
    … same as before. I think purchase of a new PI 2 is a step too far!
    No idea where to go next.. very curious.

  15. Hi
    The card I have is a Kingston 16G. I’ll buy a new one today and try it.
    thanks again.
    John

  16. John,

    As I mentioned, I don’t have anything running Raspian/Wheezy, so I can’t check this
    myself, but it does look as though there was a known problem with npm and the RPi.

    https://github.com/nodesource/distributions/issues/44

    You might want to try running “node -v” and “npm -v” from the command line to check
    whether this problem is evident or not.

    If no-one else is reporting this error, it would point to a problem with your particular
    system, though. Did you try that new SD card yet?

  17. Hi I appreciate the help..
    I have started the install at line 525:
    “task_start “NPM and NODE Installation” “Installing NPN and NODE…”
    by cutting and pasting line by line in Putty.
    Line 541:
    npm cache clean
    gives me a segmentation fault but with no other verbose explanation.
    I am running with most recent version of “Wheezy” on a PI 2
    I’m at a loss.
    thanks
    John

  18. You can get a little more information from the script about where exactly things
    are failing by asking it to be more verbose just in the Node-Red section.

    Before the line:-
    task_start “Node-Red Installation” “Installing Node-Red…” [Line # 537]
    insert this command:-
    set -x; [Sets verbose mode]

    …and a few lines further down, after:-
    update-rc.d node-red defaults
    task_end
    fi [Line # 547]
    add this command (-after- the “fi” line):-
    set +x; [Verbose mode off]

    You can keep on moving the “set +x;” further and further down the file, if the
    segmentation fault doesn’t happen in that exact section.

    NOTE:- the line numbers refer to Pete’s Bitbucket file (see his link in the main
    body of his posting), just to help you navigate.

  19. John,

    Typically a segmentation fault indicates that a program is trying to access a section of memory
    which doesn’t exist. It can be caused by faulty hardware, but in this case it is much more likely
    that you’re trying to install a version of Node-Red which is for a different machine (ie:- trying to
    install an i386 package on you ARM machine). Make sure that the package is the correct one and
    that the download process completed correctly.

    -John-

  20. I’m also using Wheezy on a Pi 2 but consistently get this error. I’ve done a chkdsk on my 16G sd card which shows no errors, but will try a new card.
    John

  21. Hi
    I have made several attempts at running the script, but each time when it gets to node-red install I get “Segmentation fault” I have even moved it to the head of the queue. Any thought?
    John

    1. Sadly no as I’ve never seen that problem – and I’ve no idea what that message means. I update Raspberry Pi 2 using Debian Wheezy on a regular basis (usually after I screw something up) using that script – the only issue I get (and not always) is the Node-Red user addition – gripes about a missing library (which is not missing) and re-running that section fixes it. I’m doing one right now…. So I’ve no idea what is happening unless you’re using different hardware or software. I managed to get most of the script to run with an Orange Pi using a later Debian (I say most – the sound would not have it).

    1. If you spot mistakes – things which could be put together better etc, FEEL FREE to let me know – I’m after making this bullet-proof and as good as it can be – sadly I can’t do much about the way other people’s scripts handle things like password requests etc..

Comments are closed.