2016. április 14., csütörtök

AutomaTales - ModuleMania

As I'm thinking further, it become obvious that I want to create a modular system. Something like a backplane, with equaly sized modules, the sensors, the actuators, the MCU, and the power source also reside on separate modules.

Even I went further. Designed a box, the backplane and the module form factor already. The modules will be implemented in 5x5cm form factor. Why? Because this can be cheaply ordered from the Chinese PCB factories - ~$10 for 10pcs.


The planed module connector has 1 SPI, 1 I2C and 8 GPIO connections. This is 17 pins together with the two power rails (3.3V and 5V). A 17 pin 0.1" single row header fits onto the 5cm edge of the board.

As I'm going further with it, I came up with quite a few modules, I want to implement. The list isn't complete, and the modules are subject to change:
  • Relay - Single channel relay module
  • RCR - Module for the rolling code receiver
  • Power sensor - Sensing if a mains voltage exists at a particular point
  • Temp/humidity - AM2302 based module (the sensor can be fitted internally or connected externally)
  • Esp01 - ESP-01 based "brain" module switchable between two GPIOs and an I2C
  • Esp07/12 + pcf8574 - ESP-07 or ESP-12 based module with an I2C extender
  • Esp12e/f - Questionable. Can be created if the internal flash SPI ports are shareable with external SPI devices easily - testing needed
  • Arduino + nrl24l01+ - MySensors.org sensor node "brain"
  • PSU - 5V/3.3V capable PSU based on HLK-PM01 and 3.3V LDO or buck converter
  • Nrl24l01+ - Nordic communication module - used primary for the Beaglebone to create MySensors.org gateway
  • Barometric pressure sensor
  • Bus Extender
  • Power Meter, Current transformer type
  • Power Meter, Hall sensor type
  • Power Meter, Utility meter pulse counter
  • Gas Utility meter Hall sensor
  • SSR Module
  • GPIO Module - Isolated I/O Module, a DC/DC converter may added
In addition I plan to design Backplane for 4, 6 and 8 modules. The backplane will have an additional connector, what is able to connect the whole thing to a BeagleBone CAPE. This means, I'll able to use this modular system for the BBG based OpenHAB central also.

I also adding parametric 3D printable enclosure for it.

Some of the modules already designed. Although it can be ordered from a fab, but all of the designs ready until today uses single sided board, what can be easily created at home with toner transfer. Most (not all) of the designs uses exclusively trough hole components, what make the life easier.

And this is how the enclosure and the module will fit. My first animation in OpenSCAD!


2016. április 12., kedd

AutomaTales - Mains Voltage Sensor

No, I don't want to measure the mains voltage (yet) here.
I want to build my garage lamp switch as minimally invasive to our current setup, as I can.
What does that mean?
The lamp today is switched by two wall switches (one inside the garage, one in the house at the garage door) in alternating configuration. I want to keep the possibility to operate the lamp with this switches. As I'm not an electrician, I not really want to touch the wires, switches inside the wall (it would be a dirty job anyways). Fortunately I've continuous mains source also at the lamp itself.
So the plan is to connect the remote switching unit to the uninterrupted source and sense if the switches are on or off. This signal will be used to alternate the lamp and not to determine the status. Every time it change (from on to off or off to on), will change the light state.
For the sensing I need some electronics. The mains is not a child play so the proper isolation is crucial.
I want to stick to the simplest circuit possible:
A capacitive non-isolated power supply (two caps, two resistors, a diode and a zener) plus an optoisolator. The whole thing cost around $1.
Here is the design:

2016. április 11., hétfő

AutomaTales - Connecting the Heating

As I mentioned earlier I've several Conrad (ELV) FHT80B thermostats, with radio controlled valves, and I've a CUL v3.2 device. Now I'm try to connect these devices to my OpenHAB.
Before I started to work on this project I updated the firmware in the CUL to the one suggested for OpenHAB from here:
http://culfw.de/culfw.html
The references for the connection can be find here:
https://github.com/openhab/openhab/wiki/FS20-Binding
https://github.com/openhab/openhab/wiki/CUL-Binding

Setting up the binding:
1. Copy the required addons into the /opt/openhab/addons folder:
org.openhab.io.transport.cul-1.8.1.jar
org.openhab.binding.fht-1.8.1.jar
If you have other devices than the heating from the FS20 family you may need the
org.openhab.binding.fs20-1.8.1.jar
also.

2. Edit the configuration file /opt/openhab/configurations/openhab.cfg. Add the following to the end:
fht:device=serial:/dev/ttyACM0
fht:baudrate=38400
fht:parity=0
fht:housecode=XXXX
The housecode is your choice. It is a four digit hexadecimal code. And it is absolutely necessary. If you don't provide it here, your system will not start without even a sign of the problem. You can just see the error message when you switch on the debug logging.
This code will be the code of your CUL device and has no connection with the codes of the FHT80b devices. In addition if you want to get readings from your devices, you have to be sure, that the "CEnt" setting in each of FHT80B devices is set to "nA".

