Archive for the Embedded Category

Niggly

Posted in Embedded, MQTT, NodeMCU, OpenSprinklette, Orange Pi on August 16, 2017 by asteriondaedalus

I may have some more design work for the opensprinklette node-red implementation.

The nuance is that the google calendar node will happily trigger on event edges but the triggered response seems to be a dump of the calendar event parameters but not the edge that triggered the node.

It might be as simple as another parameter on the configurator to tell it whether it is for sprinklers on or off

The other might be using the before event.

Have two outputs then to act as start and stop.  Feed the stop into a timed node.

Either lapsed or absolute is another question.

Much of this is trying to think in a dataflow rather than an imperative idiom.

I want to think also about ACK from the WeMOS sectors. That might want a watchdog timer.

The lwt from the WeMOS sector will need a response. Although any sector/zone on, while WeMOS is down, falls on deaf ears.  Stil, it needs to be logged and reported.

Advertisements

Small steps

Posted in Embedded, ESP8266, IOT, MQTT, node-red, NodeMCU, OpenSprinklette, WEMOS D1 R2 on August 7, 2017 by asteriondaedalus

I have roughed a node-red config node and it’s visible counterpart.  I decided to call wemos nodes “sectors” – since the usual rort is to call a single channel on an irrigation controller, controlling a single solenoid, a zone.

I have set up for 4 sectors each using a WeMOS D1R2 with a quad relay shield.  That provides up to 16 zones (4 per WeMOS).

You need to mod the relay shield with a couple of pullup resisters.  This is to get around a design shortfall on the WeMOD D1R2.

I am using a protoshield in between the WeMOS and the relay shield to allow for fidgeting with design changes. I added a four position dip to set the zone id BUT I dropped that in favour of the config node concept.

That gives me back 4 pins for GPIO. The problem is the out and out lie that the WeMOS is a Uno form factor. The ESP8266 has to cheat by using the same GPIO pins across a couple of Arduino socket pins.

I will add the rain gauge input later.

The idea is an input line such as the following as the title of the google calendar event:

sector1=1,sector3=4,sector2=0,sector3=1

The line above shows you some of the input features I will aim for, being:

  • You don’t need to nominate all four sectors or even all four individual zones of a sector.
  • You can order the sectors in any order.
  • The zones per sector are number 0..4 with 0 being the global all on/off id for all 4 zones on the addressed sector.

I did think about using JSON as input but the problem is that if you have two tokens the same then the object construction takes the later value in the line for the key.  Oh well.

For this to work you attach two google calendar event sniffers, one to flag the start of an event and one to flag the end.  Both feed into the opensprinklette-configurator to decode the events into MQTT calls to the 4 WeMOS D1 R2.

Of note, the configurator maps between chipid() and sector# (and back again) so planning the sprinkling can be in people-talk (relatively speaking).  At least you don’t have to remember which WeMOS chipid() was allocated to what sector.

Of course, there are quirks to do with the distributed system.  There will be a watchdog on the WeMOS to automatically turn off the water to a zone after 45min.  To plan out longer watering you will need back to back calendar events (shorter than 45min to avoid the watchdog).  If that is offensive please send money to help me pay the water bill of a runaway commercial setup ($3,000 in fact).

The other option I guess is send the duration to the WeMOS node and let it do the countdown.

I will play with a couple of timing approaches to see what is most robust – given you could have the ISP gateway drop out, the node-red crash, the emqttd crash, the OPiZ drop of the network.  Not to mention, google calendar hickups – I occasionally get a baulk around credentials lapsing that somehow comes good again.  Oh and of course, the WeMOS could also behave badly.

All in all needs a good bashing to help weed out nuisances.

Pump up the volume

Posted in C.H.I.P., Embedded, Linux on July 22, 2017 by asteriondaedalus

So Target had finally dropped prices of sound bars with aux input to AUS$49 so I can deal with the wife’s nagging about the BOSE wifi sound system with a $9 C.H.I.P. and a $49 sound bar.

Voila!

thomson

Perfect for the bedhead in the main bedroom and the window sill in the guest bedroom or in the book case in the wife’s study.

I only bought two as we had the speaker tower in the backroom.

