Archive for the node-red Category

Setup for home automation server

Posted in Linux, MQTT, node-red, Orange Pi on June 25, 2017 by asteriondaedalus

So, setup for house server on Orange Pi Zero 512kB using:

Armbian_5.25_Orangepizero_Debian_jessie_default_3.4.113.img

Ignore my previous posts where I use WIN32DiskImager.  Seems it has fallen out of favour (and might be the root of all the other problems I was seeing??!!).

Use Etcher as directed on the Arbian.org site, as well as a good quality Class 10 SD card.

On Windows you will get a fright because dopey Etcher does not nominate your SD card as a drive number (J: for example on my PC) – heaven forbid.   So it takes a while to work out it is happily point ONLY at your SD card.

Given all the warnings about using WIN32DiskImager (and trashing your computer) it was a bit arrgh! of the authors of Etcher.   I think they are trying to be hip *yawn*.

Login into armbian.org distro for first time and set up root and user accounts.

Setup static IP for your Orange Pi Zero using nmtui or nmcli (for power users).

Reboot and  then run:

apt-get update

Grab binaries for nodejs and install them:

wget https://nodejs.org/dist/v6.10.3/node-v6.10.3-linux-armv7l.tar.xz
tar -xf node-v6.10.3-linux-armv7l.tar.xz --directory /usr/local \
      --strip-components 1

Check install with:

node -v
npm -v

Use npm to install node-red with:

npm cache clean
npm install -g --unsafe-perm node-red

Test node-red out with:

node-red

Then go to your OPiZ static IP with your browser on another computer in your network.

1880 node-red Port

Next we are going to setup PM2 so as to start node-red as a service on boot:

npm install -g pm2
whereis node-red
node-red: /usr/local/bin/node-red
pm2 start /usr/local/bin/node-red \
      --node-args="--max-old-space-size=128" -- -v
pm2 save
pm2 startup
export PM2_HOME="/root/.pm2" # because I installed in root 
reboot #takes a while after rebooting but it should come up

Then go to your OPiZ static IP with your browser on another computer in your network – you should see node-red running.  Be brave, close the browser tab and re-open it, or refresh it.

Now let’s add erlang with:

wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb &&
dpkg -i erlang-solutions_1.0_all.deb &&
rm erlang-solutions_1.0_all.deb

Then

apt-get update && sudo apt-get install erlang erlang-dev elixir

Note you can leave elixir at the end of the previous command but emqttd following will rebuild elixir blindly over the top – bad citizen!

Now fetch and build emqttd:

git clone https://github.com/emqtt/emq-relx.git
cd emq-relx && make

Try out emqttd with:

cd _rel/emqttd && ./bin/emqttd console

 

18083 MQTT dashboard port

Go to your OPiZ static IP with your browser on another computer in your network – you should see node-red AND emqttd running.

Now let’s set up emqttd to start on boot:

cp -R emq-relx/_rel /opt/emqtt/
mkdir /usr/lib/systemd/system
nano /usr/lib/systemd/system/emqttd.service

---- inside of nano ----

[Unit]
Description=emqtt daemon
After=network.target

[Service]
Type=forking
Environment=HOME=/root
ExecStart=/bin/sh /opt/emqttd/bin/emqttd start
ExecStop=/bin/sh /opt/emqttd/bin/emqttd stop

[Install]
WantedBy=multi-user.target

---- exit and save from nano ----

chmod +x /usr/lib/systemd/system/emqttd.service
systemctl enable emqttd.service
reboot

I copy the whole _rel directory over to /opt because I tried moving only the bin directory BUT when I tried running it came up with an error.

Go to your OPiZ static IP with your browser on another computer in your network – you should see node-red AND emqttd running without having to login!

Enjoy.

 

Finally, a new mqtt based node-red server

Posted in Linux, MQTT, Networking, node-red, Orange Pi on June 21, 2017 by asteriondaedalus

So, much pain but lotsa learning!

Final story.

 