3. You have to create some items in your items file for your FHT80B device. Something like this:
Number fhtRoom1Desired "Desired-Temp. [%.1f °C]" { fht="housecode=552D;datapoint=DESIRED_TEMP" }
Number fhtRoom1Measured "Measured Temp. [%.1f °C]" { fht="housecode=552D;datapoint=MEASURED_TEMP" }
Number fhtRoom1Valve "Valve [%.1f %%]" { fht="housecode=552D;address=00;datapoint=VALVE" }
Switch fhtRoom1Battery "Battery [%s]" { fht="housecode=552D;datapoint=BATTERY" }
Contact fhtRoom1Window "Window [MAP(en.map):%s]" { fht="housecode=52FB;address=7B;datapoint=WINDOW" }
The housecode in the example is the code of the FHT80B device itself. You can read it from the device, the code1 is the first part, the code2 is the second part, and you must convert your readings to hexadecimal.

4. Now you have to insert the read values into your sitemap:
Frame label="Heating"
{
 Setpoint item=fhtRoom1Desired minValue=6 maxValue=30 step=0.5 
 Text item=fhtRoom1Measured
 Text item=fhtRoom1Valve 
 Text item=fhtRoom1Battery
 Text item=fhtRoom1Window
}
The result is something like this:

Sorry for the Hungarian text, as this is a real data from my house, I'll translate the whole frontend to Hungarian to my family.

One thing to add: Be patient. Getting the data is a time consuming task. Some of the data will just arrive when changed. So it can take several minutes, or even hours, to get your data.

2016. április 10., vasárnap

Repair: HP 3478A

The metallized film capacitors are self-healing types as we know.
Yes, I see:

Mains line RIFA filter cap of the HP 3478A Multimeter

AutomaTales - Switching the Lamp (a LED)

Going further. This is just a copy-paste programming.
I grabbed the Arduino code from here:
http://iot-playground.com/blog/2-uncategorised/40-esp8266-wifi-relay-switch-arduino-ide

Changed the SSID and the password, connected a 150ohm resistor and the first LED I found in my junk box to the corresponding pins of the ESP8266. Downloaded the code, and fired the serial monitor in the Visual Studio:


When I connect to the web server from a browser, I can switch the LED on and off.

Now integrate it to the OpenHAB.
We don't need anything else just modify the previously created rules. First I just added the http calls into the previously created rule, but the result wasn't satisfactory. I was able to control the LED from the remote, but not from the web browser. So I modified it a bit more.

Here is the result:
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

rule "GarageLightRemote"
when
    Item KeeLoq_Remote_B changed from CLOSED to OPEN
then
    if(Garage_Light.state == ON)
    {
        sendCommand(Garage_Light, OFF)
    }
    else
    {
        sendCommand(Garage_Light, ON)
    }
end

rule "GarageLightOffAction"
when
    Item Garage_Light changed from ON to OFF
then
        sendHttpGetRequest("http://10.1.2.129/gpio/0")
end

rule "GarageLightOffAction"
when
    Item Garage_Light changed from OFF to ON
then
        sendHttpGetRequest("http://10.1.2.129/gpio/1") 
end
Here is the circuit:

2016. április 9., szombat

AutomaTales - ESP8266, Arduino, Visual Studio

I'm not a big fan of the whole Arduino ecosystem. The hateful IDE, and the lack of the debug-ability kept far from it.
On the other side I must admit that it is evolved since my first encounter, and it looks like something unavoidable.
I need some remote sensors, actuators, for my OpenHAB system. I want to build most of them. As I looked around, I seen two easily usable solution:
  • ESP8266 based WiFi modules
  • MySensors.org NRF24L01+ and Arduino based mesh network
