Archive for the Linux 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.

 

Ah, the thick plottens!

Posted in Linux, Networking on June 24, 2017 by asteriondaedalus

So, even with the static IP set on the parallella the TerraTerm console keeps disconnecting after a time.

Then it dawned on me, the connection was being broken because the PC IP would expire and pick up another from the DHCP in the router.

So, the unwritten story is that you need to set the IP address of your working PC to static as well – so that IP addresses at both ends of the connection persist.

Now that I have set my PC to static IP, TerraTerm does not close down.

Is this the last straw?

Posted in Linux, Orange Pi on June 21, 2017 by asteriondaedalus

So, now after a couple of weeks of dicking around trying to sort the booting of the OPiZ – so it starts up with node-red and emqttd, it works!

Or at least I can say the both services start up.

But, of course, this last couple of days I had trouble browsing into the node-red and now, in hindsight, it seems my OPiZ was occasionally not starting up connected to the ethernet.

After all the work to get around the fragging of the board, and working out the trick to using nmcli, the OPiZ would occasionally boot with no IP (static or otherwise), no gateway setup, no DNS?

It is now worse having put the board into the case.

The simple act of screwing it in and now system boots with no network at all.

So, fingers crossed – I will type in all the nmcli commands again.

Arrrrr … no.

If type all the data again and then use the “route -n” command I get naught – meaning:

root@house:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
root@house:~#

 

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).

 

GaaaaaaaaaaaaaaG!

Posted in Linux, Orange Pi, The downside of Opensource on June 18, 2017 by asteriondaedalus

So, various things on follow up to mqtt as a service.

You can have a /etc/init.d/mqtt file (works from console but doesn’t work as a service and therefore does not work at boot)

You can have a /etc/systemd/system/mqtt.service file (doesn’t work)

You can have a /usr/lib/systemd/system/mqtt.service file (doesn’t work)

Closest thing that appears to hint at what the problem might be is that emqttd starts with console but systemd baulks during service startup.  Noting that /etc/init.d/mqtt works from console but won’t work using either of “service x start” or “systemctl start x” then that appears to “behave” in a way that would suggest console interaction with systemd.

Changed /opt/emqttd/bin/emqttd to turn off console on startup (doesn’t work).  Or at least the example code I used does not work as advertised.  The change suggested is from:

-args_file $RUNNER_ETC_DIR/vm.args 

To:

-args_file $RUNNER_ETC_DIR/vm.args -detached -noinput -noshell -- ${1+"$@"}"

Not to mention that, for some reason, the mqtt.service options seem to “break” the node-red startup somehow.   When I log into the OPiZ, pm2 show tells me node-red is online but browser fails to connect.  If I delete the mqtt services and reboot I get node-red running on boot as expected.

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.

So wearing …

Posted in Linux, Orange Pi, The downside of Opensource on June 16, 2017 by asteriondaedalus

… goddamm fracking frack!

So, again different versions of versions of linux.

So, apparently I can change the timeout of a service with:

systemctl set-property mqtt.service TimeoutStartSec=x

If and only if I have a TimeoutStartSec property that is, you guessed it.

Turns out, there is a TimeoutStartUSec … woop … er… already set to five minutes.

doh

So theres goes that theory.