Thursday 21 February 2019

ADS-B twitter feed

see here - much easier - to use this installer - installs dump1090 etc, and lets you optionally install AboveTustin, which is a great twitter bot

https://github.com/jprochazka/adsb-receiver/wiki/Quick-Install

I had to update to Raspbian Stretch to get it to work. Due to conflicts with other python versions I had to specifically install some python libraries for Python3 version.


twitter pyPi:
sudo pip-3.2 install twitter

selenium:
sudo pip-3.2 install selenium













Friday 13 January 2017

Hive Home OpenHAB2

display hive home temperatures in OpenHAB2
I started on a crude PHP class to return Hive current temperature and setpoint to OpenHAB2

https://github.com/beinnlora/HiveHomeAPI-PHP

Make sure PHP>=5.6 is installed and working, along with CURL and SSL certificates

I had to configure php.ini to add the line:
curl.cainfo=/etc/ssl/certs/cacert.pem
then download the https://curl.haxx.se/ca/cacert.pem and save to above store.
If on windows, then replace with something like
curl.cainfo="C:\certs\cacert.pem
see stack exchange
http://stackoverflow.com/questions/6400300/https-and-ssl3-get-server-certificatecertificate-verify-failed-ca-is-ok

then in your /conf/script directory, store the script and class
git clone https://github.com/beinnlora/HiveHomeAPI-PHP.git
cd /opt/openhab2/conf/scripts
chown openhab:openhab HiveHomeAPI-PHP
cd HiveHomeAPI-PHP
chown openhab:openhab

then create a new php script for, e.g current temperature in your /conf/scripts/HiveHomeAPI-PHP directory,
nano currenttemp.php
<?php
/*example code - replace your credentials below with your hivehome details*/
include ("class.hivehome.php");
$hive = new HiveHome("hiveusername", "hivepw");
print $hive->getCurrentTemperature()."\n";
//print "Target Temp: ".$hive->getCurrentTemperature()."\n";
?>
set ownership and permissions
sudo chown openhab:openhab currenttemp.php
sudo chmod +x currenttemp.php

then create a new Item in your /conf/items

hive.items:
Number Temperature_Hive "Temperature [%.1f °C]" <temperature> (gHiveTemps1) [ "CurrentTemperature" ] {exec="<[php /opt/openhab2/conf/scripts/HiveHomeAPI-PHP/currenttemp.php:60000:REGEX((.*?))]"}

then add it to your sitemap.

Wednesday 2 November 2016

OpenHAB 2 MQTT Adafruit.io

Paper UI: Extensions-->bindings--> add MQTT Broker
Create/edit the file /opt/openhab2/conf/Services/mqtt.cfg

Sample mqtt.cfg

adafruit.url=tcp://io.adafruit.com:1883:1883
//client ID - unique string - anything
adafruit.clientId=48c70a89dbf3eff670d6db18bc804504

//username - your ADAFRUIT IO username
adafruit.user=myusername

//password is your AIO KEY
adafruit.pwd=1234567834567dfghjrtyuvb

//other items can be left alone

Sample ITEM definition, for a NUMBER feed from the Adafruit feed key "templogger1"

Number temperaturelog "temperature [%.1f]" {mqtt="<[adafruit:myusername/feeds/templogger1:state:default]"}

note that compared to the demo in the  documentation, there is no leading / on the topic. This caused me a big headache!

Sample SITEMAP

Text item=temperaturelog label="Adafruit temperature feed"


There is an issue with the system remembering old MQTT broker settings. You can clear out all previous MQTT settings via the openhab2 Karaf console:
Adjust your mqtt.conf as needed, then in the console
config:edit org.openhab.mqtt
config:property-list
config:delete

restart openhab2

Tuesday 1 November 2016

Lighwaverf OpenHAB 2 (And amazon echo dot)

Ubuntu 14.04LTS x64
Java 1.8.0_111
Openhab2 2.0.0b4 2.0.0 -SNAPSHOT build #560 offline manual install, as per http://docs.openhab.org/installation/linux.html#manual-installation
(therefore my openhab2 is installed under /opt/openhab2) - adjust where necessary. 1.x compatibility was already enabled in this release