I want to try both of them. As I not really have Arduinos on hand yet (actually I've few but different manufacturers, different hassles, and not really fits into this project), so I want to start to play with the ESP8266.
As I heard the LUA interpreter of it not really fits into bigger project, so I chosen the Arduino framework for it. Actually I'm just learning it, so I don't know where this lead to.
My first goal to be able to switch a GPIO of the ESP8266 via a HTTP REST API interface.
As I mentioned above I really hate the Arduino IDE. I run into various problems with it when I tried to configure and compile the Marlin firmware for my 3D printer. Then I found that you can use the trusted Microsoft Visual Studio (I'm using it for my daily work and a few contract projects) with this addon:
http://www.visualmicro.com/
for the task.
Putting together the environment:

1. Install an Arduino IDE. Can be downloaded from here: https://www.arduino.cc/download_handler.php?f=/arduino-1.6.8-windows.exe
2. Install the Microsoft Visual Studio 2015. I'm using the Professional version, but there is a free version, can be downloaded from here: https://go.microsoft.com/fwlink/?LinkId=615448&clcid=0x409
Make sure that you enable the C++ component

3. Start the Visual Studio. Go into the Tools/Extensions and Updates menu. Select the Online in the left pane. Search for Arduino
Download the Arduino IDE for Visual Studio

Install it, and restart Visual Studio as instructed.

4. After restart the Arduino configuration will appear. You should set the Arduino IDE location and add the ESP8266 Board Manager URL: http://arduino.esp8266.com/stable/package_esp8266com_index.json


Press OK

5. On the menu bar next to the Arduino board selector click on the magnifying glass icon
select the Manage Boards tab
Expand the esp8266 and click on the Version 2.1.0
On the popup dialog Click OK for the installation


And this is the point where I run into a great trouble. My machine is part of a domain, I'm running things as a regular user, means I've limited permissions (of course I'm admin on the other side, but I should specify it when I need it). It looks like the installer have a bug. Because I'm domain member and when I installed the machine at the beginning the user name I gave is the same I use in the domain. The result of this, that my profile name in the c:\Users folder is looks like this: <username>.<domainname>. This caused no problems in the past, but not here. The installer converted the dot between the name and the domain to underscore in some places and gave me an access denied error - yes because the folder in question didn't exists and I've no right to create it.

So I created the folder as admin and granted permission for me. After this the install run smoothly, but when I wanted to compile my first code, it failed. The error message wasn't too informative. After several trials, even using Process Monitor (Microsoft, formally Sysinternals tool), I was able to copy the files left in the temp folder under the underscore user folder I created, back into its place. Now it works, several hours wasted.

6. Try this out

I wanted to have a fast test, so I just created a demo project. The blink from the Visual Studio project list.


After selecting the correct board (NodeMCU v0.9 in my case) and the serial port, just uploaded the code and it started to work.

It looks like the ESP8266 environment is ready for more complicated tasks.

2016. április 6., szerda

AutomaTales - Remote integration

To be able to use the rolling code receiver in my OpenHAB, the first thing we need to enable the GPIO binding in the OpenHAB. There is a fairly good documentation of it in the OpenHAB wiki:

https://github.com/openhab/openhab/wiki/GPIO-Binding

I mostly done, what is in it, but some modifications were needed.

1. Install the native JNA library:
apt-get install libjna-java

2. Modify /opt/openhab/start.sh
Add
-Djna.boot.library.path=/usr/lib/jni
into the list of java command line parameters

3. Modifiy the /etc/init.d/openhab

Add
-Djna.boot.library.path=/usr/lib/jni
into the DAEMON_ARGS parameters

and add the commands to unexport the gpio pins on stopping the daemon



4. From the previously downloaded distribution-1.8.1-addons.zip (part of the OpenHAB downloads) expand the following files:
     org.openhab.io.gpio
     org.openhab.binding.gpio

into the /opt/openhab/addons directory

5. Restart openhab:

/etc/init.d/openhab restart

Now the OpenHAB is ready to handle the GPIO. We need to make the configuration changes, to be able to use it.

6. Add the required items

The GPIO inputs can be represented by Contacts in the OpenHAB, so edit one of the files in the /opt/openhab/configurations/items directory (I already dropped the demo config from here, so I've the config of my house) and add the following:

Contact KeeLoq_Remote_A "Reamote A [MAP(en.map:%s]" (<ID of your Group>, Windows) { gpio="pin:66"}
Contact KeeLoq_Remote_B "Reamote B [MAP(en.map:%s]" (<ID of your Group>, Windows) { gpio="pin:67"}
Contact KeeLoq_Remote_C "Reamote C [MAP(en.map:%s]" (<ID of your Group>, Windows) { gpio="pin:69"}
Contact KeeLoq_Remote_D "Reamote D [MAP(en.map:%s]" (<ID of your Group>, Windows) { gpio="pin:68"}


When everything is fine you should see the following after the OpenHAB reload the configuration:



And when you push a button on the remote, the closed text change to open, and back when you release.

7. For the lighting it will not be enough
We need to keep the status of the light, as it switched on or off. So I added a Switch into the items config:

Switch Garage_Light "Garage Light" (<ID of your Group>, Lights)

This is only a regular switch, so if you want to control it from the remote you need some rules. You can add it to a rules file in the /opt/openhab/configurations/rules folder:

rule "GarageLightToggle"
    when
        Item KeeLoq_Remote_B changed from CLOSED to OPEN
    then
        if(Garage_Light.state == ON)
        {
            sendCommand(Garage_Light, OFF)
        }
        else
        {
            sendCommand(Garage_Light, ON)
        }
end

After this, when you push the B button on the remote, it will switch the web control, on and off
This still not change the physical light. I have to create/buy some actor for this.