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.






Monday, 22 August 2016

traccar-web with custom offline maps

(incomplete)
traccar-web interface to traccar.org
* allows URL sign-on and better mobile interface

https://github.com/vitalidze/traccar-web/

quick and dirty method - replace opensteetmap tile url with local tilestache server tiles

get file-roller (archive manager):

sudo apt-get install gnome-common
sudo apt-get install yelp

git clone 
https://wiki.gnome.org/Apps/FileRoller
./auto


install traccar.org and traccar-web as per their respective installers - confirm working.


On linux system you can open /opt/traccar/traccar-web.war with archive manager, edit files then re-pack quite easily. https://wiki.gnome.org/Apps/FileRoller (installed default in ubuntu 12.0.4 

We are concentrating on the mobile interface
traccar-web.war/m/index.html:
change any references to CDN cloudflare css or js libraries to point to "js/{name of js" or "css/{name..." as required.
then download and add the css or js file to the traccar-web.war/js/ or /css within the archive and re-pack the grml file

...



Thursday, 11 August 2016

raspberry pi lora hoperf python code

clone
https://github.com/mayeranalytics/pySX127x
sudo apt-get install python-dev

wget https://pypi.python.org/packages/source/s/spidev/spidev-3.1.tar.gz
tar xfvz  spidev-3.1.tar.gz
cd spidev-3.1
sudo python setup.py install
sudo pip install Adafruit
sudo pip install httplib2

edit files to account for Uputronics Hoperf board#############
pySX127x/SX127x/board_config.py:
line 33 onwards
change pins for the HAB pi board on CE1:
class BOARD:
  # Note that the BCOM numbering for the GPIOs is used.   
    DIO0 = 16   # RaspPi GPIO 16 = wpi 27 = phys 36 (input)#dio0 on habboard
  #  DIO1 = 12   # RaspPi GPIO 12 = wpi 26 = phys 16 (input)DIO5 on habboard
   # DIO2 = 24   # RaspPi GPIO 24 = wpi 5 = phys 18 (input)#notused
   # DIO3 = 25   # RaspPi GPIO 25 = wpi 6 = phys 22 (input)#notused
    LED  = 13   # RaspPi GPIO 23 = wpi 1 = phys 33 ( make output on ‘internet’ LED)
#################
line 74, in def SpiDev(): and change to
BOARD.spi.open (0,1) #for HOPE module at bus CE1
###################
pySX127x/SX127x/LoRaArgumentParser.py
line 41 onwards
change the default= items in the __init__ self section to the required frequency, spreading factor,bandwidth etc that you are using. Setting them here for 433MHz board means constructing a LoRa object without all the parameters will at least work without defaulting to 868mhz. I have mine set at 434.4mhz
#####################
pySX127x/SX127x/LoRa.py
Line 84 change calibration freq to 433mhz
Line 815 change freq to 433mhz
This just allows the self-test facility to work at 433mhz without supplying further parameters
remove any initialisations for DIO2 onwards
################
you can now run pySX127x/test_lora.py, to see if it works. Do a ‘gpio readall’( part of wiringpi) beforehand, which seems to un-stick it – I guess some wiring pi is not being initialised completely….
#################
I have a blind receiver running continuously, so I just modify the file pySX127x/rx_cont.py:
Line 44: in function
   def on_rx_done(self):
this is where I add my code – and is triggered on each
successful packet reception:IO

installing tilestache on raspberry pi 3

from clean raspbian jessie install
open terminal
sudo pip install tilestache

you may get a warning  re compilation terminated, but read it carefully - this is just for C extension speedups which are not compulsory

make directory to serve tiles from and store tilestache

mkdir /home/pi/src/tilestache
create config file as shown in previous posts
sudo nano tilestache.cfg

change hostname of pi:
start tilestache: (assuming your pi is set for hostname pitracker.local)
tilestache-server.py -c /home/pi/src/tilestache/tilestache.cfg -i pitracker.local -p 8080

Installing traccar.org on raspberry pi 3

from fresh raspbian distribution image
in a terminal

1. expand filesystem and refresh raspbian
raspi-config
follow instructions to expand filesystem to fill SD card
sudo apt-get update
sudo apt-get upgrade
1.a optional - I operate via RDP gui: sudo apt-get install xrdp

2. download traccar.org Linux ARM
currently this version:
https://github.com/tananaev/traccar/releases/download/v3.6/traccar-linux-arm-3.6.zip
extract to e.g. /home/pi/downloads
sudo /home/pi/Downloads/traccar.run

sudo /opt/traccar/bin/traccar start