1 - create file opt/openhab2/conf/Services/openhab.cfg and populate with the sample lighwaverf binding configuration as per
https://github.com/openhab/openhab/wiki/LightwaveRF-Binding
I left alone - the default IP using the broadcast address worked for me.

2 - copy the lighwaverf binding jar (version 1.9.0) from snapshot build (link below), into /opt/openhab2/addons/
https://openhab.ci.cloudbees.com/job/openHAB1-Addons/lastSuccessfulBuild/artifact/bundles/binding/org.openhab.binding.lightwaverf/target/
When I copied the .jar file over, my lightwave hub immediately started blinking saying "add app?", so I clicked YES.
The default settings for looking for the device on the broadcast IP 255.255.255.255 worked!
Depending on how you copied the file over (I used filezilla from my windows machine to the linux server) You might have to check permissions are set properly; I configured it as per manual install to run under user:group openhab, and changed owner of conf/services/openhab.cfg and addons/opt.xxxx.lighwavexxxx.jar to openhabuser&group

3 - create an Openhab "Item" in /opt/openhab2/conf/Items (I appended the demo.items file) - one line for each of your switches/dimmers etc - this is where you need to customise your individual device/switch/dimmer/mood. here's a sample switch in room 2, device 3: (sudo nano /opt/openhab2/conf/Items/demo.items)
Switch LWRF_light1 "bedside light" { lightwaverf="room=2,device=3,type=SWITCH" }

4 - create a switch in a Sitemap, so you can control it from the GUI:
Switch item=LWRF_light1 label="Bedside Light"

that's it - check the events.log or log:tail command


The above creates the OpenHAB lightwaverf switch

You also need to create a Hue Switch in OpenHAB that can be detected by the Amazon Echo
(the Amazon Echo OpenHAB bridge turns your OpenHAB into an emulated Philips Hue system, which Echo then detects/controls)
Then you can link the Lightwaverf switch to the Hue switch using a Rule (or probably some more elegant method)
updated guide below:
1) install OpenHAB2 somewhere on your home network
http://docs.openhab.org/installation/
From the PaperUI interface to openHAB2
2) Install Amazon Echo Bridge (Philips Hue emulation)
Extensions–>Misc–>Hue Emulation
(further reading) http://docs.openhab.org/addons/io/hueemulation/readme.html
3) Install Lighwaverf binding 1.9.0 (not fantastically userfriendly at the moment in openHAB2) see
https://community.openhab.org/t/lightwaverf-openhab2/13717/5
4) Create an Item in OpenHAB conf/items, that will control the Lightwaverf switch
Switch LWRF_light1 “bedside light” { lightwaverf=”room=2,device=3,type=SWITCH” }
5) Create an emulated HUE Item in OpenHAB, that Echo can control – see https://github.com/openhab/openhab2-addons/tree/master/addons/io/org.openhab.io.hueemulation. e.g.
Switch HUE_LWRF_light1 “bedside light Echo” [ "Switchable" ]
6) create a rule in /opt/openhab2/conf/rules (e.g. demo.rules), to update your lightwaverf switch state when you update the Echo/hue switch
**there will probably be a more elegant way of doing this, using bindings or something **
// ECHO TO LIGHTWAVE – when Amazon Echo switch is updated, also update the lightwaverf switch
rule “LWRF bedside light”
when
Item HUE_LWRF_light1 received command
then
println (“command”)
sendCommand(LWRF_light1, receivedCommand)
end
7) Turn on Pairing in OpenHAB (Configuration–>Services–Hue Emulation–>Start
8) Ask alexa “Alexa, discover devices”. It will then discover the new HUE switch, that you control using the description you gave to the item (e.g. “Bedsite light”)
9) Create a switch in your openhab Sitemap, if you also want to control via your openHAB gui. Create it for the HUE switch rather than the LWRF switch and it will mirror the commands sent via Echo.
Switch item=HUE_LWRF_light1 label=”Bedside Light”