If you are using:

  • OS: armbian.org debian server: ARMBIAN 5.31 stable Debian GNU/Linux 8 (jessie) 3.4.113-sun8i
  • Erlang/OTP: V9.2/19
  • EMQ: 2.2
  • Orange Pi Zero 512kb (and fragged by expansion board 😉

Ignore the service definition at the emqttd site

DO NOT CREATE /etc/init.d/emqtt – because systemd is installed in ARMBIAN 5.31 and systemd uses UNIT files (as emqttd.service below).  The /etc/init.d/xxx file should be ignored if the UNIT file is there but why clutter and have junk around.

Then do the following (from root):

mkdir /opt/emqttd
mkdir /opt/emqttd/bin
cp -R emq-relx/_rel /opt/emqtt/
mkdir /usr/lib/systemd/system
nano /usr/lib/systemd/system/emqttd.service

---- inside of nano ----

[Unit]
Description=emqtt daemon
After=network.target

[Service]
Type=forking
Environment=HOME=/root
ExecStart=/bin/sh /opt/emqttd/bin/emqttd start
ExecStop=/bin/sh /opt/emqttd/bin/emqttd stop

[Install]
WantedBy=multi-user.target

---- exit and save from nano ----

chmod +x /usr/lib/systemd/system/emqttd.service
systemctl enable emqttd.service
reboot

voila!

Thanks awfully to @turtleDeng.

There is, of course, a new problem.  Both node-red and emqttd services start every time the OPiZ boots.  However, for some reason (tonight for the first time) connection to LAN is not coming up every time.  It comes up with no IP, no gateway, no DNS addresses???

Reboot a second time and it comes up.

This new problem means I will need check after brownout, or cycle power on ISP gateway (where the OPiZ will get its power … assuming there is 5volts on the USB port on the gateway).

 

The problem with the internet …

Posted in Linux, node-red, Orange Pi, The downside of Opensource on June 17, 2017 by asteriondaedalus

… and all you need is that one page you can get to from anywhere in the world, though it might be obfuscated by all the other pseudo pages on the same topic.

So, to get the node-red to run on boot I used the following (see “Starting Node-RED on boot”)(as root):

npm install -g pm2
whereis node-red
node-red: /usr/local/bin/node-red
pm2 start /usr/local/bin/node-red --node-args="--max-old-space-size=128" -- -v
pm2 save
pm2 startup
export PM2_HOME="/root/.pm2" # because I installed in root 
reboot #takes a while after rebooting but it should come up

The max-old-space-size=128 is based on suggestions for RaspingBreathBurryDoodle Pi and Beaglebone Black, which both have (as does the Orange Pi Zero) 512Mb of memory.

So, now that fraking emqttd, which does not start as a service on boot, is the last hurdle.

Wow, that turned out to be simple

Posted in Embedded, node-red, OpenSprinklette, Orange Pi, The downside of Opensource on June 13, 2017 by asteriondaedalus

So voila!

calendar

This doesn’t look like much but it made my teeth grate for the longest time.

The problem was setting up node-red on the OPiZ (and indeed the ODROID-C1) I could not use the google calendar as planned, for setting sprinklers on/off, because the embedded machine’s IP would not resolve to the domain name “node-red.example.com”.

Turns out I had the right idea, I just set the IP address incorrectly in my hosts file on my PC.

The problem was fixed by setting the c:\Windows\System32\Drivers\etc\hosts on my PC with the correct IP address of the OPiZ (I noted I had shrapnel there from the ODROID-C1 attempts and realised I had a 178 in place of 168 in the IP preamble).

The figure above shows now browsing from the PC into the OPiZ which is running node-red.

What you are seeing is a response from a google calendar I set up (to ping the node-red server when an event start occurred).   My heart stopped a little when the google api exception popped up (though that itself told me we were talking).  The start event I set came through regardless (so it must have resolve the lists in the background in any event).  The strange problem being that there is a time sync problem between what my computer says is the time and the calendar.  I can get events from calendar two minutes early according to my computer.  Likely source is whatever “clock” google calendar is running to (it reports the correct time from perspective of the calendar).  Something to track down.

Not the best solution, setting up a hosts files on every machine in the house is doable but there has to be a smarter way?

Now I have to muddle through the emqtt install again.  The problem there ended up none of the examples for starting the emqtt as a service worked for the armbian distro.

Swapping out …

Posted in MQTT, node-red, Orange Pi on May 19, 2017 by asteriondaedalus

… or in.

To give my cluster back an ODROID-C1, I got a 512M Orange Pi to host the mqtt and node-red for my house automation.  It is tini, even with the case ( a couple of match boxes in size ).  So, un-obtrusive to boot.

I will get a couple more once I have sorted some software to monitor my barking dogs.    Python based signal processing to detect the dog back and then, perhaps, hooked into sprinkler zone the dog barking is detected in.

I have an IR sprinkler guarding the side of the house.  Neighbors complained that they’d been barking daily for 12 months, why wait 12 months before telling me?  So they became set in their ways.  However, the sprinkler works the dog psychology as it breaks the fixation on the noise.

However, of course, I want to be a little more sophisticated.  I want to record the activity so I will get a camera for the OPi later.  Wifi it up to the home PC.  Because it has GPIO ports it could also drive a solenoid valve, a horn or a shaker (marbles in a coke can will distract the dog as it doesn’t like that type of noise).

Untitled

Parallela turned up so it and the C1 will be fitted this weekend.

I relented on the idea of an old multi cpu server.  I am fickle … I know.

It’s getting REAL!

Posted in ESP8266, Lua, MQTT, node-red, OpenSprinklette, Wifi on July 12, 2016 by asteriondaedalus

20160712_183121

So the four-4-US$12 flow sensors have turned up.  The minimum measurable flow rate appears to be 1 litre a minute.  To put this in perspective Bob Hawke (ex Australian Prime Minister) sculled a yard glass (1.4 litre) of beer in a record (for the time) 12 seconds.

In comparison irrigation “emitters” tend to be in the ranges of:

  • 2,0 liters/hour – 1/2 gallon per hour
  • 4,0 liters/hour – 1 gallon per hour
  • 8,0 liters/hour – 2 gallons per hour

Now this will be per emitter so you will need around 8 times 8,0 liters/hour “emitter” in a line to get a 1 liter/minute flow by napkin scribbles.  A whopping 30! 2,0 liters/hour “emitter” will be needed to get a 1 litre/minute flow in a line.  Note, there may well be more than enough “emitter” to turn the paddle but that will depend upon the individual installations.

Not really a problem as the intention was to use this as a leak detector as the rate will be driven up but the leak, especially if your dog has dug up and chewed through a hidden hose, as evidenced by …

20160617_083246

… mind you that one didn’t need a leak detector to find.

These sensors are advertised as low precision in any event so really not a problem.  So this won’t be of use to meter your water usage.

I am playing with the idea of higher precision flow sensors – to set time-versus-budget constraints  – but I will roll that in as a separate option as such a flow meter can likely go on the input rather than output lines, and as we are using MQTT the high precision flow-sensor can also be separate unit to the valve controller/line flow sensor.

All the signal integration will occur in the main host.

Hot damn!

Posted in MQTT, Networking, node-red, ODROID-W on January 3, 2016 by asteriondaedalus

node-red-pi

node-red running on my odroid-w.

I have my old blackwidow working with a relay shield so I can drive sprinkler valves but I could not sort mqtt onto the older dopey wifi shield – just lazy.  So I will use node-red to drive tcp chatter to drive the relays and drive that with mqtt via the node-red.  That way I can integrate the board gently, using its current libraries.

Next experiments include, yes, sorting that static IP story.

Then getting mosquitto up and running.

There are a few warnings in the node-red install that I need address (upgrades of dependencies).  Otherwise I am looking at a thingybox the size of a matchbox.

Sensibly though I am looking at a small 220VAC-5VDC module to build the whole thing into a 3 Pin Plug Pack Case.

case

Yes, yes.  All would have been easier with a fresh download of the Jessi distro – since it comes with node-red.  But I do like the labour.

Still, the final version will be on a fresh Jessi distro so that I only need the mosquitto install to get this rolling.