Now, given all the problems I had with Armbian.com debian server distro and the OPiZ, here I am using nmcli to setup the static IP for the wifi on the C.H.I.P. with no problems.

Given I had the 3-pin serial cable out, I just swapped it over to the C.H.I.P. from the OPiZ.

I flashed with the headless server version 4.4 of for the C.H.I.P..

I used nmcli to setup the wifi using the provided example.

I then used “sudo nmtui” and setup the static ip and then reboot.

I found the device on my gateway list of wifi devices … bute!

To install shairpoint-sync I simply followed the instructions at Hackster.

The trick is where the instruction asks for interpolation to be set to soxr I reset it back to basic.  I also set the alsa property:

audio_backend_buffer_desired_length_in_seconds = 0.5 (it was set to 0.15).

I did this because the audio would drop out briefly.  Evidence is the soxr interpolation takes a grunting cpu and there might have been some network problems.  So, between relaxing the interpolation and buffering more audio, the dropping of audio apparently has ceased – much to Madam’s delight.

The nuisance, the wife has given up her iPhone for a Samsung S8 – which she doesn’t like.

I found you can get Airplay running on Android so we could get by.  I bought her a new laptop but she hasn’t moved her iTunes to that yet.

She hasn’t installed iTunes on the PC that I built her.  iTunes is on her old laptop so there are some politics there to get that transferred – especially as I have my eye on her old laptop to be my 64bit Debian dev box.

So while the Airplay route is “comfortable” it is rather “complicated”.

However, she has an iPad that she now hardly if ever uses so it can be the server for the house music.

Too easy drill sergeant!

Too easy, that is, because even though I am using a debian based distro on the C.H.I.P., and essentially using the same tools to set up the C.H.I.P. as I was the OPiZ, I am having no problems with C.H.I.P. headless server.

What?

Oh … yes, if she asks BOSE was bought out by Thompson.

 

 

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.

It occurred …

Posted in Embedded, Erlang, ODROID is wonderful, OpenSprinklette on December 5, 2016 by asteriondaedalus

… that after all the fluffing around with TTB on the inherited RaspingBreathBurryDOodlePi, I did rather prefer my mix I built originally on one of my ODROID-W.

Still, now I have got the additional ODROID-C1 it makes more sense for use as the house automation server.

The reason is that there is a UPS module that I can get from HardKernel that will help with survival requirements (given the blackouts we occasionally get in sleepy little Adelaide).

I do rather like the 7″ touch display you can get for the C1 as well.  Although, that isn’t strictly necessary since we will browse into the node-red running on it.

 

Erlang on C.H.I.P.

Posted in Embedded, Erlang on July 30, 2016 by asteriondaedalus

Well, with github and nerves-project.org down (for some dangblasted reason) I tried building Erlang on one of my C.H.I.P. from instructions here (for RaspbreathyPiklette).

CHIPerl

Sorta stuck after that as … github is down.  Git can’t find it, ping can’t browser can’t.  The site reports up and running but still can’t connect.

 

Connecting NodeMCU to a NTP server

Posted in Embedded, Lua, NodeMCU on July 4, 2016 by asteriondaedalus

Ignore the IP suggested in example.

Search google for “NTP server”.

Being Australian I am using one from the pool listed at:

http://www.pool.ntp.org/zone/au

Code therefore becomes:

sntp.sync("0.au.pool.ntp.org",

 function(sec,usec,server)
   print('setting time to:', sec, usec, "from: " .. server)
   rtctime.set(sec, usec)
   sec, usec = rtctime.get()
   print('time set to: ', sec, usec)
 end,

 function()
   print('failed!')
 end
)

The difference between times that you will see, when running this gem, is in and around 7 milliseconds which is the cost from function calls is all.

The idea would be to use a timer, set to max time and auto mode to run this occasionally to keep the time on the node synced with your local world.  That is:

tmr.register(6, 6870947, tmr.ALARM_AUTO, sntp.sync(...)) -- see above code

You might like to set a flag if the sync fails, or publish a mqtt alarm, or something more useful as the print will be lost on the world since we are deploying nodes in the real-world sans terminals.  Although consider loss of sync might also be loss of wifi access and so likely loss of communications with your mqtt server – so devilishly complicated this will all be.