Monday 31 October 2016

find my iphone using amazon dash button openhab

Using Amazon Dash Button and OpenHab2 to find my iphone

2.0.0-SNAPSHOP build #560
instructions as per
https://github.com/openhab/openhab2-addons/tree/master/addons/binding/org.openhab.binding.amazondashbutton

follow install pcap4j, including permissions for running as non-root:

then for the java path I did
whereis java
then ls -l /usr/bin/java
ls -l /etc/alternatives/java
then

setcap cap_net_raw,cap_net_admin=eip /usr/lib/jvm/java-8-oracle/jre/bin/java

started openHAB script
sudo su -s /bin/bash -c '/opt/openhab2/start.sh' openhab

let it run 15 mins - check GUI ok, then restarted it

on my router, I noted down all current DHCP leases, then followed the dash button setup until the point of choosing button, then stopped, then looked for new DHCP lease and found the MAC address AC-63-BE-XX-XX-XX, gave it a fixed IP assignment then blocked it in the router firewall for WAN access.

enable amazon dash binding in Paper UI - click install

when happy, press the button and the Dash button appears as a Thing in inbox!
click the tick in the Inbox to add the dash button as a Thing.
make a note of the CHANNEL that the dashbutton publishes its events to, something like
amazondashbutton:dashbutton:ac-63-be-xx-xx-xx:press

Now you can just add a rule in /opt/openhab2/conf/rules
e.g.
sudo nano dashbuttons.rules

rule "Dash button pressed" when Channel "amazondashbutton:dashbutton:ac-63-be-xx-xx-xx:press" triggered then
println("The Dash button has been pressed") end


change owner to openhab as per the install guide,

sudo chown openhab:openhab dashbuttons.rules

What got me was that the usual approach of Thing < -- bind with channel --> Item isn't followed. The dash button is a pure Thing with channel trigger - no Item to bind to - no Item State/Command to run in a rule

Discussion here:
https://community.openhab.org/t/amazon-dash-button-as-openhab-trigger/3622/52


Now, get the PHP 'find my iphone' library
as per
http://blog.qnology.com/2015/11/voice-control-home-automation-via.html
(adapted for OH2)
cd /opt/openhab2/conf/scripts
sudo git clone git://github.com/albeebe/PHP-FindMyiPhone
sudo cp PHP-FindMyiPhone/class.findmyiphone.php .
UPDATE Jan 2017 - ensure you use version of pull request 12th Jan 2017 or later as API has changed.

You may also need to install/configure PHP for SSL certificates

edit php.ini and add/uncomment line

curl.cainfo=/etc/ssl/certs/cacert.pem
then download the https://curl.haxx.se/ca/cacert.pem and save to above store.
If on windows, then replace with something like
curl.cainfo="C:\certs\cacert.pem"

http://stackoverflow.com/questions/6400300/https-and-ssl3-get-server-certificatecertificate-verify-failed-ca-is-ok



sudo wget --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/custom_scripts/listiclouddevices.php
sudo wget --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/custom_scripts/turnoniphone.php
sudo wget --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/custom_scripts/turnoffiphone.php

#FIND MY IPHONE SETUP
#CONFIGURE SAMPLE SCRIPTS
#Edit listiclouddevices.php with your iCloud username (email) and password

cd /opt/openhab2/c
onf/scripts
sudo nano listiclouddevices.php


#Run it to find your deviceID
#DeviceID will be something like Eu4EGWK1Yt5+2JtKM7YNA++hxNtDw4ZzZuwT9BLxYcL2d7FaULCJMuHYVNSUzmXV<
php ./listiclouddevices.php

#Edit turnoniphone.php, turnoffiphone.php
#with username, password and deviceID
sudo nano turnoniphone.php
sudo nano turnoffiphone.php

#Run scripts to test
php ./turnoniphone.php
php ./turnoffiphone.php

Permissions are a sticky point.
After creating php scripts, I changed all files in openhab2 to be owner:openhab, group openhab
for the manual install, this is
sudo chown -hR openhab:openhab /opt/openhab2

