From 7464903e66abc53c1305e478cc40e41c0268fe02 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Thu, 28 Sep 2017 17:42:16 +0200 Subject: [PATCH] bugfix -> register ETREE file before deploying (else we have no etree to dispatch) --- feature/portail-emitter/connect | 17 ++++++ feature/portail-receiver/install | 6 +++ feature/portail-receiver/test.py | 9 ++++ lib/api/source/deploy.php | 91 +++++++++++++++++--------------- lib/api/source/fetch.php | 2 + 5 files changed, 81 insertions(+), 44 deletions(-) create mode 100644 feature/portail-emitter/connect create mode 100644 feature/portail-receiver/install create mode 100644 feature/portail-receiver/test.py diff --git a/feature/portail-emitter/connect b/feature/portail-emitter/connect new file mode 100644 index 0000000..9602225 --- /dev/null +++ b/feature/portail-emitter/connect @@ -0,0 +1,17 @@ +#!/bin/bash + +# (1) Get iface name # +iface="`hciconfig | awk '{print $1'} | grep -P ':$' | sed 's/://' | head -n 1`"; + +# (2) Enable secure pairing # +sudo hciconfig $iface sspmode 1; +sudo hciconfig $Iface piscan; + +# (3) Find device mac addr # +macaddr="`hcitool scan | grep -vP '^Scan'`"; + +# If nothing found -> exit + +# (4) Pair with device # +# newiface target channel +sudo rfcomm bind /dev/rfcomm1 $macaddr 1; diff --git a/feature/portail-receiver/install b/feature/portail-receiver/install new file mode 100644 index 0000000..29885b1 --- /dev/null +++ b/feature/portail-receiver/install @@ -0,0 +1,6 @@ +apt-get install libbluetooth-dev +pip install pybluez + + +# v2 +apt-get install bluetooth bluez python-serial diff --git a/feature/portail-receiver/test.py b/feature/portail-receiver/test.py new file mode 100644 index 0000000..9c24fb2 --- /dev/null +++ b/feature/portail-receiver/test.py @@ -0,0 +1,9 @@ +from bluetooth import *; + + +sock = BluetoothSocket( RFCOMM ); +sock.bind( ('', PORT_ANY) ); +sock.listen(1); + + +port = sock.getsockname()[1]; diff --git a/lib/api/source/deploy.php b/lib/api/source/deploy.php index 1c70a49..383c925 100755 --- a/lib/api/source/deploy.php +++ b/lib/api/source/deploy.php @@ -25,8 +25,29 @@ } + /* [2] Get etrees list + =========================================================*/ + /* (1) Check data */ + if( !isset($arr_r['etrees']) || !is_array($arr_r['etrees']) ){ + slog('No \'etree\' found in response file', "api:deploy", 'update'); + return 127; + } - /* [2] Get the list of daemons (features) + /* (2) Reset file */ + file_put_contents(ETREE_CONF, ''); + + /* (3) Replace content */ + $f = new SplFileObject(ETREE_CONF, 'w'); + + foreach($arr_r['etrees'] as $etree) + $f->fwrite( $etree.PHP_EOL ); + + $f = null; + + + + + /* [3] Get the list of daemons (features) =========================================================*/ $feature = []; $f = new SplFileObject(ETREE_CONF, 'r'); @@ -44,53 +65,11 @@ $feature[] = $etree; } - - - - /* [3] Launch deploy script for each feature - =========================================================*/ - /* (1) For each feature */ - foreach($feature as $feat_name){ - - /* (2) Check if specific data in response */ - if( !isset($arr_r['feature'][$feat_name]) ) - continue; - - /* (3) Check for feature deploy script */ - if( !file_exists(SOURCE_DIR."/feature/$feat_name/deploy") ) - continue; - - /* (4) Write useful exclusive data to tmp file */ - file_put_contents(TMP_DIR."/$feat_name", json_encode($arr_r['feature'][$feat_name])); - - /* (4) Execute deploy script */ - $sync_suffix = $sync ? ' sync' : ''; - syscall(SOURCE_DIR."/feature/$feat_name/deploy$sync"); - - } - - /* [4] Get etrees list - =========================================================*/ - /* (1) Check data */ - if( !isset($arr_r['etrees']) || !is_array($arr_r['etrees']) ){ - slog('No \'etree\' found in response file', "$FEATURE:deploy", 'update'); - return 127; - } - - /* (2) Reset file */ - file_put_contents(ETREE_CONF, ''); - - /* (3) Replace content */ - $f = new SplFileObject(ETREE_CONF, 'w'); - - foreach($arr_r['etrees'] as $etree) - $f->fwrite( $etree.PHP_EOL ); - $f = null; - /* [5] Remove features' entries + /* [4] Remove features' entries =========================================================*/ /* (0) We are done if @sync */ if( $sync ){ @@ -129,6 +108,30 @@ } + + /* [5] Launch deploy script for each feature + =========================================================*/ + /* (1) For each feature */ + foreach($feature as $feat_name){ + + /* (2) Check if specific data in response */ + if( !isset($arr_r['feature'][$feat_name]) ) + continue; + + /* (3) Check for feature deploy script */ + if( !file_exists(SOURCE_DIR."/feature/$feat_name/deploy") ) + continue; + + /* (4) Write useful exclusive data to tmp file */ + file_put_contents(TMP_DIR."/$feat_name", json_encode($arr_r['feature'][$feat_name])); + + /* (4) Execute deploy script */ + $sync_suffix = $sync ? ' sync' : ''; + syscall(SOURCE_DIR."/feature/$feat_name/deploy$sync"); + + } + + return 0; } diff --git a/lib/api/source/fetch.php b/lib/api/source/fetch.php index 71269c2..0ee2baa 100755 --- a/lib/api/source/fetch.php +++ b/lib/api/source/fetch.php @@ -24,6 +24,8 @@ } + $f = null; + /* [2] Fetch & generate useful data from features