I also added my linux user to the group openhab, for ease of editing:
sudo usermod -a -G openhab myusername

Sunday 30 October 2016

Openhab2 beginner's guide

my own hints for starting from scratch with openhab2 - not a step-by-step guide!

openhab2 installation location  (ubuntu 14.04)

depends on whether you manually install or install from repo:

http://docs.openhab.org/installation/linux.html#file-locations

openhab 1 bindings in openhab2?

http://docs.openhab.org/developers/development/compatibilitylayer.html#how-to-use-openhab-1x-add-ons-that-are-not-part-of-the-distribution
in 2.0.0.B4+ (and probably earlier) the 1.x compatibility binding is already enabled.
Copy your 1.x .jar file into /opt/openhab2/addons.
Create/edit /opt/openhab2/conf/Services/openhab.cfg and add your 1.x binding configuration there
check the Karaf log or openhab.log for any issues.

lightwaverf binding openhab2

SEE DEDICATED POST LATER IN BLOG - requires nightly build 1.9.0 of addon.

get openhab1 lightwaverf binding from github
https://bintray.com/artifact/download/openhab/bin/distribution-1.8.3-addons.zip
unzip
copy the openhab binding lightwaverf into /usr/share/openhab2/addons
I did this via filezilla local sftp to my linux box, having first done:
#add my username to the openhab group  (replace myusername as needed)
sudo usermod -a -G openhab myusername
# give the openhab group permissins to the addons folder
sudo chmod g+rws usr/share/openhab2/addons

then I can unzip on windows the 1.8.3 distribution-addons.zip - move the lightwaverf jar across to usr/share/openhab2/addons

at this point, my lightwaverf hub asked immediately to authorise the app - I did nothing else - no config yet!

in /etc/openhab2/services, create file openhab.cfg
copy the supplied lightwaverf config into it, i.e. from
https://github.com/openhab/openhab/wiki/LightwaveRF-Binding

now I'm stuck - not available in bindings in Paper UI - error in log about lightwaverf missing addBinding method...

openhab2 console

- for checking the 1.x compatibility layer is installed - it was by defulat

http://docs.openhab.org/administration/console.html

More up-to-date openhab1 binding for lightwaverf available from openhab nightly build:

https://openhab.ci.cloudbees.com/job/openHAB1-Addons/lastSuccessfulBuild/artifact/bundles/binding/


Monday 5 September 2016

Multiple LoRa clients on one frequency - how to synchronise multiple LoRa transmitters using GPS

Implementing a time division multiple access scheme for single channel non-LoRaWAN access network, we need to synchronise each transmitter's TX window in order to maximise channel capacity.

We start by working out the TX window length (based on payload, LoRa parameters, receiver gain recovery rate etc). 12 bytes of data allows us lat/long to ~10m precision. vBat to 8 bit resolution plus plus other bytes for general purpose flags.

We then use the Semtech LoRa calculator program to determine a tradeoff between on-air time and SNR margin .
* We want maximum SNR to get the best range.
* We want to minimise on-air time as our trackers are moving, and we want to squeeze as many trackers onto one radio channel as possible.
* We want to minimise bandwidth if possible, are our trackers will have greatly varying temperatures and supply voltages/currents so frequency stability might not be great.
* we want our receiver to be able to recover its AGC circuitry and have sufficient processing power/message buffering queue to be able to pick out successive transmissions (if too closely spaced and densely transmitted, the limiting factor might be our receiver, not our transmitters)

We then decide how often we want to receive position updates - a tradeoff in refresh rate and remote battery life.

We then work out how tight a timing/synchronising loop we can achieve using the available hardware (48MHz onboard clock, GPS PPS synchronisation driving hardware interrupts

We can then design our TDMA scheme around these parameters.

For me, 30 second position updates is more than adequate. I would want to fit around 100 devices on one radio channel.
Rounding numbers up gives us 120 devices transmitting once every 30 seconds, or one transmission every 250 milliseconds.