├── .gitignore ├── .gitmodules ├── LICENSE ├── build ├── debian │ ├── .gitignore │ ├── devicehive-cloud.create │ ├── devicehive-cloud.template │ │ └── DEBIAN │ │ │ └── control │ ├── framework.create │ ├── framework.template │ │ ├── DEBIAN │ │ │ └── control │ │ └── etc │ │ │ ├── dbus-1 │ │ │ └── system.d │ │ │ │ ├── com.devicehive.alljoyn.conf │ │ │ │ ├── com.devicehive.ble.conf │ │ │ │ └── com.devicehive.cloud.conf │ │ │ └── init.d │ │ │ ├── alljoyn-daemon │ │ │ ├── devicehive-alljoyn │ │ │ ├── devicehive-ble │ │ │ └── devicehive-cloud │ └── readme.md └── snappy │ ├── build-alljoyn.sh │ ├── build-apps.sh │ ├── build-framework.sh │ ├── canonical-heart-pulse-demo │ ├── bin │ │ └── service │ ├── build.sh │ └── meta │ │ ├── devicehive.apparmor │ │ ├── heart.png │ │ ├── hooks │ │ └── config │ │ ├── package.yaml │ │ └── readme.md │ ├── devicehive-alljoyn-tools │ ├── alljoyn-armhf.patch │ ├── armhf │ │ └── libcap.so │ └── build.sh │ ├── devicehive-alljoyn │ ├── bin │ │ ├── alljoyn-daemon │ │ └── devicehive-alljoyn │ └── meta │ │ ├── alljoyn-daemon.apparmor │ │ ├── devicehive-alljoyn.apparmor │ │ ├── dh.png │ │ ├── framework-policy │ │ └── apparmor │ │ │ └── policygroups │ │ │ └── client │ │ ├── hooks │ │ └── config │ │ ├── package.yaml │ │ └── readme.md │ ├── devicehive-framework │ ├── bin │ │ ├── ble-service │ │ ├── cloud-service │ │ ├── enocean-service │ │ └── gpio-service │ ├── build.sh │ ├── config.yaml │ └── meta │ │ ├── ble.apparmor │ │ ├── cloud.apparmor │ │ ├── dh.png │ │ ├── enocean.apparmor │ │ ├── framework-policy │ │ └── apparmor │ │ │ └── policygroups │ │ │ └── client │ │ ├── gpio.apparmor │ │ ├── hooks │ │ └── config │ │ ├── package.yaml │ │ └── readme.md │ ├── devicehive-iot-demo │ ├── bin │ │ └── service │ ├── build.sh │ └── meta │ │ ├── devicehive.apparmor │ │ ├── dh.png │ │ ├── package.yaml │ │ └── readme.md │ ├── readme.md │ ├── sensortag-cloud-demo │ ├── build.sh │ └── meta │ │ ├── devicehive.apparmor │ │ ├── dh.png │ │ ├── package.yaml │ │ └── readme.md │ ├── snappy-clean.sh │ └── sysmon │ ├── bin │ └── service │ ├── build.sh │ └── meta │ ├── devicehive.apparmor │ ├── dh.png │ ├── package.yaml │ └── readme.md ├── devicehive-alljoyn ├── ajmarshal │ ├── decoder.go │ └── encoder.go ├── alljoyn-bridge.png ├── alljoyn-device-example │ └── alljoyn-device-example.go ├── basic-service │ └── basic-service.go ├── cfuncs.c ├── cfuncs.h ├── conf │ ├── args.go │ └── conf.go ├── devicehive-alljoyn.go ├── lib │ ├── hashmap.c │ └── hashmap.h ├── readme.md └── tests │ ├── alljoyn-bridge_test.go │ └── alljoyn-simple-device.go ├── devicehive-ble ├── devicehive-ble.go └── readme.md ├── devicehive-bridge ├── .gitignore ├── devicehive-bridge.js └── package.json ├── devicehive-cloud ├── conf │ ├── args.go │ └── conf.go ├── device-cloud-mock │ └── devicehive-cloud-mock.go ├── devicehive-cloud.go ├── devicehive-test-priority │ ├── README.md │ ├── devicehive-high-send │ │ └── devicehive-high-send.go │ └── devicehive-low-sender-loop │ │ └── devicehive-low-sender-loop.go ├── exampleconf.yml ├── main-loop.go ├── pqueue │ ├── consts.go │ ├── heap.go │ ├── pqueue.go │ └── sorting.go └── readme.md ├── devicehive-enocean ├── enocean-daemon └── readme.md ├── devicehive-gpio ├── DBUS-SPEC.md ├── README.md ├── gpio-daemon └── profiles │ ├── Raspberry Pi 2 Model B.yaml │ └── TI AM335x BeagleBone Black.yaml ├── examples ├── alljoyn │ ├── common │ │ ├── controlpanel.py │ │ ├── core.py │ │ ├── lighting.py │ │ └── notification.py │ ├── controlpanel │ │ └── smartplug.py │ ├── eventaction │ │ └── enocean-ble.py │ ├── hello.py │ ├── hello2.py │ ├── lighting │ │ ├── real-light.py │ │ └── terminal-light.py │ ├── notifications │ │ └── clock.py │ └── readme.md ├── cloud-ble │ ├── cloud-ble.go │ ├── queue.go │ ├── readme.md │ └── wrapper.go ├── cpu-stats │ └── cpu-stats.go ├── dash-xylo.go ├── echo.py ├── enocean │ ├── README.md │ └── enocean-dbus-ble.py ├── gpio │ ├── adc.py │ ├── gpio-blink-python │ ├── gpio-click-python │ ├── gpio-switch-python │ ├── gpio-switch-python-profiles │ │ ├── Raspberry Pi 2 Model B.yaml │ │ └── TI AM335x BeagleBone.yaml │ └── readme.md ├── heart-pulse-demo.go ├── iot-demo.go ├── lamp.py ├── pod.py ├── readme.md ├── scales.py ├── sensortag-cloud.py └── sensortag.py ├── framework.png ├── godbus-helpers ├── ble │ └── ble.go ├── cloud │ └── cloud.go └── dbushelper │ └── dbushelper.go └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | build/**/bin/armhf 10 | build/**/bin/x86_64 11 | *.snap 12 | 13 | # Architecture specific extensions/prefixes 14 | *.[568vq] 15 | [568vq].out 16 | 17 | *.cgo1.go 18 | *.cgo2.c 19 | _cgo_defun.c 20 | _cgo_gotypes.go 21 | _cgo_export.* 22 | 23 | _testmain.go 24 | 25 | *.exe 26 | *.test 27 | *.prof 28 | *.nvram 29 | 30 | *.*~ 31 | devicehive-cloud/astaff.conf 32 | 33 | devicehive-alljoyn/libajtcl.so 34 | 35 | *.DS_Store 36 | 37 | __pycache__ 38 | *.pyc -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "devicehive-alljoyn/alljoyn"] 2 | path = devicehive-alljoyn/alljoyn 3 | url = git@github.com:devicehive/alljoyn.git 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 DeviceHive 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /build/debian/.gitignore: -------------------------------------------------------------------------------- 1 | *.deb 2 | -------------------------------------------------------------------------------- /build/debian/devicehive-cloud.create: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # For manual modification 4 | TEMPLATE=devicehive-cloud.template 5 | export VERSION=0.1 6 | 7 | 8 | function render_template() { 9 | envsubst < $1 > $1.new 10 | rm $1 11 | mv $1.new $1 12 | } 13 | 14 | # Automatic update packages 15 | pushd ../../devicehive-cloud 16 | go get -u github.com/godbus/dbus 17 | go get -u github.com/gorilla/websocket 18 | popd 19 | 20 | # Automatic calculate revision 21 | export GITHASH=$(git rev-parse HEAD) 22 | 23 | 24 | # Automatic amd64 25 | DEBNAME="devicehive-cloud_${VERSION}-${GITHASH}_amd64" 26 | [ -d "$DEBNAME" ] && rm -rf "$DEBNAME" 27 | cp -rv "$TEMPLATE" "$DEBNAME" 28 | GOOS=linux GOARCH=amd64 go build -o "$DEBNAME/usr/bin/devicehive-cloud" ../../devicehive-cloud/*.go 29 | ARCHITECTURE=amd64 render_template "$DEBNAME/DEBIAN/control" 30 | dpkg-deb --build $DEBNAME && rm -rf $DEBNAME 31 | 32 | 33 | # Automatic armv7 34 | DEBNAME="devicehive-cloud_${VERSION}-${GITHASH}_arm" 35 | [ -d "$DEBNAME" ] && rm -rf "$DEBNAME" 36 | cp -rv "$TEMPLATE" "$DEBNAME" 37 | GOOS=linux GOARCH=arm GOARM=7 go build -o "$DEBNAME/usr/bin/devicehive-cloud" ../../devicehive-cloud/*.go 38 | ARCHITECTURE=arm render_template "$DEBNAME/DEBIAN/control" 39 | dpkg-deb --build $DEBNAME && rm -rf $DEBNAME 40 | -------------------------------------------------------------------------------- /build/debian/devicehive-cloud.template/DEBIAN/control: -------------------------------------------------------------------------------- 1 | Package: devicehive-cloud 2 | Version: ${VERSION}-${GITHASH} 3 | Section: base 4 | Priority: optional 5 | Architecture: ${ARCHITECTURE} 6 | Maintainer: Anton Rudnev 7 | Description: DeviceHive Gateway 8 | Gateway for DeviceHive 9 | -------------------------------------------------------------------------------- /build/debian/framework.create: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # For manual modification 4 | TEMPLATE=framework.template 5 | export VERSION=0.1.0 6 | 7 | DIR="$(dirname "$(readlink -f "$0")")" 8 | ROOT=$DIR/../.. 9 | variant=${VARIANT:-release} 10 | 11 | function render_template() { 12 | envsubst < $1 > $1.new 13 | rm $1 14 | mv $1.new $1 15 | } 16 | 17 | # Automatic update packages 18 | pushd $ROOT/devicehive-cloud 19 | go get -u github.com/godbus/dbus 20 | go get -u github.com/gorilla/websocket 21 | popd 22 | 23 | # Automatic calculate revision 24 | export GITHASH=$(git rev-parse HEAD) 25 | 26 | # TODO: add GITHASH to VERSION? 27 | 28 | # Automatic amd64 29 | DEBNAME="$DIR/devicehive-IoT_${VERSION}_amd64" 30 | [ -d "$DEBNAME" ] && rm -rf "$DEBNAME" 31 | cp -rv "$TEMPLATE" "$DEBNAME" 32 | GOOS=linux GOARCH=amd64 go build -o "$DEBNAME/usr/bin/devicehive-cloud" $ROOT/devicehive-cloud/*.go 33 | GOOS=linux GOARCH=amd64 go build -o "$DEBNAME/usr/bin/devicehive-ble" $ROOT/devicehive-ble/*.go 34 | pushd $ROOT/devicehive-alljoyn/alljoyn && PLATFORM=x86_64 ./build-thin-linux-core && popd 35 | cp -fv $ROOT/devicehive-alljoyn/alljoyn/core/alljoyn/build/linux/x86_64/$variant/dist/cpp/bin/alljoyn-daemon "$DEBNAME/usr/bin/" 36 | cp -fv $ROOT/devicehive-alljoyn/alljoyn/core/alljoyn/build/linux/x86_64/$variant/dist/cpp/lib/liballjoyn.so "$DEBNAME/usr/lib/" 37 | cp -fv $ROOT/devicehive-alljoyn/alljoyn/core/ajtcl/libajtcl.so "$DEBNAME/usr/lib/" 38 | # TODO: do we need update LD_LIBRARY_PATH? 39 | pushd $ROOT/devicehive-alljoyn && GOOS=linux GOARCH=amd64 go build -o "$DEBNAME/usr/bin/devicehive-alljoyn" && popd 40 | ARCHITECTURE=amd64 render_template "$DEBNAME/DEBIAN/control" 41 | dpkg-deb --build $DEBNAME && rm -rf "$DEBNAME" 42 | 43 | # Automatic armv7 44 | DEBNAME="$DIR/devicehive-IoT_${VERSION}_arm" 45 | [ -d "$DEBNAME" ] && rm -rf "$DEBNAME" 46 | cp -rv "$TEMPLATE" "$DEBNAME" 47 | GOOS=linux GOARCH=arm GOARM=7 go build -o "$DEBNAME/usr/bin/devicehive-cloud" $ROOT/devicehive-cloud/*.go 48 | GOOS=linux GOARCH=arm GOARM=7 go build -o "$DEBNAME/usr/bin/devicehive-ble" $ROOT/devicehive-ble/*.go 49 | [ -d $ROOT/devicehive-alljoyn/alljoyn/core/alljoyn/build_core/conf/linux/armhf ] || patch -d $ROOT/devicehive-alljoyn/alljoyn/core/alljoyn -p1 -i $ROOT/build/snappy/devicehive-alljoyn-tools/alljoyn-armhf.patch 50 | [ -e /usr/arm-linux-gnueabihf/lib/libcap.so ] || sudo ln -s $ROOT/build/snappy/devicehive-alljoyn-tools/armhf/libcap.so /usr/arm-linux-gnueabihf/lib/libcap.so 51 | pushd $ROOT/devicehive-alljoyn/alljoyn && PLATFORM=armhf ./build-thin-linux-core && popd 52 | cp -fv $ROOT/devicehive-alljoyn/alljoyn/core/alljoyn/build/linux/armhf/$variant/dist/cpp/bin/alljoyn-daemon "$DEBNAME/usr/bin/" 53 | cp -fv $ROOT/devicehive-alljoyn/alljoyn/core/alljoyn/build/linux/armhf/$variant/dist/cpp/lib/liballjoyn.so "$DEBNAME/usr/lib/" 54 | cp -fv $ROOT/devicehive-alljoyn/alljoyn/core/ajtcl/libajtcl.so "$DEBNAME/usr/lib/" 55 | # TODO: do we need update LD_LIBRARY_PATH? 56 | pushd $ROOT/devicehive-alljoyn && GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ go build -o "$DEBNAME/usr/bin/devicehive-alljoyn" && popd 57 | ARCHITECTURE=arm render_template "$DEBNAME/DEBIAN/control" 58 | dpkg-deb --build $DEBNAME && rm -rf "$DEBNAME" 59 | 60 | -------------------------------------------------------------------------------- /build/debian/framework.template/DEBIAN/control: -------------------------------------------------------------------------------- 1 | Package: devicehive-IoT-framework 2 | Version: ${VERSION} 3 | Section: base 4 | Priority: optional 5 | Architecture: ${ARCHITECTURE} 6 | Maintainer: DeviceHive Team 7 | Description: DeviceHive IoT framework 8 | Set of DeviceHive IoT tools 9 | git revision ${GITHASH} 10 | -------------------------------------------------------------------------------- /build/debian/framework.template/etc/dbus-1/system.d/com.devicehive.alljoyn.conf: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /build/debian/framework.template/etc/dbus-1/system.d/com.devicehive.ble.conf: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /build/debian/framework.template/etc/dbus-1/system.d/com.devicehive.cloud.conf: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /build/debian/framework.template/etc/init.d/alljoyn-daemon: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ### BEGIN INIT INFO 4 | # Provides: alljoyn-daemon 5 | # Required-Start: 6 | # Required-Stop: 7 | # Default-Start: 2 3 4 5 8 | # Default-Stop: 0 1 6 9 | # Short-Description: AllJoyn daemon 10 | # Description: This script is used to start/stop AllJoyn daemon. 11 | ### END INIT INFO 12 | 13 | DESC="AllJoyn daemon" 14 | NAME="alljoyn-daemon" 15 | DAEMON="/usr/bin/$NAME" 16 | 17 | PIDFILE="/var/run/$NAME.pid" 18 | LOGFILE="/var/log/$NAME.log" 19 | 20 | do_start() { 21 | if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE"); then 22 | echo "$NAME is already running" >&2 23 | return 1 24 | fi 25 | echo "$NAME starting..." >&2 26 | local CMD="$DAEMON &> \"$LOGFILE\" & echo \$!" 27 | su -c "$CMD" > "$PIDFILE" 28 | echo "$NAME started" >&2 29 | } 30 | 31 | do_stop() { 32 | if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then 33 | echo "$NAME is not running" >&2 34 | return 1 35 | fi 36 | echo "$NAME stopping..." >&2 37 | kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE" 38 | echo "$NAME stopped" >&2 39 | } 40 | 41 | case "$1" in 42 | start) 43 | do_start 44 | ;; 45 | stop) 46 | do_stop 47 | ;; 48 | restart) 49 | do_stop 50 | do_start 51 | ;; 52 | *) 53 | echo "Usage: $0 {start|stop|restart}" 54 | ;; 55 | esac 56 | 57 | -------------------------------------------------------------------------------- /build/debian/framework.template/etc/init.d/devicehive-alljoyn: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ### BEGIN INIT INFO 4 | # Provides: devicehive-alljoyn 5 | # Required-Start: alljoyn-daemon 6 | # Required-Stop: 7 | # Default-Start: 2 3 4 5 8 | # Default-Stop: 0 1 6 9 | # Short-Description: D-Bus to AllJoyn bridge 10 | # Description: This script is used to start/stop D-Bus to AllJoyn bridge. 11 | ### END INIT INFO 12 | 13 | DESC="D-Bus to AllJoyn bridge" 14 | NAME="devicehive-alljoyn" 15 | DAEMON="/usr/bin/$NAME" 16 | 17 | PIDFILE="/var/run/$NAME.pid" 18 | LOGFILE="/var/log/$NAME.log" 19 | 20 | do_start() { 21 | if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE"); then 22 | echo "$NAME is already running" >&2 23 | return 1 24 | fi 25 | echo "$NAME starting..." >&2 26 | local CMD="$DAEMON &> \"$LOGFILE\" & echo \$!" 27 | su -c "$CMD" > "$PIDFILE" 28 | echo "$NAME started" >&2 29 | } 30 | 31 | do_stop() { 32 | if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then 33 | echo "$NAME is not running" >&2 34 | return 1 35 | fi 36 | echo "$NAME stopping..." >&2 37 | kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE" 38 | echo "$NAME stopped" >&2 39 | } 40 | 41 | case "$1" in 42 | start) 43 | do_start 44 | ;; 45 | stop) 46 | do_stop 47 | ;; 48 | restart) 49 | do_stop 50 | do_start 51 | ;; 52 | *) 53 | echo "Usage: $0 {start|stop|restart}" 54 | ;; 55 | esac 56 | 57 | -------------------------------------------------------------------------------- /build/debian/framework.template/etc/init.d/devicehive-ble: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ### BEGIN INIT INFO 4 | # Provides: devicehive-ble 5 | # Required-Start: 6 | # Required-Stop: 7 | # Default-Start: 2 3 4 5 8 | # Default-Stop: 0 1 6 9 | # Short-Description: D-Bus to BLE bridge 10 | # Description: This script is used to start/stop D-Bus to BLE bridge. 11 | ### END INIT INFO 12 | 13 | DESC="D-Bus to BLE bridge" 14 | NAME="devicehive-ble" 15 | DAEMON="/usr/bin/$NAME" 16 | 17 | PIDFILE="/var/run/$NAME.pid" 18 | LOGFILE="/var/log/$NAME.log" 19 | 20 | do_start() { 21 | if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE"); then 22 | echo "$NAME is already running" >&2 23 | return 1 24 | fi 25 | echo "$NAME starting..." >&2 26 | local CMD="$DAEMON &> \"$LOGFILE\" & echo \$!" 27 | su -c "$CMD" > "$PIDFILE" 28 | echo "$NAME started" >&2 29 | } 30 | 31 | do_stop() { 32 | if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then 33 | echo "$NAME is not running" >&2 34 | return 1 35 | fi 36 | echo "$NAME stopping..." >&2 37 | kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE" 38 | echo "$NAME stopped" >&2 39 | } 40 | 41 | case "$1" in 42 | start) 43 | do_start 44 | ;; 45 | stop) 46 | do_stop 47 | ;; 48 | restart) 49 | do_stop 50 | do_start 51 | ;; 52 | *) 53 | echo "Usage: $0 {start|stop|restart}" 54 | ;; 55 | esac 56 | 57 | -------------------------------------------------------------------------------- /build/debian/framework.template/etc/init.d/devicehive-cloud: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ### BEGIN INIT INFO 4 | # Provides: devicehive-cloud 5 | # Required-Start: 6 | # Required-Stop: 7 | # Default-Start: 2 3 4 5 8 | # Default-Stop: 0 1 6 9 | # Short-Description: D-Bus to DeviceHive bridge 10 | # Description: This script is used to start/stop D-Bus to DeviceHive bridge. 11 | ### END INIT INFO 12 | 13 | DESC="D-Bus to DeviceHive bridge" 14 | NAME="devicehive-cloud" 15 | DAEMON="/usr/bin/$NAME" 16 | 17 | PIDFILE="/var/run/$NAME.pid" 18 | LOGFILE="/var/log/$NAME.log" 19 | 20 | do_start() { 21 | if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE"); then 22 | echo "$NAME is already running" >&2 23 | return 1 24 | fi 25 | echo "$NAME starting..." >&2 26 | local CMD="$DAEMON &> \"$LOGFILE\" & echo \$!" 27 | su -c "$CMD" > "$PIDFILE" 28 | echo "$NAME started" >&2 29 | } 30 | 31 | do_stop() { 32 | if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then 33 | echo "$NAME is not running" >&2 34 | return 1 35 | fi 36 | echo "$NAME stopping..." >&2 37 | kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE" 38 | echo "$NAME stopped" >&2 39 | } 40 | 41 | case "$1" in 42 | start) 43 | do_start 44 | ;; 45 | stop) 46 | do_stop 47 | ;; 48 | restart) 49 | do_stop 50 | do_start 51 | ;; 52 | *) 53 | echo "Usage: $0 {start|stop|restart}" 54 | ;; 55 | esac 56 | 57 | -------------------------------------------------------------------------------- /build/debian/readme.md: -------------------------------------------------------------------------------- 1 | ## IoT Framework for debian like operating systems 2 | Run 3 | ```bash 4 | devicehive-cloud.create 5 | ``` 6 | to create binaries. Currently, all binaries will not be build, so if you need binaries you can make build for snappy and then extract binaries from snap files(it's archives, just open it with any archinve manager) 7 | -------------------------------------------------------------------------------- /build/snappy/build-alljoyn.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "building AllJoyn ..." 4 | PLATFORM=x86_64 devicehive-alljoyn-tools/build.sh || exit 1 5 | PLATFORM=armhf devicehive-alljoyn-tools/build.sh || exit 1 6 | 7 | echo "building snappy package (devicehive-alljoyn) ..." 8 | snappy build devicehive-alljoyn || exit 1 9 | 10 | exit 0 # OK 11 | 12 | -------------------------------------------------------------------------------- /build/snappy/build-apps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | devicehive-iot-demo/build.sh 4 | snappy build devicehive-iot-demo 5 | 6 | sysmon/build.sh 7 | snappy build sysmon 8 | 9 | canonical-heart-pulse-demo/build.sh 10 | snappy build canonical-heart-pulse-demo 11 | 12 | sensortag-cloud-demo/build.sh 13 | snappy build sensortag-cloud-demo 14 | -------------------------------------------------------------------------------- /build/snappy/build-framework.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Building framework..." 4 | devicehive-framework/build.sh 5 | 6 | echo "snappy Building package (devicehive-framework) ..." 7 | snappy build devicehive-framework 8 | -------------------------------------------------------------------------------- /build/snappy/canonical-heart-pulse-demo/bin/service: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | SNAPP_APP_PATH=$(realpath $(dirname $0)/../) 6 | SNAPP_APP_DATA_PATH=/var/lib$SNAPP_APP_PATH 7 | 8 | # map platform 9 | PLATFORM= 10 | case $(uname -i) in 11 | x86_64) 12 | PLATFORM=x86_64 13 | ;; 14 | armv7l) 15 | PLATFORM=armhf 16 | ;; 17 | *) 18 | echo "Unknown platform" 19 | exit 1 20 | ;; 21 | esac 22 | 23 | # set enviroment 24 | export LD_LIBRARY_PATH="$SNAPP_APP_PATH/lib/$PLATFORM/:$LD_LIBRARY_PATH" 25 | export PATH="$SNAPP_APP_PATH/bin/$PLATFORM/:$PATH" 26 | mkdir -p $SNAPP_APP_DATA_PATH # system create this folder only after service has started for the first time 27 | 28 | # run 29 | $SNAPP_APP_PATH/bin/$PLATFORM/heart-pulse-demo -conf=$SNAPP_APP_DATA_PATH/config.yaml 30 | -------------------------------------------------------------------------------- /build/snappy/canonical-heart-pulse-demo/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$(dirname "$(readlink -f "$0")")" 4 | 5 | go get github.com/godbus/dbus 6 | 7 | GOOS=linux go build -o $DIR/bin/x86_64/heart-pulse-demo $DIR/../../../examples/heart-pulse-demo.go 8 | GOOS=linux GOARCH=arm GOARM=7 go build -o $DIR/bin/armhf/heart-pulse-demo $DIR/../../../examples/heart-pulse-demo.go 9 | -------------------------------------------------------------------------------- /build/snappy/canonical-heart-pulse-demo/meta/devicehive.apparmor: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | ###VAR### 4 | 5 | ###PROFILEATTACH### (attach_disconnected) { 6 | #include 7 | #include 8 | #include 9 | 10 | # for python apps/services 11 | #include 12 | /usr/bin/python{,2,2.[0-9]*,3,3.[0-9]*} ixr, 13 | 14 | # for perl apps/services 15 | #include 16 | /usr/bin/perl{,5*} ixr, 17 | 18 | # for bash 'binaries' (do *not* use abstractions/bash) 19 | # user-specific bash files 20 | /bin/bash ixr, 21 | /bin/dash ixr, 22 | /etc/bash.bashrc r, 23 | /usr/share/terminfo/** r, 24 | /etc/inputrc r, 25 | deny @{HOME}/.inputrc r, 26 | # Common utilities for shell scripts 27 | /{,usr/}bin/{,g,m}awk ixr, 28 | /{,usr/}bin/basename ixr, 29 | /{,usr/}bin/bunzip2 ixr, 30 | /{,usr/}bin/bzcat ixr, 31 | /{,usr/}bin/bzdiff ixr, 32 | /{,usr/}bin/bzgrep ixr, 33 | /{,usr/}bin/bzip2 ixr, 34 | /{,usr/}bin/cat ixr, 35 | /{,usr/}bin/chmod ixr, 36 | /{,usr/}bin/cmp ixr, 37 | /{,usr/}bin/cp ixr, 38 | /{,usr/}bin/cpio ixr, 39 | /{,usr/}bin/cut ixr, 40 | /{,usr/}bin/date ixr, 41 | /{,usr/}bin/dd ixr, 42 | /{,usr/}bin/diff{,3} ixr, 43 | /{,usr/}bin/dir ixr, 44 | /{,usr/}bin/dirname ixr, 45 | /{,usr/}bin/echo ixr, 46 | /{,usr/}bin/{,e,f,r}grep ixr, 47 | /{,usr/}bin/env ixr, 48 | /{,usr/}bin/expr ixr, 49 | /{,usr/}bin/find ixr, 50 | /{,usr/}bin/fmt ixr, 51 | /{,usr/}bin/getopt ixr, 52 | /{,usr/}bin/false ixr, 53 | /{,usr/}bin/head ixr, 54 | /{,usr/}bin/id ixr, 55 | /{,usr/}bin/igawk ixr, 56 | /{,usr/}bin/kill ixr, 57 | /{,usr/}bin/ln ixr, 58 | /{,usr/}bin/line ixr, 59 | /{,usr/}bin/link ixr, 60 | /{,usr/}bin/ls ixr, 61 | /{,usr/}bin/md5sum ixr, 62 | /{,usr/}bin/mkdir ixr, 63 | /{,usr/}bin/mktemp ixr, 64 | /{,usr/}bin/mv ixr, 65 | /{,usr/}bin/pgrep ixr, 66 | /{,usr/}bin/printenv ixr, 67 | /{,usr/}bin/printf ixr, 68 | /{,usr/}bin/ps ixr, 69 | /{,usr/}bin/pwd ixr, 70 | /{,usr/}bin/readlink ixr, 71 | /{,usr/}bin/realpath ixr, 72 | /{,usr/}bin/rev ixr, 73 | /{,usr/}bin/rm ixr, 74 | /{,usr/}bin/rmdir ixr, 75 | /{,usr/}bin/sed ixr, 76 | /{,usr/}bin/seq ixr, 77 | /{,usr/}bin/sleep ixr, 78 | /{,usr/}bin/sort ixr, 79 | /{,usr/}bin/stat ixr, 80 | /{,usr/}bin/tac ixr, 81 | /{,usr/}bin/tail ixr, 82 | /{,usr/}bin/tar ixr, 83 | /{,usr/}bin/tee ixr, 84 | /{,usr/}bin/test ixr, 85 | /{,usr/}bin/tempfile ixr, 86 | /{,usr/}bin/touch ixr, 87 | /{,usr/}bin/tr ixr, 88 | /{,usr/}bin/true ixr, 89 | /{,usr/}bin/uname ixr, 90 | /{,usr/}bin/uniq ixr, 91 | /{,usr/}bin/unlink ixr, 92 | /{,usr/}bin/unxz ixr, 93 | /{,usr/}bin/unzip ixr, 94 | /{,usr/}bin/vdir ixr, 95 | /{,usr/}bin/wc ixr, 96 | /{,usr/}bin/which ixr, 97 | /{,usr/}bin/xz ixr, 98 | /{,usr/}bin/yes ixr, 99 | /{,usr/}bin/zcat ixr, 100 | /{,usr/}bin/z{,e,f}grep ixr, 101 | /{,usr/}bin/zip ixr, 102 | /{,usr/}bin/zipgrep ixr, 103 | 104 | # uptime 105 | /{,usr/}bin/uptime ixr, 106 | @{PROC}/uptime r, 107 | @{PROC}/loadavg r, 108 | @{PROC}/stat r, 109 | # this is an information leak 110 | deny /{,var/}run/utmp r, 111 | 112 | # Miscellaneous accesses 113 | /etc/mime.types r, 114 | @{PROC}/sys/kernel/hostname r, 115 | @{PROC}/sys/kernel/osrelease r, 116 | 117 | # Read-only for the install directory 118 | @{CLICK_DIR}/@{APP_PKGNAME}/ r, 119 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/ r, 120 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/** mrklix, 121 | 122 | # Read-only home area for other versions 123 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ r, 124 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ r, 125 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** mrkix, 126 | 127 | # Writable home area for this version. 128 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 129 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 130 | 131 | # Read-only system area for other versions 132 | /var/lib/apps/@{APP_PKGNAME}/ r, 133 | /var/lib/apps/@{APP_PKGNAME}/** mrkix, 134 | 135 | # TODO: the write on these is needed in case they doesn't exist, but means an 136 | # app could adjust inode data and affect rollbacks. 137 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ w, 138 | /var/lib/apps/@{APP_PKGNAME}/ w, 139 | 140 | # Writable system area only for this version 141 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 142 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 143 | 144 | # Writable temp area only for this version (launcher will create this 145 | # directory on our behalf so only allow readonly on parent) 146 | /tmp/snapps/@{APP_PKGNAME}/ r, 147 | /tmp/snapps/@{APP_PKGNAME}/** rk, 148 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/ rw, 149 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/** mrwlkix, 150 | 151 | # No abstractions specified 152 | 153 | # Rules specified via policy groups 154 | # Description: Can access the network 155 | # Usage: common 156 | #include 157 | #include 158 | 159 | @{PROC}/sys/net/core/somaxconn r, 160 | 161 | # We want to explicitly deny access to NetworkManager because its DBus API 162 | # gives away too much 163 | deny dbus (receive, send) 164 | bus=system 165 | path=/org/freedesktop/NetworkManager, 166 | deny dbus (receive, send) 167 | bus=system 168 | peer=(name=org.freedesktop.NetworkManager), 169 | 170 | # Do the same for ofono (LP: #1226844) 171 | deny dbus (receive, send) 172 | bus=system 173 | interface="org.ofono.Manager", 174 | 175 | # No read paths specified 176 | 177 | # No write paths specified 178 | 179 | # dbus 180 | /run/dbus/system_bus_socket rw, 181 | dbus (send,receive) bus=system, 182 | dbus (bind) bus=system, 183 | 184 | /proc/*/mounts r, 185 | 186 | # bluetooth 187 | network bluetooth raw, 188 | network bluetooth seqpacket, 189 | capability net_admin, 190 | capability net_raw, 191 | } 192 | -------------------------------------------------------------------------------- /build/snappy/canonical-heart-pulse-demo/meta/heart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devicehive/IoT-framework/b268664a3e28f7fda786dc872a83879329bbf65d/build/snappy/canonical-heart-pulse-demo/meta/heart.png -------------------------------------------------------------------------------- /build/snappy/canonical-heart-pulse-demo/meta/hooks/config: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | SNAPP_APP_PATH=$(realpath $(dirname $0)/../../) 3 | SNAPP_APP_DATA_PATH=/var/lib$SNAPP_APP_PATH 4 | cat /dev/stdin > $SNAPP_APP_DATA_PATH/config.yaml 5 | -------------------------------------------------------------------------------- /build/snappy/canonical-heart-pulse-demo/meta/package.yaml: -------------------------------------------------------------------------------- 1 | name: canonical-heart-pulse-demo 2 | version: 1.0.0 3 | type: app 4 | vendor: Loïc Minier 5 | icon: meta/heart.png 6 | architecture: [amd64, armhf] 7 | frameworks: 8 | - devicehive-iot-toolkit 9 | services: 10 | - name: service 11 | description: "Combine various frameworks in one demo: BLE Cloud EnOcean" 12 | start: bin/service 13 | security-policy: 14 | apparmor: meta/devicehive.apparmor -------------------------------------------------------------------------------- /build/snappy/canonical-heart-pulse-demo/meta/readme.md: -------------------------------------------------------------------------------- 1 | Canonical pulsating heart beat demo using and based on DeviceHive 2 | 3 | Canonical pulsating heart beat demo using and based on DeviceHive 4 | -------------------------------------------------------------------------------- /build/snappy/devicehive-alljoyn-tools/alljoyn-armhf.patch: -------------------------------------------------------------------------------- 1 | diff --git a/build_core/SConscript b/build_core/SConscript 2 | index c1f8562..b3fed7b 100644 3 | --- a/build_core/SConscript 4 | +++ b/build_core/SConscript 5 | @@ -24,7 +24,7 @@ if platform.system() == 'Linux': 6 | default_target_cpu = 'x86_64' 7 | else: 8 | default_target_cpu = 'x86' 9 | - allowed_target_cpus = ('x86', 'x86_64', 'arm', 'openwrt') 10 | + allowed_target_cpus = ('x86', 'x86_64', 'arm', 'armhf', 'openwrt') 11 | 12 | default_msvc_version = None 13 | 14 | diff --git a/build_core/conf/linux/armhf/SConscript b/build_core/conf/linux/armhf/SConscript 15 | new file mode 100644 16 | index 0000000..abe6e00 17 | --- /dev/null 18 | +++ b/build_core/conf/linux/armhf/SConscript 19 | @@ -0,0 +1,42 @@ 20 | +# Copyright AllSeen Alliance. All rights reserved. 21 | +# 22 | +# Permission to use, copy, modify, and/or distribute this software for any 23 | +# purpose with or without fee is hereby granted, provided that the above 24 | +# copyright notice and this permission notice appear in all copies. 25 | +# 26 | +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 27 | +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 28 | +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 29 | +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 30 | +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 31 | +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 32 | +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 | +# 34 | + 35 | +Import('env') 36 | +import os 37 | + 38 | +# Linux specific flags 39 | +env.Append(CPPDEFINES=['QCC_CPU_ARM']) 40 | +env.Append(CPPFLAGS=['-fPIC', 41 | + '-mthumb-interwork']) 42 | + 43 | +# Use the OpenEmbedded cross-compilation environment 44 | +vars = Variables() 45 | +vars.Add('CROSS_COMPILE', 'Cross compile toolchain prefix', os.environ.get('CROSS_COMPILE')) 46 | +vars.Update(env) 47 | +Help(vars.GenerateHelpText(env)) 48 | + 49 | +# Use common CROSS_COMPILE prefix 50 | +if '' == env.subst('$CROSS_COMPILE'): 51 | + print 'CROSS_COMPILE variable is required for Linux/ARM builds' 52 | + if not GetOption('help'): 53 | + Exit(1) 54 | + 55 | +env['CC'] = env['CROSS_COMPILE'] + 'gcc' 56 | +env['CXX'] = env['CROSS_COMPILE'] + 'g++' 57 | +env['LINK'] = env['CROSS_COMPILE'] + 'gcc' 58 | + 59 | + 60 | + 61 | + 62 | -------------------------------------------------------------------------------- /build/snappy/devicehive-alljoyn-tools/armhf/libcap.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devicehive/IoT-framework/b268664a3e28f7fda786dc872a83879329bbf65d/build/snappy/devicehive-alljoyn-tools/armhf/libcap.so -------------------------------------------------------------------------------- /build/snappy/devicehive-alljoyn-tools/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | platform=${PLATFORM:-`uname -i`} # platform: x86_64|armhf 4 | variant=${VARIANT:-"release"} # variant: debug|release 5 | echo "platform=$platform variant=$variant" 6 | 7 | DIR="$(dirname "$(readlink -f "$0")")" 8 | OUT_DIR=$DIR/../devicehive-alljoyn 9 | AJ_PATH=$DIR/../../../devicehive-alljoyn 10 | AJ_CPP=$AJ_PATH/alljoyn/core/alljoyn/build/linux/$platform/$variant/dist/cpp 11 | 12 | mkdir -p $OUT_DIR/bin/$platform/ 13 | mkdir -p $OUT_DIR/lib/$platform/ 14 | 15 | # patch alljoyn and ensure libcap.so is available on ARM 16 | case $platform in 17 | arm|armhf|RPi|RPi2|BBB) 18 | [ -d $AJ_PATH/alljoyn/core/alljoyn/build_core/conf/linux/armhf ] || patch -d $AJ_PATH/alljoyn/core/alljoyn -p1 -i $DIR/alljoyn-armhf.patch 19 | [ -e /usr/arm-linux-gnueabihf/lib/libcap.so ] || sudo ln -s $DIR/armhf/libcap.so /usr/arm-linux-gnueabihf/lib/libcap.so 20 | # TODO: remove these symbolic links at the end 21 | ;; 22 | esac 23 | 24 | # Standard+Thin Core 25 | echo "Building thin core ..." 26 | pushd $AJ_PATH/alljoyn 27 | ./build-thin-linux-core || exit 1 28 | popd 29 | 30 | # Thin Services 31 | echo "Building thin services ..." 32 | pushd $AJ_PATH/alljoyn 33 | ./build-thin-linux-services || exit 1 34 | popd 35 | 36 | # Go service 37 | echo "Building Go service ..." 38 | pushd $AJ_PATH 39 | case $platform in 40 | x86_64) 41 | GOOS=linux go build -o $OUT_DIR/bin/$platform/devicehive-alljoyn || exit 1 42 | ;; 43 | arm|armhf|RPi|RPi2) 44 | GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ go build -o $OUT_DIR/bin/$platform/devicehive-alljoyn || exit 1 45 | ;; 46 | *) 47 | echo "Unsupported platform" 48 | exit 1 49 | ;; 50 | esac 51 | popd 52 | 53 | echo "Copying alljoyn daemon ..." 54 | cp -fv $AJ_CPP/bin/alljoyn-daemon $OUT_DIR/bin/$platform/ || exit 1 55 | cp -fv $AJ_CPP/lib/liballjoyn.so $OUT_DIR/lib/$platform/ || exit 1 56 | cp -fv $AJ_PATH/alljoyn/core/ajtcl/libajtcl.so $OUT_DIR/lib/$platform/ || exit 1 57 | 58 | exit 0 # OK 59 | 60 | -------------------------------------------------------------------------------- /build/snappy/devicehive-alljoyn/bin/alljoyn-daemon: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | app_path=${SNAP_APP_PATH:-"$(realpath $(dirname $0)/../)"} 6 | app_data=${SNAP_APP_DATA_PATH:-"/var/lib$app_path"} 7 | 8 | # map platform 9 | case $(uname -i) in 10 | x86_64) 11 | platform=x86_64 12 | ;; 13 | armv7l) 14 | platform=armhf 15 | ;; 16 | *) 17 | echo "Unknown platform" 18 | exit 1 19 | ;; 20 | esac 21 | 22 | # set library path enviroment 23 | export LD_LIBRARY_PATH="$app_path/lib/$platform/:$LD_LIBRARY_PATH" 24 | export PATH="$app_path/bin/$platform/:$PATH" 25 | mkdir -p "$app_data" # system creates this folder only after service has started for the first time 26 | 27 | # run it 28 | $app_path/bin/$platform/alljoyn-daemon 29 | #-conf=$app_conf 30 | 31 | -------------------------------------------------------------------------------- /build/snappy/devicehive-alljoyn/bin/devicehive-alljoyn: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | app_path=${SNAP_APP_PATH:-"$(realpath $(dirname $0)/../)"} 6 | app_data=${SNAP_APP_DATA_PATH:-"/var/lib$app_path"} 7 | 8 | # map platform 9 | case $(uname -i) in 10 | x86_64) 11 | platform=x86_64 12 | ;; 13 | armv7l) 14 | platform=armhf 15 | ;; 16 | *) 17 | echo "Unknown platform" 18 | exit 1 19 | ;; 20 | esac 21 | 22 | # set library path enviroment 23 | export LD_LIBRARY_PATH="$app_path/lib/$platform/:$LD_LIBRARY_PATH" 24 | export PATH="$app_path/bin/$platform/:$PATH" 25 | mkdir -p "$app_data" # system creates this folder only after service has started for the first time 26 | 27 | # run it 28 | cd $app_data 29 | $app_path/bin/$platform/devicehive-alljoyn 30 | #-conf=$app_conf 31 | 32 | -------------------------------------------------------------------------------- /build/snappy/devicehive-alljoyn/meta/alljoyn-daemon.apparmor: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | ###VAR### 4 | 5 | ###PROFILEATTACH### (attach_disconnected) { 6 | #include 7 | #include 8 | #include 9 | 10 | # for python apps/services 11 | #include 12 | /usr/bin/python{,2,2.[0-9]*,3,3.[0-9]*} ixr, 13 | 14 | # for perl apps/services 15 | #include 16 | /usr/bin/perl{,5*} ixr, 17 | 18 | # for bash 'binaries' (do *not* use abstractions/bash) 19 | # user-specific bash files 20 | /bin/bash ixr, 21 | /bin/dash ixr, 22 | /etc/bash.bashrc r, 23 | /usr/share/terminfo/** r, 24 | /etc/inputrc r, 25 | deny @{HOME}/.inputrc r, 26 | # Common utilities for shell scripts 27 | /{,usr/}bin/{,g,m}awk ixr, 28 | /{,usr/}bin/basename ixr, 29 | /{,usr/}bin/bunzip2 ixr, 30 | /{,usr/}bin/bzcat ixr, 31 | /{,usr/}bin/bzdiff ixr, 32 | /{,usr/}bin/bzgrep ixr, 33 | /{,usr/}bin/bzip2 ixr, 34 | /{,usr/}bin/cat ixr, 35 | /{,usr/}bin/chmod ixr, 36 | /{,usr/}bin/cmp ixr, 37 | /{,usr/}bin/cp ixr, 38 | /{,usr/}bin/cpio ixr, 39 | /{,usr/}bin/cut ixr, 40 | /{,usr/}bin/date ixr, 41 | /{,usr/}bin/dd ixr, 42 | /{,usr/}bin/diff{,3} ixr, 43 | /{,usr/}bin/dir ixr, 44 | /{,usr/}bin/dirname ixr, 45 | /{,usr/}bin/echo ixr, 46 | /{,usr/}bin/{,e,f,r}grep ixr, 47 | /{,usr/}bin/env ixr, 48 | /{,usr/}bin/expr ixr, 49 | /{,usr/}bin/find ixr, 50 | /{,usr/}bin/fmt ixr, 51 | /{,usr/}bin/getopt ixr, 52 | /{,usr/}bin/false ixr, 53 | /{,usr/}bin/head ixr, 54 | /{,usr/}bin/id ixr, 55 | /{,usr/}bin/igawk ixr, 56 | /{,usr/}bin/kill ixr, 57 | /{,usr/}bin/ln ixr, 58 | /{,usr/}bin/line ixr, 59 | /{,usr/}bin/link ixr, 60 | /{,usr/}bin/ls ixr, 61 | /{,usr/}bin/md5sum ixr, 62 | /{,usr/}bin/mkdir ixr, 63 | /{,usr/}bin/mktemp ixr, 64 | /{,usr/}bin/mv ixr, 65 | /{,usr/}bin/pgrep ixr, 66 | /{,usr/}bin/printenv ixr, 67 | /{,usr/}bin/printf ixr, 68 | /{,usr/}bin/ps ixr, 69 | /{,usr/}bin/pwd ixr, 70 | /{,usr/}bin/readlink ixr, 71 | /{,usr/}bin/realpath ixr, 72 | /{,usr/}bin/rev ixr, 73 | /{,usr/}bin/rm ixr, 74 | /{,usr/}bin/rmdir ixr, 75 | /{,usr/}bin/sed ixr, 76 | /{,usr/}bin/seq ixr, 77 | /{,usr/}bin/sleep ixr, 78 | /{,usr/}bin/sort ixr, 79 | /{,usr/}bin/stat ixr, 80 | /{,usr/}bin/tac ixr, 81 | /{,usr/}bin/tail ixr, 82 | /{,usr/}bin/tar ixr, 83 | /{,usr/}bin/tee ixr, 84 | /{,usr/}bin/test ixr, 85 | /{,usr/}bin/tempfile ixr, 86 | /{,usr/}bin/touch ixr, 87 | /{,usr/}bin/tr ixr, 88 | /{,usr/}bin/true ixr, 89 | /{,usr/}bin/uname ixr, 90 | /{,usr/}bin/uniq ixr, 91 | /{,usr/}bin/unlink ixr, 92 | /{,usr/}bin/unxz ixr, 93 | /{,usr/}bin/unzip ixr, 94 | /{,usr/}bin/vdir ixr, 95 | /{,usr/}bin/wc ixr, 96 | /{,usr/}bin/which ixr, 97 | /{,usr/}bin/xz ixr, 98 | /{,usr/}bin/yes ixr, 99 | /{,usr/}bin/zcat ixr, 100 | /{,usr/}bin/z{,e,f}grep ixr, 101 | /{,usr/}bin/zip ixr, 102 | /{,usr/}bin/zipgrep ixr, 103 | 104 | # uptime 105 | /{,usr/}bin/uptime ixr, 106 | @{PROC}/uptime r, 107 | @{PROC}/loadavg r, 108 | # this is an information leak 109 | deny /{,var/}run/utmp r, 110 | 111 | # Miscellaneous accesses 112 | /etc/mime.types r, 113 | @{PROC}/sys/kernel/hostname r, 114 | @{PROC}/sys/kernel/osrelease r, 115 | 116 | # Read-only for the install directory 117 | @{CLICK_DIR}/@{APP_PKGNAME}/ r, 118 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/ r, 119 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/** mrklix, 120 | 121 | # Read-only home area for other versions 122 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ r, 123 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ r, 124 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** mrkix, 125 | 126 | # Writable home area for this version. 127 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 128 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 129 | 130 | # Read-only system area for other versions 131 | /var/lib/apps/@{APP_PKGNAME}/ r, 132 | /var/lib/apps/@{APP_PKGNAME}/** mrkix, 133 | 134 | # TODO: the write on these is needed in case they doesn't exist, but means an 135 | # app could adjust inode data and affect rollbacks. 136 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ w, 137 | /var/lib/apps/@{APP_PKGNAME}/ w, 138 | 139 | # Writable system area only for this version 140 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 141 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 142 | 143 | # Writable temp area only for this version (launcher will create this 144 | # directory on our behalf so only allow readonly on parent) 145 | /tmp/snapps/@{APP_PKGNAME}/ r, 146 | /tmp/snapps/@{APP_PKGNAME}/** rk, 147 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/ rw, 148 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/** mrwlkix, 149 | 150 | # No abstractions specified 151 | 152 | # Rules specified via policy groups 153 | # Description: Can access the network 154 | # Usage: common 155 | #include 156 | #include 157 | 158 | @{PROC}/sys/net/core/somaxconn r, 159 | 160 | # We want to explicitly deny access to NetworkManager because its DBus API 161 | # gives away too much 162 | deny dbus (receive, send) 163 | bus=system 164 | path=/org/freedesktop/NetworkManager, 165 | deny dbus (receive, send) 166 | bus=system 167 | peer=(name=org.freedesktop.NetworkManager), 168 | 169 | # Do the same for ofono (LP: #1226844) 170 | deny dbus (receive, send) 171 | bus=system 172 | interface="org.ofono.Manager", 173 | 174 | # No read paths specified 175 | 176 | # No write paths specified 177 | 178 | #include 179 | 180 | # dbus 181 | /run/dbus/system_bus_socket rw, 182 | dbus (send,receive) bus=system, 183 | #dbus (bind) bus=system, 184 | 185 | # Allow binding the service and receiving traffic 186 | dbus (send) 187 | bus=system 188 | path=/org/freedesktop/DBus 189 | interface=org.freedesktop.DBus 190 | member=RequestName 191 | peer=(name=org.freedesktop.DBus), 192 | 193 | /proc/*/mounts r, 194 | 195 | # Network 196 | network inet stream, 197 | network unix stream, 198 | network inet6 stream, 199 | network netlink dgram, 200 | 201 | capability net_admin, 202 | capability net_raw, 203 | /dev/urandom r, 204 | } 205 | -------------------------------------------------------------------------------- /build/snappy/devicehive-alljoyn/meta/devicehive-alljoyn.apparmor: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | ###VAR### 4 | 5 | ###PROFILEATTACH### (attach_disconnected) { 6 | #include 7 | #include 8 | #include 9 | 10 | # for python apps/services 11 | #include 12 | /usr/bin/python{,2,2.[0-9]*,3,3.[0-9]*} ixr, 13 | 14 | # for perl apps/services 15 | #include 16 | /usr/bin/perl{,5*} ixr, 17 | 18 | # for bash 'binaries' (do *not* use abstractions/bash) 19 | # user-specific bash files 20 | /bin/bash ixr, 21 | /bin/dash ixr, 22 | /etc/bash.bashrc r, 23 | /usr/share/terminfo/** r, 24 | /etc/inputrc r, 25 | deny @{HOME}/.inputrc r, 26 | # Common utilities for shell scripts 27 | /{,usr/}bin/{,g,m}awk ixr, 28 | /{,usr/}bin/basename ixr, 29 | /{,usr/}bin/bunzip2 ixr, 30 | /{,usr/}bin/bzcat ixr, 31 | /{,usr/}bin/bzdiff ixr, 32 | /{,usr/}bin/bzgrep ixr, 33 | /{,usr/}bin/bzip2 ixr, 34 | /{,usr/}bin/cat ixr, 35 | /{,usr/}bin/chmod ixr, 36 | /{,usr/}bin/cmp ixr, 37 | /{,usr/}bin/cp ixr, 38 | /{,usr/}bin/cpio ixr, 39 | /{,usr/}bin/cut ixr, 40 | /{,usr/}bin/date ixr, 41 | /{,usr/}bin/dd ixr, 42 | /{,usr/}bin/diff{,3} ixr, 43 | /{,usr/}bin/dir ixr, 44 | /{,usr/}bin/dirname ixr, 45 | /{,usr/}bin/echo ixr, 46 | /{,usr/}bin/{,e,f,r}grep ixr, 47 | /{,usr/}bin/env ixr, 48 | /{,usr/}bin/expr ixr, 49 | /{,usr/}bin/find ixr, 50 | /{,usr/}bin/fmt ixr, 51 | /{,usr/}bin/getopt ixr, 52 | /{,usr/}bin/false ixr, 53 | /{,usr/}bin/head ixr, 54 | /{,usr/}bin/id ixr, 55 | /{,usr/}bin/igawk ixr, 56 | /{,usr/}bin/kill ixr, 57 | /{,usr/}bin/ln ixr, 58 | /{,usr/}bin/line ixr, 59 | /{,usr/}bin/link ixr, 60 | /{,usr/}bin/ls ixr, 61 | /{,usr/}bin/md5sum ixr, 62 | /{,usr/}bin/mkdir ixr, 63 | /{,usr/}bin/mktemp ixr, 64 | /{,usr/}bin/mv ixr, 65 | /{,usr/}bin/pgrep ixr, 66 | /{,usr/}bin/printenv ixr, 67 | /{,usr/}bin/printf ixr, 68 | /{,usr/}bin/ps ixr, 69 | /{,usr/}bin/pwd ixr, 70 | /{,usr/}bin/readlink ixr, 71 | /{,usr/}bin/realpath ixr, 72 | /{,usr/}bin/rev ixr, 73 | /{,usr/}bin/rm ixr, 74 | /{,usr/}bin/rmdir ixr, 75 | /{,usr/}bin/sed ixr, 76 | /{,usr/}bin/seq ixr, 77 | /{,usr/}bin/sleep ixr, 78 | /{,usr/}bin/sort ixr, 79 | /{,usr/}bin/stat ixr, 80 | /{,usr/}bin/tac ixr, 81 | /{,usr/}bin/tail ixr, 82 | /{,usr/}bin/tar ixr, 83 | /{,usr/}bin/tee ixr, 84 | /{,usr/}bin/test ixr, 85 | /{,usr/}bin/tempfile ixr, 86 | /{,usr/}bin/touch ixr, 87 | /{,usr/}bin/tr ixr, 88 | /{,usr/}bin/true ixr, 89 | /{,usr/}bin/uname ixr, 90 | /{,usr/}bin/uniq ixr, 91 | /{,usr/}bin/unlink ixr, 92 | /{,usr/}bin/unxz ixr, 93 | /{,usr/}bin/unzip ixr, 94 | /{,usr/}bin/vdir ixr, 95 | /{,usr/}bin/wc ixr, 96 | /{,usr/}bin/which ixr, 97 | /{,usr/}bin/xz ixr, 98 | /{,usr/}bin/yes ixr, 99 | /{,usr/}bin/zcat ixr, 100 | /{,usr/}bin/z{,e,f}grep ixr, 101 | /{,usr/}bin/zip ixr, 102 | /{,usr/}bin/zipgrep ixr, 103 | 104 | # uptime 105 | /{,usr/}bin/uptime ixr, 106 | @{PROC}/uptime r, 107 | @{PROC}/loadavg r, 108 | # this is an information leak 109 | deny /{,var/}run/utmp r, 110 | 111 | # Miscellaneous accesses 112 | /etc/mime.types r, 113 | @{PROC}/sys/kernel/hostname r, 114 | @{PROC}/sys/kernel/osrelease r, 115 | 116 | # Read-only for the install directory 117 | @{CLICK_DIR}/@{APP_PKGNAME}/ r, 118 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/ r, 119 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/** mrklix, 120 | 121 | # Read-only home area for other versions 122 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ r, 123 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ r, 124 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** mrkix, 125 | 126 | # Writable home area for this version. 127 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 128 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 129 | 130 | # Read-only system area for other versions 131 | /var/lib/apps/@{APP_PKGNAME}/ r, 132 | /var/lib/apps/@{APP_PKGNAME}/** mrkix, 133 | 134 | # TODO: the write on these is needed in case they doesn't exist, but means an 135 | # app could adjust inode data and affect rollbacks. 136 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ w, 137 | /var/lib/apps/@{APP_PKGNAME}/ w, 138 | 139 | # Writable system area only for this version 140 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 141 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 142 | 143 | # Writable temp area only for this version (launcher will create this 144 | # directory on our behalf so only allow readonly on parent) 145 | /tmp/snapps/@{APP_PKGNAME}/ r, 146 | /tmp/snapps/@{APP_PKGNAME}/** rk, 147 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/ rw, 148 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/** mrwlkix, 149 | 150 | # No abstractions specified 151 | 152 | # Rules specified via policy groups 153 | # Description: Can access the network 154 | # Usage: common 155 | #include 156 | #include 157 | 158 | @{PROC}/sys/net/core/somaxconn r, 159 | 160 | # We want to explicitly deny access to NetworkManager because its DBus API 161 | # gives away too much 162 | deny dbus (receive, send) 163 | bus=system 164 | path=/org/freedesktop/NetworkManager, 165 | deny dbus (receive, send) 166 | bus=system 167 | peer=(name=org.freedesktop.NetworkManager), 168 | 169 | # Do the same for ofono (LP: #1226844) 170 | deny dbus (receive, send) 171 | bus=system 172 | interface="org.ofono.Manager", 173 | 174 | # No read paths specified 175 | 176 | # No write paths specified 177 | 178 | #include 179 | 180 | # dbus 181 | /run/dbus/system_bus_socket rw, 182 | dbus (send,receive) bus=system, 183 | #dbus (bind) bus=system, 184 | 185 | # Allow binding the service and receiving traffic 186 | dbus (send) 187 | bus=system 188 | path=/org/freedesktop/DBus 189 | interface=org.freedesktop.DBus 190 | member=RequestName 191 | peer=(name=org.freedesktop.DBus), 192 | 193 | dbus (bind) 194 | bus=system 195 | name="com.devicehive.alljoyn.bridge", 196 | 197 | /proc/*/mounts r, 198 | 199 | capability net_admin, 200 | capability net_raw, 201 | /dev/urandom r, 202 | } 203 | -------------------------------------------------------------------------------- /build/snappy/devicehive-alljoyn/meta/dh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devicehive/IoT-framework/b268664a3e28f7fda786dc872a83879329bbf65d/build/snappy/devicehive-alljoyn/meta/dh.png -------------------------------------------------------------------------------- /build/snappy/devicehive-alljoyn/meta/framework-policy/apparmor/policygroups/client: -------------------------------------------------------------------------------- 1 | # Description: allow using devicehive-alljoyn 2 | # Usage: common 3 | 4 | #include 5 | 6 | /run/dbus/system_bus_socket rw, 7 | dbus (receive, send) 8 | bus=system 9 | path=com/devicehive/alljoyn/bridge 10 | interface=com.devicehive.alljoyn.bridge,org.freedesktop.DBus.Introspectable, 11 | peer=(label=devicehive_alljoyn-service_*), 12 | 13 | -------------------------------------------------------------------------------- /build/snappy/devicehive-alljoyn/meta/hooks/config: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | SNAPP_APP_PATH=$(realpath $(dirname $0)/../../) 3 | SNAPP_APP_DATA_PATH=/var/lib$SNAPP_APP_PATH 4 | cat /dev/stdin > $SNAPP_APP_DATA_PATH/config.yaml 5 | -------------------------------------------------------------------------------- /build/snappy/devicehive-alljoyn/meta/package.yaml: -------------------------------------------------------------------------------- 1 | name: devicehive-alljoyn 2 | version: 1.0.2 3 | type: framework 4 | vendor: DataArt 5 | icon: meta/dh.png 6 | architecture: [amd64, armhf] 7 | services: 8 | - name: alljoyn-daemon 9 | description: "AllJoyn Daemon" 10 | start: bin/alljoyn-daemon 11 | security-policy: 12 | apparmor: meta/alljoyn-daemon.apparmor 13 | ports: 14 | external: 15 | alljoyn-tcp: 16 | port: 9955-9966/tcp 17 | negotiable: no 18 | alljoyn-udp: 19 | port: 9955-9966/udp 20 | negotiable: no 21 | 22 | - name: devicehive-alljoyn 23 | description: "DeviceHive AllJoyn Service" 24 | bus-name: "com.devicehive.alljoyn.bridge" 25 | start: bin/devicehive-alljoyn 26 | security-policy: 27 | apparmor: meta/devicehive-alljoyn.apparmor 28 | ports: 29 | internal: 30 | alljoyn-tcp: 31 | port: 9955-9966/tcp 32 | negotiable: no 33 | alljoyn-udp: 34 | port: 9955-9966/udp 35 | negotiable: no 36 | -------------------------------------------------------------------------------- /build/snappy/devicehive-alljoyn/meta/readme.md: -------------------------------------------------------------------------------- 1 | DeviceHive AllJoyn Framework 2 | 3 | Run "config" hook after install 4 | -------------------------------------------------------------------------------- /build/snappy/devicehive-framework/bin/ble-service: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | SNAPP_APP_PATH=$(realpath $(dirname $0)/../) 6 | SNAPP_APP_DATA_PATH=/var/lib$SNAPP_APP_PATH 7 | 8 | # map platform 9 | PLATFORM= 10 | case $(uname -i) in 11 | x86_64) 12 | PLATFORM=x86_64 13 | ;; 14 | armv7l) 15 | PLATFORM=armhf 16 | ;; 17 | *) 18 | echo "Unknown platform" 19 | exit 1 20 | ;; 21 | esac 22 | 23 | # set enviroment 24 | export LD_LIBRARY_PATH="$SNAPP_APP_PATH/lib/$PLATFORM/:$LD_LIBRARY_PATH" 25 | export PATH="$SNAPP_APP_PATH/bin/$PLATFORM/:$PATH" 26 | mkdir -p $SNAPP_APP_DATA_PATH # system create this folder only after service has started for the first time 27 | 28 | # run 29 | $SNAPP_APP_PATH/bin/$PLATFORM/devicehive-ble 30 | -------------------------------------------------------------------------------- /build/snappy/devicehive-framework/bin/cloud-service: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | SNAPP_APP_PATH=$(realpath $(dirname $0)/../) 6 | SNAPP_APP_DATA_PATH=/var/lib$SNAPP_APP_PATH 7 | 8 | # map platform 9 | PLATFORM= 10 | case $(uname -i) in 11 | x86_64) 12 | PLATFORM=x86_64 13 | ;; 14 | armv7l) 15 | PLATFORM=armhf 16 | ;; 17 | *) 18 | echo "Unknown platform" 19 | exit 1 20 | ;; 21 | esac 22 | 23 | # set enviroment 24 | export LD_LIBRARY_PATH="$SNAPP_APP_PATH/lib/$PLATFORM/:$LD_LIBRARY_PATH" 25 | export PATH="$SNAPP_APP_PATH/bin/$PLATFORM/:$PATH" 26 | mkdir -p $SNAPP_APP_DATA_PATH # system create this folder only after service has started for the first time 27 | 28 | if [ ! -f "$SNAPP_APP_DATA_PATH/config.yaml" ]; then 29 | echo "Config file not found!" 30 | #TODO here we can copy default config 31 | fi 32 | 33 | CLOUD_CONFIG=$SNAPP_APP_DATA_PATH/config.yaml 34 | 35 | # temporary solution for initial config 36 | if [ ! -f $CLOUD_CONFIG ]; then 37 | echo "Cloud Config was not found, using default one:" 38 | cat $SNAPP_APP_PATH/config.yaml 39 | #copy default config 40 | cp $SNAPP_APP_PATH/config.yaml $CLOUD_CONFIG 41 | fi 42 | 43 | 44 | # run 45 | $SNAPP_APP_PATH/bin/$PLATFORM/devicehive-cloud -conf=$CLOUD_CONFIG 46 | -------------------------------------------------------------------------------- /build/snappy/devicehive-framework/bin/enocean-service: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BASE=$(realpath $(dirname $0)/../); 4 | PYTHONUSERBASE=$BASE $BASE/bin/devicehive-enocean 5 | -------------------------------------------------------------------------------- /build/snappy/devicehive-framework/bin/gpio-service: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BASE=$(realpath $(dirname $0)/../); 4 | PYTHONUSERBASE=$BASE $BASE/bin/devicehive-gpio 5 | -------------------------------------------------------------------------------- /build/snappy/devicehive-framework/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$(dirname "$(readlink -f "$0")")" 4 | 5 | # Common 6 | echo "Fetching github.com/godbus/dbus ..." 7 | go get github.com/godbus/dbus 8 | 9 | # Bluetooth LE 10 | echo "Fetching github.com/devicehive/gatt" 11 | go get github.com/devicehive/gatt 12 | 13 | echo "Building devicehive-ble (amd64) ..." 14 | GOOS=linux go build -o $DIR/bin/x86_64/devicehive-ble $DIR/../../../devicehive-ble/devicehive-ble.go 15 | 16 | echo "Building devicehive-ble (arm) ..." 17 | GOOS=linux GOARCH=arm GOARM=7 go build -o $DIR/bin/armhf/devicehive-ble $DIR/../../../devicehive-ble/devicehive-ble.go 18 | 19 | # Cloud 20 | echo "Fetching gopkg.in/yaml.v2 ..." 21 | go get gopkg.in/yaml.v2 22 | 23 | echo "Fetching github.com/gorilla/websocket ..." 24 | go get github.com/gorilla/websocket 25 | # go get github.com/mibori/gopencils 26 | # GOOS=linux go build -o $DIR/bin/x86_64/devicehive-cloud $DIR/../../../devicehive-cloud/devicehive-cloud.go $DIR/../../../devicehive-cloud/rest-serve.go $DIR/../../../devicehive-cloud/ws-serve.go 27 | # GOOS=linux GOARCH=arm GOARM=7 go build -o $DIR/bin/armhf/devicehive-cloud $DIR/../../../devicehive-cloud/devicehive-cloud.go $DIR/../../../devicehive-cloud/rest-serve.go $DIR/../../../devicehive-cloud/ws-serve.go 28 | 29 | echo "Building devicehive-daemon (amd64) ..." 30 | GOOS=linux go build -o $DIR/bin/x86_64/devicehive-cloud $DIR/../../../devicehive-cloud/*.go 31 | echo "Building devicehive-cloud (arm) ..." 32 | GOOS=linux GOARCH=arm GOARM=7 go build -o $DIR/bin/armhf/devicehive-cloud $DIR/../../../devicehive-cloud/*.go 33 | 34 | 35 | # Enocean 36 | echo "Copying enocean-daemon ..." 37 | cp -fv $DIR/../../../devicehive-enocean/enocean-daemon $DIR/bin/devicehive-enocean 38 | 39 | echo "Pip3 install enocean ..." 40 | PYTHONUSERBASE=$DIR pip3 install --force-reinstall --upgrade --user enocean 41 | 42 | # GPIO 43 | 44 | echo "Copying gpio-daemon ..." 45 | cp -fv $DIR/../../../devicehive-gpio/gpio-daemon $DIR/bin/devicehive-gpio 46 | 47 | echo "Copying gpio-daemon profiles ..." 48 | cp -frv $DIR/../../../devicehive-gpio/profiles $DIR/bin/ 49 | 50 | -------------------------------------------------------------------------------- /build/snappy/devicehive-framework/config.yaml: -------------------------------------------------------------------------------- 1 | URL: http://playground.devicehive.com/api/rest 2 | AccessKey: 3 | 4 | DeviceID: snappy-device 5 | DeviceName: snappy-device 6 | SendNotificationQueueCapacity: 2048 7 | LoggingLevel: info 8 | -------------------------------------------------------------------------------- /build/snappy/devicehive-framework/meta/ble.apparmor: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | ###VAR### 4 | 5 | ###PROFILEATTACH### (attach_disconnected) { 6 | #include 7 | #include 8 | #include 9 | 10 | # for python apps/services 11 | #include 12 | /usr/bin/python{,2,2.[0-9]*,3,3.[0-9]*} ixr, 13 | 14 | # for perl apps/services 15 | #include 16 | /usr/bin/perl{,5*} ixr, 17 | 18 | # for bash 'binaries' (do *not* use abstractions/bash) 19 | # user-specific bash files 20 | /bin/bash ixr, 21 | /bin/dash ixr, 22 | /etc/bash.bashrc r, 23 | /usr/share/terminfo/** r, 24 | /etc/inputrc r, 25 | deny @{HOME}/.inputrc r, 26 | # Common utilities for shell scripts 27 | /{,usr/}bin/{,g,m}awk ixr, 28 | /{,usr/}bin/basename ixr, 29 | /{,usr/}bin/bunzip2 ixr, 30 | /{,usr/}bin/bzcat ixr, 31 | /{,usr/}bin/bzdiff ixr, 32 | /{,usr/}bin/bzgrep ixr, 33 | /{,usr/}bin/bzip2 ixr, 34 | /{,usr/}bin/cat ixr, 35 | /{,usr/}bin/chmod ixr, 36 | /{,usr/}bin/cmp ixr, 37 | /{,usr/}bin/cp ixr, 38 | /{,usr/}bin/cpio ixr, 39 | /{,usr/}bin/cut ixr, 40 | /{,usr/}bin/date ixr, 41 | /{,usr/}bin/dd ixr, 42 | /{,usr/}bin/diff{,3} ixr, 43 | /{,usr/}bin/dir ixr, 44 | /{,usr/}bin/dirname ixr, 45 | /{,usr/}bin/echo ixr, 46 | /{,usr/}bin/{,e,f,r}grep ixr, 47 | /{,usr/}bin/env ixr, 48 | /{,usr/}bin/expr ixr, 49 | /{,usr/}bin/find ixr, 50 | /{,usr/}bin/fmt ixr, 51 | /{,usr/}bin/getopt ixr, 52 | /{,usr/}bin/false ixr, 53 | /{,usr/}bin/head ixr, 54 | /{,usr/}bin/id ixr, 55 | /{,usr/}bin/igawk ixr, 56 | /{,usr/}bin/kill ixr, 57 | /{,usr/}bin/ln ixr, 58 | /{,usr/}bin/line ixr, 59 | /{,usr/}bin/link ixr, 60 | /{,usr/}bin/ls ixr, 61 | /{,usr/}bin/md5sum ixr, 62 | /{,usr/}bin/mkdir ixr, 63 | /{,usr/}bin/mktemp ixr, 64 | /{,usr/}bin/mv ixr, 65 | /{,usr/}bin/pgrep ixr, 66 | /{,usr/}bin/printenv ixr, 67 | /{,usr/}bin/printf ixr, 68 | /{,usr/}bin/ps ixr, 69 | /{,usr/}bin/pwd ixr, 70 | /{,usr/}bin/readlink ixr, 71 | /{,usr/}bin/realpath ixr, 72 | /{,usr/}bin/rev ixr, 73 | /{,usr/}bin/rm ixr, 74 | /{,usr/}bin/rmdir ixr, 75 | /{,usr/}bin/sed ixr, 76 | /{,usr/}bin/seq ixr, 77 | /{,usr/}bin/sleep ixr, 78 | /{,usr/}bin/sort ixr, 79 | /{,usr/}bin/stat ixr, 80 | /{,usr/}bin/tac ixr, 81 | /{,usr/}bin/tail ixr, 82 | /{,usr/}bin/tar ixr, 83 | /{,usr/}bin/tee ixr, 84 | /{,usr/}bin/test ixr, 85 | /{,usr/}bin/tempfile ixr, 86 | /{,usr/}bin/touch ixr, 87 | /{,usr/}bin/tr ixr, 88 | /{,usr/}bin/true ixr, 89 | /{,usr/}bin/uname ixr, 90 | /{,usr/}bin/uniq ixr, 91 | /{,usr/}bin/unlink ixr, 92 | /{,usr/}bin/unxz ixr, 93 | /{,usr/}bin/unzip ixr, 94 | /{,usr/}bin/vdir ixr, 95 | /{,usr/}bin/wc ixr, 96 | /{,usr/}bin/which ixr, 97 | /{,usr/}bin/xz ixr, 98 | /{,usr/}bin/yes ixr, 99 | /{,usr/}bin/zcat ixr, 100 | /{,usr/}bin/z{,e,f}grep ixr, 101 | /{,usr/}bin/zip ixr, 102 | /{,usr/}bin/zipgrep ixr, 103 | 104 | # uptime 105 | /{,usr/}bin/uptime ixr, 106 | @{PROC}/uptime r, 107 | @{PROC}/loadavg r, 108 | # this is an information leak 109 | deny /{,var/}run/utmp r, 110 | 111 | # Miscellaneous accesses 112 | /etc/mime.types r, 113 | @{PROC}/sys/kernel/hostname r, 114 | @{PROC}/sys/kernel/osrelease r, 115 | 116 | # Read-only for the install directory 117 | @{CLICK_DIR}/@{APP_PKGNAME}/ r, 118 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/ r, 119 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/** mrklix, 120 | 121 | # Read-only home area for other versions 122 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ r, 123 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ r, 124 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** mrkix, 125 | 126 | # Writable home area for this version. 127 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 128 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 129 | 130 | # Read-only system area for other versions 131 | /var/lib/apps/@{APP_PKGNAME}/ r, 132 | /var/lib/apps/@{APP_PKGNAME}/** mrkix, 133 | 134 | # TODO: the write on these is needed in case they doesn't exist, but means an 135 | # app could adjust inode data and affect rollbacks. 136 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ w, 137 | /var/lib/apps/@{APP_PKGNAME}/ w, 138 | 139 | # Writable system area only for this version 140 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 141 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 142 | 143 | # Writable temp area only for this version (launcher will create this 144 | # directory on our behalf so only allow readonly on parent) 145 | /tmp/snapps/@{APP_PKGNAME}/ r, 146 | /tmp/snapps/@{APP_PKGNAME}/** rk, 147 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/ rw, 148 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/** mrwlkix, 149 | 150 | # No abstractions specified 151 | 152 | # Rules specified via policy groups 153 | # Description: Can access the network 154 | # Usage: common 155 | #include 156 | #include 157 | 158 | @{PROC}/sys/net/core/somaxconn r, 159 | 160 | # We want to explicitly deny access to NetworkManager because its DBus API 161 | # gives away too much 162 | deny dbus (receive, send) 163 | bus=system 164 | path=/org/freedesktop/NetworkManager, 165 | deny dbus (receive, send) 166 | bus=system 167 | peer=(name=org.freedesktop.NetworkManager), 168 | 169 | # Do the same for ofono (LP: #1226844) 170 | deny dbus (receive, send) 171 | bus=system 172 | interface="org.ofono.Manager", 173 | 174 | # No read paths specified 175 | 176 | # No write paths specified 177 | 178 | #include 179 | 180 | # dbus 181 | /run/dbus/system_bus_socket rw, 182 | dbus (send,receive) bus=system, 183 | #dbus (bind) bus=system, 184 | 185 | # Allow binding the service and receiving traffic 186 | dbus (send) 187 | bus=system 188 | path=/org/freedesktop/DBus 189 | interface=org.freedesktop.DBus 190 | member=RequestName 191 | peer=(name=org.freedesktop.DBus), 192 | 193 | dbus (bind) 194 | bus=system 195 | name="com.devicehive.bluetooth", 196 | 197 | 198 | /proc/*/mounts r, 199 | 200 | # bluetooth 201 | network bluetooth raw, 202 | network bluetooth seqpacket, 203 | capability net_admin, 204 | capability net_raw, 205 | } 206 | -------------------------------------------------------------------------------- /build/snappy/devicehive-framework/meta/cloud.apparmor: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | ###VAR### 4 | 5 | ###PROFILEATTACH### (attach_disconnected) { 6 | #include 7 | #include 8 | #include 9 | 10 | # for python apps/services 11 | #include 12 | /usr/bin/python{,2,2.[0-9]*,3,3.[0-9]*} ixr, 13 | 14 | # for perl apps/services 15 | #include 16 | /usr/bin/perl{,5*} ixr, 17 | 18 | # for bash 'binaries' (do *not* use abstractions/bash) 19 | # user-specific bash files 20 | /bin/bash ixr, 21 | /bin/dash ixr, 22 | /etc/bash.bashrc r, 23 | /usr/share/terminfo/** r, 24 | /etc/inputrc r, 25 | deny @{HOME}/.inputrc r, 26 | # Common utilities for shell scripts 27 | /{,usr/}bin/{,g,m}awk ixr, 28 | /{,usr/}bin/basename ixr, 29 | /{,usr/}bin/bunzip2 ixr, 30 | /{,usr/}bin/bzcat ixr, 31 | /{,usr/}bin/bzdiff ixr, 32 | /{,usr/}bin/bzgrep ixr, 33 | /{,usr/}bin/bzip2 ixr, 34 | /{,usr/}bin/cat ixr, 35 | /{,usr/}bin/chmod ixr, 36 | /{,usr/}bin/cmp ixr, 37 | /{,usr/}bin/cp ixr, 38 | /{,usr/}bin/cpio ixr, 39 | /{,usr/}bin/cut ixr, 40 | /{,usr/}bin/date ixr, 41 | /{,usr/}bin/dd ixr, 42 | /{,usr/}bin/diff{,3} ixr, 43 | /{,usr/}bin/dir ixr, 44 | /{,usr/}bin/dirname ixr, 45 | /{,usr/}bin/echo ixr, 46 | /{,usr/}bin/{,e,f,r}grep ixr, 47 | /{,usr/}bin/env ixr, 48 | /{,usr/}bin/expr ixr, 49 | /{,usr/}bin/find ixr, 50 | /{,usr/}bin/fmt ixr, 51 | /{,usr/}bin/getopt ixr, 52 | /{,usr/}bin/false ixr, 53 | /{,usr/}bin/head ixr, 54 | /{,usr/}bin/id ixr, 55 | /{,usr/}bin/igawk ixr, 56 | /{,usr/}bin/kill ixr, 57 | /{,usr/}bin/ln ixr, 58 | /{,usr/}bin/line ixr, 59 | /{,usr/}bin/link ixr, 60 | /{,usr/}bin/ls ixr, 61 | /{,usr/}bin/md5sum ixr, 62 | /{,usr/}bin/mkdir ixr, 63 | /{,usr/}bin/mktemp ixr, 64 | /{,usr/}bin/mv ixr, 65 | /{,usr/}bin/pgrep ixr, 66 | /{,usr/}bin/printenv ixr, 67 | /{,usr/}bin/printf ixr, 68 | /{,usr/}bin/ps ixr, 69 | /{,usr/}bin/pwd ixr, 70 | /{,usr/}bin/readlink ixr, 71 | /{,usr/}bin/realpath ixr, 72 | /{,usr/}bin/rev ixr, 73 | /{,usr/}bin/rm ixr, 74 | /{,usr/}bin/rmdir ixr, 75 | /{,usr/}bin/sed ixr, 76 | /{,usr/}bin/seq ixr, 77 | /{,usr/}bin/sleep ixr, 78 | /{,usr/}bin/sort ixr, 79 | /{,usr/}bin/stat ixr, 80 | /{,usr/}bin/tac ixr, 81 | /{,usr/}bin/tail ixr, 82 | /{,usr/}bin/tar ixr, 83 | /{,usr/}bin/tee ixr, 84 | /{,usr/}bin/test ixr, 85 | /{,usr/}bin/tempfile ixr, 86 | /{,usr/}bin/touch ixr, 87 | /{,usr/}bin/tr ixr, 88 | /{,usr/}bin/true ixr, 89 | /{,usr/}bin/uname ixr, 90 | /{,usr/}bin/uniq ixr, 91 | /{,usr/}bin/unlink ixr, 92 | /{,usr/}bin/unxz ixr, 93 | /{,usr/}bin/unzip ixr, 94 | /{,usr/}bin/vdir ixr, 95 | /{,usr/}bin/wc ixr, 96 | /{,usr/}bin/which ixr, 97 | /{,usr/}bin/xz ixr, 98 | /{,usr/}bin/yes ixr, 99 | /{,usr/}bin/zcat ixr, 100 | /{,usr/}bin/z{,e,f}grep ixr, 101 | /{,usr/}bin/zip ixr, 102 | /{,usr/}bin/zipgrep ixr, 103 | 104 | # uptime 105 | /{,usr/}bin/uptime ixr, 106 | @{PROC}/uptime r, 107 | @{PROC}/loadavg r, 108 | # this is an information leak 109 | deny /{,var/}run/utmp r, 110 | 111 | # Miscellaneous accesses 112 | /etc/mime.types r, 113 | @{PROC}/sys/kernel/hostname r, 114 | @{PROC}/sys/kernel/osrelease r, 115 | 116 | # Read-only for the install directory 117 | @{CLICK_DIR}/@{APP_PKGNAME}/ r, 118 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/ r, 119 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/** mrklix, 120 | 121 | # Read-only home area for other versions 122 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ r, 123 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ r, 124 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** mrkix, 125 | 126 | # Writable home area for this version. 127 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 128 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 129 | 130 | # Read-only system area for other versions 131 | /var/lib/apps/@{APP_PKGNAME}/ r, 132 | /var/lib/apps/@{APP_PKGNAME}/** mrkix, 133 | 134 | # TODO: the write on these is needed in case they doesn't exist, but means an 135 | # app could adjust inode data and affect rollbacks. 136 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ w, 137 | /var/lib/apps/@{APP_PKGNAME}/ w, 138 | 139 | # Writable system area only for this version 140 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 141 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 142 | 143 | # Writable temp area only for this version (launcher will create this 144 | # directory on our behalf so only allow readonly on parent) 145 | /tmp/snapps/@{APP_PKGNAME}/ r, 146 | /tmp/snapps/@{APP_PKGNAME}/** rk, 147 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/ rw, 148 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/** mrwlkix, 149 | 150 | # No abstractions specified 151 | 152 | # Rules specified via policy groups 153 | # Description: Can access the network 154 | # Usage: common 155 | #include 156 | #include 157 | 158 | @{PROC}/sys/net/core/somaxconn r, 159 | 160 | # We want to explicitly deny access to NetworkManager because its DBus API 161 | # gives away too much 162 | deny dbus (receive, send) 163 | bus=system 164 | path=/org/freedesktop/NetworkManager, 165 | deny dbus (receive, send) 166 | bus=system 167 | peer=(name=org.freedesktop.NetworkManager), 168 | 169 | # Do the same for ofono (LP: #1226844) 170 | deny dbus (receive, send) 171 | bus=system 172 | interface="org.ofono.Manager", 173 | 174 | # No read paths specified 175 | 176 | # No write paths specified 177 | 178 | #include 179 | 180 | # dbus 181 | /run/dbus/system_bus_socket rw, 182 | dbus (send,receive) bus=system, 183 | #dbus (bind) bus=system, 184 | 185 | # Allow binding the service and receiving traffic 186 | dbus (send) 187 | bus=system 188 | path=/org/freedesktop/DBus 189 | interface=org.freedesktop.DBus 190 | member=RequestName 191 | peer=(name=org.freedesktop.DBus), 192 | 193 | dbus (bind) 194 | bus=system 195 | name="com.devicehive.cloud", 196 | 197 | /proc/*/mounts r, 198 | 199 | capability net_admin, 200 | capability net_raw, 201 | /dev/urandom r, 202 | } 203 | -------------------------------------------------------------------------------- /build/snappy/devicehive-framework/meta/dh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devicehive/IoT-framework/b268664a3e28f7fda786dc872a83879329bbf65d/build/snappy/devicehive-framework/meta/dh.png -------------------------------------------------------------------------------- /build/snappy/devicehive-framework/meta/enocean.apparmor: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | ###VAR### 4 | 5 | ###PROFILEATTACH### (attach_disconnected) { 6 | #include 7 | #include 8 | #include 9 | 10 | # for python apps/services 11 | #include 12 | /usr/bin/python{,2,2.[0-9]*,3,3.[0-9]*} ixr, 13 | 14 | # for perl apps/services 15 | #include 16 | /usr/bin/perl{,5*} ixr, 17 | 18 | # for bash 'binaries' (do *not* use abstractions/bash) 19 | # user-specific bash files 20 | /bin/bash ixr, 21 | /bin/dash ixr, 22 | /etc/bash.bashrc r, 23 | /usr/share/terminfo/** r, 24 | /etc/inputrc r, 25 | deny @{HOME}/.inputrc r, 26 | # Common utilities for shell scripts 27 | /{,usr/}bin/{,g,m}awk ixr, 28 | /{,usr/}bin/basename ixr, 29 | /{,usr/}bin/bunzip2 ixr, 30 | /{,usr/}bin/bzcat ixr, 31 | /{,usr/}bin/bzdiff ixr, 32 | /{,usr/}bin/bzgrep ixr, 33 | /{,usr/}bin/bzip2 ixr, 34 | /{,usr/}bin/cat ixr, 35 | /{,usr/}bin/chmod ixr, 36 | /{,usr/}bin/cmp ixr, 37 | /{,usr/}bin/cp ixr, 38 | /{,usr/}bin/cpio ixr, 39 | /{,usr/}bin/cut ixr, 40 | /{,usr/}bin/date ixr, 41 | /{,usr/}bin/dd ixr, 42 | /{,usr/}bin/diff{,3} ixr, 43 | /{,usr/}bin/dir ixr, 44 | /{,usr/}bin/dirname ixr, 45 | /{,usr/}bin/echo ixr, 46 | /{,usr/}bin/{,e,f,r}grep ixr, 47 | /{,usr/}bin/env ixr, 48 | /{,usr/}bin/expr ixr, 49 | /{,usr/}bin/find ixr, 50 | /{,usr/}bin/fmt ixr, 51 | /{,usr/}bin/getopt ixr, 52 | /{,usr/}bin/false ixr, 53 | /{,usr/}bin/head ixr, 54 | /{,usr/}bin/id ixr, 55 | /{,usr/}bin/igawk ixr, 56 | /{,usr/}bin/kill ixr, 57 | /{,usr/}bin/ln ixr, 58 | /{,usr/}bin/line ixr, 59 | /{,usr/}bin/link ixr, 60 | /{,usr/}bin/ls ixr, 61 | /{,usr/}bin/md5sum ixr, 62 | /{,usr/}bin/mkdir ixr, 63 | /{,usr/}bin/mktemp ixr, 64 | /{,usr/}bin/mv ixr, 65 | /{,usr/}bin/pgrep ixr, 66 | /{,usr/}bin/printenv ixr, 67 | /{,usr/}bin/printf ixr, 68 | /{,usr/}bin/ps ixr, 69 | /{,usr/}bin/pwd ixr, 70 | /{,usr/}bin/readlink ixr, 71 | /{,usr/}bin/realpath ixr, 72 | /{,usr/}bin/rev ixr, 73 | /{,usr/}bin/rm ixr, 74 | /{,usr/}bin/rmdir ixr, 75 | /{,usr/}bin/sed ixr, 76 | /{,usr/}bin/seq ixr, 77 | /{,usr/}bin/sleep ixr, 78 | /{,usr/}bin/sort ixr, 79 | /{,usr/}bin/stat ixr, 80 | /{,usr/}bin/tac ixr, 81 | /{,usr/}bin/tail ixr, 82 | /{,usr/}bin/tar ixr, 83 | /{,usr/}bin/tee ixr, 84 | /{,usr/}bin/test ixr, 85 | /{,usr/}bin/tempfile ixr, 86 | /{,usr/}bin/touch ixr, 87 | /{,usr/}bin/tr ixr, 88 | /{,usr/}bin/true ixr, 89 | /{,usr/}bin/uname ixr, 90 | /{,usr/}bin/uniq ixr, 91 | /{,usr/}bin/unlink ixr, 92 | /{,usr/}bin/unxz ixr, 93 | /{,usr/}bin/unzip ixr, 94 | /{,usr/}bin/vdir ixr, 95 | /{,usr/}bin/wc ixr, 96 | /{,usr/}bin/which ixr, 97 | /{,usr/}bin/xz ixr, 98 | /{,usr/}bin/yes ixr, 99 | /{,usr/}bin/zcat ixr, 100 | /{,usr/}bin/z{,e,f}grep ixr, 101 | /{,usr/}bin/zip ixr, 102 | /{,usr/}bin/zipgrep ixr, 103 | 104 | # uptime 105 | /{,usr/}bin/uptime ixr, 106 | @{PROC}/uptime r, 107 | @{PROC}/loadavg r, 108 | # this is an information leak 109 | deny /{,var/}run/utmp r, 110 | 111 | # Miscellaneous accesses 112 | /etc/mime.types r, 113 | @{PROC}/sys/kernel/hostname r, 114 | @{PROC}/sys/kernel/osrelease r, 115 | 116 | # Read-only for the install directory 117 | @{CLICK_DIR}/@{APP_PKGNAME}/ r, 118 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/ r, 119 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/** mrklix, 120 | 121 | # Read-only home area for other versions 122 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ r, 123 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ r, 124 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** mrkix, 125 | 126 | # Writable home area for this version. 127 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 128 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 129 | 130 | # Read-only system area for other versions 131 | /var/lib/apps/@{APP_PKGNAME}/ r, 132 | /var/lib/apps/@{APP_PKGNAME}/** mrkix, 133 | 134 | # TODO: the write on these is needed in case they doesn't exist, but means an 135 | # app could adjust inode data and affect rollbacks. 136 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ w, 137 | /var/lib/apps/@{APP_PKGNAME}/ w, 138 | 139 | # Writable system area only for this version 140 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 141 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 142 | 143 | # Writable temp area only for this version (launcher will create this 144 | # directory on our behalf so only allow readonly on parent) 145 | /tmp/snapps/@{APP_PKGNAME}/ r, 146 | /tmp/snapps/@{APP_PKGNAME}/** rk, 147 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/ rw, 148 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/** mrwlkix, 149 | 150 | # No abstractions specified 151 | 152 | # Rules specified via policy groups 153 | # Description: Can access the network 154 | # Usage: common 155 | #include 156 | #include 157 | 158 | @{PROC}/sys/net/core/somaxconn r, 159 | 160 | # We want to explicitly deny access to NetworkManager because its DBus API 161 | # gives away too much 162 | deny dbus (receive, send) 163 | bus=system 164 | path=/org/freedesktop/NetworkManager, 165 | deny dbus (receive, send) 166 | bus=system 167 | peer=(name=org.freedesktop.NetworkManager), 168 | 169 | # Do the same for ofono (LP: #1226844) 170 | deny dbus (receive, send) 171 | bus=system 172 | interface="org.ofono.Manager", 173 | 174 | # No read paths specified 175 | 176 | # No write paths specified 177 | 178 | #include 179 | 180 | # dbus 181 | /run/dbus/system_bus_socket rw, 182 | dbus (send,receive) bus=system, 183 | #dbus (bind) bus=system, 184 | 185 | # Allow binding the service and receiving traffic 186 | dbus (send) 187 | bus=system 188 | path=/org/freedesktop/DBus 189 | interface=org.freedesktop.DBus 190 | member=RequestName 191 | peer=(name=org.freedesktop.DBus), 192 | 193 | dbus (bind) 194 | bus=system 195 | name="com.devicehive.enocean", 196 | 197 | 198 | 199 | /proc/*/mounts r, 200 | 201 | # ttyUSB 202 | /dev/ttyUSB* rw, 203 | /var/lock/** rw, 204 | /run/lock/** rw, 205 | 206 | capability dac_override, 207 | capability dac_read_search, 208 | } 209 | -------------------------------------------------------------------------------- /build/snappy/devicehive-framework/meta/framework-policy/apparmor/policygroups/client: -------------------------------------------------------------------------------- 1 | # Description: allow using devicehive-cloud 2 | # Usage: common 3 | 4 | #include 5 | 6 | /run/dbus/system_bus_socket rw, 7 | dbus (receive, send) 8 | bus=system 9 | path=com/devicehive/bluetooth 10 | interface=com.devicehive.bluetooth,org.freedesktop.DBus.Introspectable, 11 | peer=(label=devicehive_ble-service_*), 12 | 13 | /run/dbus/system_bus_socket rw, 14 | dbus (send,receive) 15 | bus=system 16 | path=com/devicehive/cloud 17 | peer=(label=devicehive_cloud-service_*), 18 | 19 | /run/dbus/system_bus_socket rw, 20 | dbus (send,receive) 21 | bus=system 22 | path=com/devicehive/enocean 23 | peer=(label=devicehive_enocean-service_*), 24 | 25 | /run/dbus/system_bus_socket rw, 26 | dbus (send,receive) 27 | bus=system 28 | path=com/devicehive/gpio 29 | peer=(label=devicehive_gpio-service_*), 30 | -------------------------------------------------------------------------------- /build/snappy/devicehive-framework/meta/gpio.apparmor: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | ###VAR### 4 | 5 | ###PROFILEATTACH### (attach_disconnected) { 6 | #include 7 | #include 8 | #include 9 | 10 | # for python apps/services 11 | #include 12 | /usr/bin/python{,2,2.[0-9]*,3,3.[0-9]*} ixr, 13 | 14 | # for perl apps/services 15 | #include 16 | /usr/bin/perl{,5*} ixr, 17 | 18 | # for bash 'binaries' (do *not* use abstractions/bash) 19 | # user-specific bash files 20 | /bin/bash ixr, 21 | /bin/dash ixr, 22 | /etc/bash.bashrc r, 23 | /usr/share/terminfo/** r, 24 | /etc/inputrc r, 25 | deny @{HOME}/.inputrc r, 26 | # Common utilities for shell scripts 27 | /{,usr/}bin/{,g,m}awk ixr, 28 | /{,usr/}bin/basename ixr, 29 | /{,usr/}bin/bunzip2 ixr, 30 | /{,usr/}bin/bzcat ixr, 31 | /{,usr/}bin/bzdiff ixr, 32 | /{,usr/}bin/bzgrep ixr, 33 | /{,usr/}bin/bzip2 ixr, 34 | /{,usr/}bin/cat ixr, 35 | /{,usr/}bin/chmod ixr, 36 | /{,usr/}bin/cmp ixr, 37 | /{,usr/}bin/cp ixr, 38 | /{,usr/}bin/cpio ixr, 39 | /{,usr/}bin/cut ixr, 40 | /{,usr/}bin/date ixr, 41 | /{,usr/}bin/dd ixr, 42 | /{,usr/}bin/diff{,3} ixr, 43 | /{,usr/}bin/dir ixr, 44 | /{,usr/}bin/dirname ixr, 45 | /{,usr/}bin/echo ixr, 46 | /{,usr/}bin/{,e,f,r}grep ixr, 47 | /{,usr/}bin/env ixr, 48 | /{,usr/}bin/expr ixr, 49 | /{,usr/}bin/find ixr, 50 | /{,usr/}bin/fmt ixr, 51 | /{,usr/}bin/getopt ixr, 52 | /{,usr/}bin/false ixr, 53 | /{,usr/}bin/head ixr, 54 | /{,usr/}bin/id ixr, 55 | /{,usr/}bin/igawk ixr, 56 | /{,usr/}bin/kill ixr, 57 | /{,usr/}bin/ln ixr, 58 | /{,usr/}bin/line ixr, 59 | /{,usr/}bin/link ixr, 60 | /{,usr/}bin/ls ixr, 61 | /{,usr/}bin/md5sum ixr, 62 | /{,usr/}bin/mkdir ixr, 63 | /{,usr/}bin/mktemp ixr, 64 | /{,usr/}bin/mv ixr, 65 | /{,usr/}bin/pgrep ixr, 66 | /{,usr/}bin/printenv ixr, 67 | /{,usr/}bin/printf ixr, 68 | /{,usr/}bin/ps ixr, 69 | /{,usr/}bin/pwd ixr, 70 | /{,usr/}bin/readlink ixr, 71 | /{,usr/}bin/realpath ixr, 72 | /{,usr/}bin/rev ixr, 73 | /{,usr/}bin/rm ixr, 74 | /{,usr/}bin/rmdir ixr, 75 | /{,usr/}bin/sed ixr, 76 | /{,usr/}bin/seq ixr, 77 | /{,usr/}bin/sleep ixr, 78 | /{,usr/}bin/sort ixr, 79 | /{,usr/}bin/stat ixr, 80 | /{,usr/}bin/tac ixr, 81 | /{,usr/}bin/tail ixr, 82 | /{,usr/}bin/tar ixr, 83 | /{,usr/}bin/tee ixr, 84 | /{,usr/}bin/test ixr, 85 | /{,usr/}bin/tempfile ixr, 86 | /{,usr/}bin/touch ixr, 87 | /{,usr/}bin/tr ixr, 88 | /{,usr/}bin/true ixr, 89 | /{,usr/}bin/uname ixr, 90 | /{,usr/}bin/uniq ixr, 91 | /{,usr/}bin/unlink ixr, 92 | /{,usr/}bin/unxz ixr, 93 | /{,usr/}bin/unzip ixr, 94 | /{,usr/}bin/vdir ixr, 95 | /{,usr/}bin/wc ixr, 96 | /{,usr/}bin/which ixr, 97 | /{,usr/}bin/xz ixr, 98 | /{,usr/}bin/yes ixr, 99 | /{,usr/}bin/zcat ixr, 100 | /{,usr/}bin/z{,e,f}grep ixr, 101 | /{,usr/}bin/zip ixr, 102 | /{,usr/}bin/zipgrep ixr, 103 | 104 | # uptime 105 | /{,usr/}bin/uptime ixr, 106 | @{PROC}/uptime r, 107 | @{PROC}/loadavg r, 108 | # this is an information leak 109 | deny /{,var/}run/utmp r, 110 | 111 | # Miscellaneous accesses 112 | /etc/mime.types r, 113 | @{PROC}/sys/kernel/hostname r, 114 | @{PROC}/sys/kernel/osrelease r, 115 | 116 | # Read-only for the install directory 117 | @{CLICK_DIR}/@{APP_PKGNAME}/ r, 118 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/ r, 119 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/** mrklix, 120 | 121 | # Read-only home area for other versions 122 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ r, 123 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ r, 124 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** mrkix, 125 | 126 | # Writable home area for this version. 127 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 128 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 129 | 130 | # Read-only system area for other versions 131 | /var/lib/apps/@{APP_PKGNAME}/ r, 132 | /var/lib/apps/@{APP_PKGNAME}/** mrkix, 133 | 134 | # TODO: the write on these is needed in case they doesn't exist, but means an 135 | # app could adjust inode data and affect rollbacks. 136 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ w, 137 | /var/lib/apps/@{APP_PKGNAME}/ w, 138 | 139 | # Writable system area only for this version 140 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 141 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 142 | 143 | # Writable temp area only for this version (launcher will create this 144 | # directory on our behalf so only allow readonly on parent) 145 | /tmp/snapps/@{APP_PKGNAME}/ r, 146 | /tmp/snapps/@{APP_PKGNAME}/** rk, 147 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/ rw, 148 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/** mrwlkix, 149 | 150 | # No abstractions specified 151 | 152 | # Rules specified via policy groups 153 | # Description: Can access the network 154 | # Usage: common 155 | #include 156 | #include 157 | 158 | @{PROC}/sys/net/core/somaxconn r, 159 | 160 | # We want to explicitly deny access to NetworkManager because its DBus API 161 | # gives away too much 162 | deny dbus (receive, send) 163 | bus=system 164 | path=/org/freedesktop/NetworkManager, 165 | deny dbus (receive, send) 166 | bus=system 167 | peer=(name=org.freedesktop.NetworkManager), 168 | 169 | # Do the same for ofono (LP: #1226844) 170 | deny dbus (receive, send) 171 | bus=system 172 | interface="org.ofono.Manager", 173 | 174 | # No read paths specified 175 | 176 | # No write paths specified 177 | 178 | #include 179 | 180 | # dbus 181 | /run/dbus/system_bus_socket rw, 182 | dbus (send,receive) bus=system, 183 | #dbus (bind) bus=system, 184 | 185 | # Allow binding the service and receiving traffic 186 | dbus (send) 187 | bus=system 188 | path=/org/freedesktop/DBus 189 | interface=org.freedesktop.DBus 190 | member=RequestName 191 | peer=(name=org.freedesktop.DBus), 192 | 193 | dbus (bind) 194 | bus=system 195 | name="com.devicehive.gpio", 196 | 197 | 198 | 199 | /proc/*/mounts r, 200 | 201 | # gpio access 202 | /sys/class/gpio/** rw, 203 | /sys/devices/ocp/** rw, 204 | /sys/devices/platform/soc/** rw, 205 | 206 | # info 207 | /sys/firmware/devicetree/base/model r, 208 | 209 | # read apps profiles 210 | /apps/** r, 211 | } 212 | -------------------------------------------------------------------------------- /build/snappy/devicehive-framework/meta/hooks/config: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | SNAPP_APP_PATH=$(realpath $(dirname $0)/../../) 3 | SNAPP_APP_DATA_PATH=/var/lib$SNAPP_APP_PATH 4 | cat /dev/stdin > $SNAPP_APP_DATA_PATH/config.yaml 5 | -------------------------------------------------------------------------------- /build/snappy/devicehive-framework/meta/package.yaml: -------------------------------------------------------------------------------- 1 | name: devicehive-iot-toolkit 2 | version: 1.0.0 3 | type: framework 4 | vendor: DataArt 5 | icon: meta/dh.png 6 | architecture: [amd64, armhf] 7 | services: 8 | - name: enocean-service 9 | description: "DeviceHive Enocean Service" 10 | start: bin/enocean-service 11 | bus-name: "com.devicehive.enocean" 12 | security-policy: 13 | apparmor: meta/enocean.apparmor 14 | - name: gpio-service 15 | description: "DeviceHive GPIO Service" 16 | start: bin/gpio-service 17 | bus-name: "com.devicehive.gpio" 18 | security-policy: 19 | apparmor: meta/gpio.apparmor 20 | - name: ble-service 21 | description: "DeviceHive BLE Service" 22 | bus-name: "com.devicehive.bluetooth" 23 | start: bin/ble-service 24 | security-policy: 25 | apparmor: meta/ble.apparmor 26 | - name: cloud-service 27 | description: "DeviceHive Cloud Gateway" 28 | bus-name: "com.devicehive.cloud" 29 | start: bin/cloud-service 30 | security-policy: 31 | apparmor: meta/cloud.apparmor 32 | -------------------------------------------------------------------------------- /build/snappy/devicehive-framework/meta/readme.md: -------------------------------------------------------------------------------- 1 | DeviceHive Framework 2 | 3 | Modules: 4 | - DeviceHive Cloud 5 | - Bluetooth Low Energy 6 | - EnOcean 7 | - GPIO 8 | 9 | Run "config" hook after install -------------------------------------------------------------------------------- /build/snappy/devicehive-iot-demo/bin/service: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | SNAPP_APP_PATH=$(realpath $(dirname $0)/../) 6 | SNAPP_APP_DATA_PATH=/var/lib$SNAPP_APP_PATH 7 | 8 | # map platform 9 | PLATFORM= 10 | case $(uname -i) in 11 | x86_64) 12 | PLATFORM=x86_64 13 | ;; 14 | armv7l) 15 | PLATFORM=armhf 16 | ;; 17 | *) 18 | echo "Unknown platform" 19 | exit 1 20 | ;; 21 | esac 22 | 23 | # set enviroment 24 | export LD_LIBRARY_PATH="$SNAPP_APP_PATH/lib/$PLATFORM/:$LD_LIBRARY_PATH" 25 | export PATH="$SNAPP_APP_PATH/bin/$PLATFORM/:$PATH" 26 | mkdir -p $SNAPP_APP_DATA_PATH # system create this folder only after service has started for the first time 27 | 28 | # run 29 | $SNAPP_APP_PATH/bin/$PLATFORM/devicehive-iot-demo 30 | -------------------------------------------------------------------------------- /build/snappy/devicehive-iot-demo/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$(dirname "$(readlink -f "$0")")" 4 | 5 | go get github.com/montanaflynn/stats 6 | go get github.com/godbus/dbus 7 | GOOS=linux go build -o $DIR/bin/x86_64/devicehive-iot-demo $DIR/../../../examples/iot-demo.go 8 | GOOS=linux GOARCH=arm GOARM=7 go build -o $DIR/bin/armhf/devicehive-iot-demo $DIR/../../../examples/iot-demo.go 9 | -------------------------------------------------------------------------------- /build/snappy/devicehive-iot-demo/meta/devicehive.apparmor: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | ###VAR### 4 | 5 | ###PROFILEATTACH### (attach_disconnected) { 6 | #include 7 | #include 8 | #include 9 | 10 | # for python apps/services 11 | #include 12 | /usr/bin/python{,2,2.[0-9]*,3,3.[0-9]*} ixr, 13 | 14 | # for perl apps/services 15 | #include 16 | /usr/bin/perl{,5*} ixr, 17 | 18 | # for bash 'binaries' (do *not* use abstractions/bash) 19 | # user-specific bash files 20 | /bin/bash ixr, 21 | /bin/dash ixr, 22 | /etc/bash.bashrc r, 23 | /usr/share/terminfo/** r, 24 | /etc/inputrc r, 25 | deny @{HOME}/.inputrc r, 26 | # Common utilities for shell scripts 27 | /{,usr/}bin/{,g,m}awk ixr, 28 | /{,usr/}bin/basename ixr, 29 | /{,usr/}bin/bunzip2 ixr, 30 | /{,usr/}bin/bzcat ixr, 31 | /{,usr/}bin/bzdiff ixr, 32 | /{,usr/}bin/bzgrep ixr, 33 | /{,usr/}bin/bzip2 ixr, 34 | /{,usr/}bin/cat ixr, 35 | /{,usr/}bin/chmod ixr, 36 | /{,usr/}bin/cmp ixr, 37 | /{,usr/}bin/cp ixr, 38 | /{,usr/}bin/cpio ixr, 39 | /{,usr/}bin/cut ixr, 40 | /{,usr/}bin/date ixr, 41 | /{,usr/}bin/dd ixr, 42 | /{,usr/}bin/diff{,3} ixr, 43 | /{,usr/}bin/dir ixr, 44 | /{,usr/}bin/dirname ixr, 45 | /{,usr/}bin/echo ixr, 46 | /{,usr/}bin/{,e,f,r}grep ixr, 47 | /{,usr/}bin/env ixr, 48 | /{,usr/}bin/expr ixr, 49 | /{,usr/}bin/find ixr, 50 | /{,usr/}bin/fmt ixr, 51 | /{,usr/}bin/getopt ixr, 52 | /{,usr/}bin/false ixr, 53 | /{,usr/}bin/head ixr, 54 | /{,usr/}bin/id ixr, 55 | /{,usr/}bin/igawk ixr, 56 | /{,usr/}bin/kill ixr, 57 | /{,usr/}bin/ln ixr, 58 | /{,usr/}bin/line ixr, 59 | /{,usr/}bin/link ixr, 60 | /{,usr/}bin/ls ixr, 61 | /{,usr/}bin/md5sum ixr, 62 | /{,usr/}bin/mkdir ixr, 63 | /{,usr/}bin/mktemp ixr, 64 | /{,usr/}bin/mv ixr, 65 | /{,usr/}bin/pgrep ixr, 66 | /{,usr/}bin/printenv ixr, 67 | /{,usr/}bin/printf ixr, 68 | /{,usr/}bin/ps ixr, 69 | /{,usr/}bin/pwd ixr, 70 | /{,usr/}bin/readlink ixr, 71 | /{,usr/}bin/realpath ixr, 72 | /{,usr/}bin/rev ixr, 73 | /{,usr/}bin/rm ixr, 74 | /{,usr/}bin/rmdir ixr, 75 | /{,usr/}bin/sed ixr, 76 | /{,usr/}bin/seq ixr, 77 | /{,usr/}bin/sleep ixr, 78 | /{,usr/}bin/sort ixr, 79 | /{,usr/}bin/stat ixr, 80 | /{,usr/}bin/tac ixr, 81 | /{,usr/}bin/tail ixr, 82 | /{,usr/}bin/tar ixr, 83 | /{,usr/}bin/tee ixr, 84 | /{,usr/}bin/test ixr, 85 | /{,usr/}bin/tempfile ixr, 86 | /{,usr/}bin/touch ixr, 87 | /{,usr/}bin/tr ixr, 88 | /{,usr/}bin/true ixr, 89 | /{,usr/}bin/uname ixr, 90 | /{,usr/}bin/uniq ixr, 91 | /{,usr/}bin/unlink ixr, 92 | /{,usr/}bin/unxz ixr, 93 | /{,usr/}bin/unzip ixr, 94 | /{,usr/}bin/vdir ixr, 95 | /{,usr/}bin/wc ixr, 96 | /{,usr/}bin/which ixr, 97 | /{,usr/}bin/xz ixr, 98 | /{,usr/}bin/yes ixr, 99 | /{,usr/}bin/zcat ixr, 100 | /{,usr/}bin/z{,e,f}grep ixr, 101 | /{,usr/}bin/zip ixr, 102 | /{,usr/}bin/zipgrep ixr, 103 | 104 | # uptime 105 | /{,usr/}bin/uptime ixr, 106 | @{PROC}/uptime r, 107 | @{PROC}/loadavg r, 108 | @{PROC}/stat r, 109 | # this is an information leak 110 | deny /{,var/}run/utmp r, 111 | 112 | # Miscellaneous accesses 113 | /etc/mime.types r, 114 | @{PROC}/sys/kernel/hostname r, 115 | @{PROC}/sys/kernel/osrelease r, 116 | 117 | # Read-only for the install directory 118 | @{CLICK_DIR}/@{APP_PKGNAME}/ r, 119 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/ r, 120 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/** mrklix, 121 | 122 | # Read-only home area for other versions 123 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ r, 124 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ r, 125 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** mrkix, 126 | 127 | # Writable home area for this version. 128 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 129 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 130 | 131 | # Read-only system area for other versions 132 | /var/lib/apps/@{APP_PKGNAME}/ r, 133 | /var/lib/apps/@{APP_PKGNAME}/** mrkix, 134 | 135 | # TODO: the write on these is needed in case they doesn't exist, but means an 136 | # app could adjust inode data and affect rollbacks. 137 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ w, 138 | /var/lib/apps/@{APP_PKGNAME}/ w, 139 | 140 | # Writable system area only for this version 141 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 142 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 143 | 144 | # Writable temp area only for this version (launcher will create this 145 | # directory on our behalf so only allow readonly on parent) 146 | /tmp/snapps/@{APP_PKGNAME}/ r, 147 | /tmp/snapps/@{APP_PKGNAME}/** rk, 148 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/ rw, 149 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/** mrwlkix, 150 | 151 | # No abstractions specified 152 | 153 | # Rules specified via policy groups 154 | # Description: Can access the network 155 | # Usage: common 156 | #include 157 | #include 158 | 159 | @{PROC}/sys/net/core/somaxconn r, 160 | 161 | # We want to explicitly deny access to NetworkManager because its DBus API 162 | # gives away too much 163 | deny dbus (receive, send) 164 | bus=system 165 | path=/org/freedesktop/NetworkManager, 166 | deny dbus (receive, send) 167 | bus=system 168 | peer=(name=org.freedesktop.NetworkManager), 169 | 170 | # Do the same for ofono (LP: #1226844) 171 | deny dbus (receive, send) 172 | bus=system 173 | interface="org.ofono.Manager", 174 | 175 | # No read paths specified 176 | 177 | # No write paths specified 178 | 179 | # dbus 180 | #include 181 | 182 | /run/dbus/system_bus_socket rw, 183 | dbus (send,receive) bus=system, 184 | #dbus (bind) bus=system, 185 | 186 | 187 | /proc/*/mounts r, 188 | 189 | # bluetooth 190 | network bluetooth raw, 191 | network bluetooth seqpacket, 192 | capability net_admin, 193 | capability net_raw, 194 | } 195 | -------------------------------------------------------------------------------- /build/snappy/devicehive-iot-demo/meta/dh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devicehive/IoT-framework/b268664a3e28f7fda786dc872a83879329bbf65d/build/snappy/devicehive-iot-demo/meta/dh.png -------------------------------------------------------------------------------- /build/snappy/devicehive-iot-demo/meta/package.yaml: -------------------------------------------------------------------------------- 1 | name: devicehive-iot-demo 2 | version: 1.0.1 3 | type: app 4 | vendor: Artyom Astafurov 5 | icon: meta/dh.png 6 | architecture: [amd64, armhf] 7 | services: 8 | - name: service 9 | description: "Combine various frameworks in one demo: BLE Cloud EnOcean" 10 | start: bin/service 11 | security-policy: 12 | apparmor: meta/devicehive.apparmor 13 | -------------------------------------------------------------------------------- /build/snappy/devicehive-iot-demo/meta/readme.md: -------------------------------------------------------------------------------- 1 | DeviceHive BLE Gateway 2 | 3 | BLE Gateway for DeviceHive. 4 | -------------------------------------------------------------------------------- /build/snappy/readme.md: -------------------------------------------------------------------------------- 1 | ## IoT Framework build system for Ubuntu Snappy 2 | 3 | Run 4 | ```bash 5 | build-framework.sh 6 | ``` 7 | to create `devicehive-iot-toolkit_1.0.0_multi.snap` file. This snap contains all frameworks and will start all services automatically after installation. Upload snap to Snappy machine and run `snappy install` or just use `snappy-remote` for install. 8 | 9 | You can also run 10 | ```bash 11 | build-apps.sh 12 | ``` 13 | to create few demo snap that using our IoT framework 14 | 15 | There are a few environment variables you can customize: 16 | - `PLATFORM` could be `x86_64` or `armhf` 17 | - `VARIANT` could be `debug` or `release` 18 | 19 | For example: 20 | ```bash 21 | VARIANT=debug build-alljoyn.sh 22 | ``` 23 | 24 | -------------------------------------------------------------------------------- /build/snappy/sensortag-cloud-demo/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$(dirname "$(readlink -f "$0")")" 4 | 5 | mkdir -p $DIR/bin 6 | cp $DIR/../../../examples/sensortag-cloud.py $DIR/bin 7 | 8 | -------------------------------------------------------------------------------- /build/snappy/sensortag-cloud-demo/meta/devicehive.apparmor: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | ###VAR### 4 | 5 | ###PROFILEATTACH### (attach_disconnected) { 6 | #include 7 | #include 8 | #include 9 | 10 | # for python apps/services 11 | #include 12 | /usr/bin/python{,2,2.[0-9]*,3,3.[0-9]*} ixr, 13 | 14 | # for perl apps/services 15 | #include 16 | /usr/bin/perl{,5*} ixr, 17 | 18 | # for bash 'binaries' (do *not* use abstractions/bash) 19 | # user-specific bash files 20 | /bin/bash ixr, 21 | /bin/dash ixr, 22 | /etc/bash.bashrc r, 23 | /usr/share/terminfo/** r, 24 | /etc/inputrc r, 25 | deny @{HOME}/.inputrc r, 26 | # Common utilities for shell scripts 27 | /{,usr/}bin/{,g,m}awk ixr, 28 | /{,usr/}bin/basename ixr, 29 | /{,usr/}bin/bunzip2 ixr, 30 | /{,usr/}bin/bzcat ixr, 31 | /{,usr/}bin/bzdiff ixr, 32 | /{,usr/}bin/bzgrep ixr, 33 | /{,usr/}bin/bzip2 ixr, 34 | /{,usr/}bin/cat ixr, 35 | /{,usr/}bin/chmod ixr, 36 | /{,usr/}bin/cmp ixr, 37 | /{,usr/}bin/cp ixr, 38 | /{,usr/}bin/cpio ixr, 39 | /{,usr/}bin/cut ixr, 40 | /{,usr/}bin/date ixr, 41 | /{,usr/}bin/dd ixr, 42 | /{,usr/}bin/diff{,3} ixr, 43 | /{,usr/}bin/dir ixr, 44 | /{,usr/}bin/dirname ixr, 45 | /{,usr/}bin/echo ixr, 46 | /{,usr/}bin/{,e,f,r}grep ixr, 47 | /{,usr/}bin/env ixr, 48 | /{,usr/}bin/expr ixr, 49 | /{,usr/}bin/find ixr, 50 | /{,usr/}bin/fmt ixr, 51 | /{,usr/}bin/getopt ixr, 52 | /{,usr/}bin/false ixr, 53 | /{,usr/}bin/head ixr, 54 | /{,usr/}bin/id ixr, 55 | /{,usr/}bin/igawk ixr, 56 | /{,usr/}bin/kill ixr, 57 | /{,usr/}bin/ln ixr, 58 | /{,usr/}bin/line ixr, 59 | /{,usr/}bin/link ixr, 60 | /{,usr/}bin/ls ixr, 61 | /{,usr/}bin/md5sum ixr, 62 | /{,usr/}bin/mkdir ixr, 63 | /{,usr/}bin/mktemp ixr, 64 | /{,usr/}bin/mv ixr, 65 | /{,usr/}bin/pgrep ixr, 66 | /{,usr/}bin/printenv ixr, 67 | /{,usr/}bin/printf ixr, 68 | /{,usr/}bin/ps ixr, 69 | /{,usr/}bin/pwd ixr, 70 | /{,usr/}bin/readlink ixr, 71 | /{,usr/}bin/realpath ixr, 72 | /{,usr/}bin/rev ixr, 73 | /{,usr/}bin/rm ixr, 74 | /{,usr/}bin/rmdir ixr, 75 | /{,usr/}bin/sed ixr, 76 | /{,usr/}bin/seq ixr, 77 | /{,usr/}bin/sleep ixr, 78 | /{,usr/}bin/sort ixr, 79 | /{,usr/}bin/stat ixr, 80 | /{,usr/}bin/tac ixr, 81 | /{,usr/}bin/tail ixr, 82 | /{,usr/}bin/tar ixr, 83 | /{,usr/}bin/tee ixr, 84 | /{,usr/}bin/test ixr, 85 | /{,usr/}bin/tempfile ixr, 86 | /{,usr/}bin/touch ixr, 87 | /{,usr/}bin/tr ixr, 88 | /{,usr/}bin/true ixr, 89 | /{,usr/}bin/uname ixr, 90 | /{,usr/}bin/uniq ixr, 91 | /{,usr/}bin/unlink ixr, 92 | /{,usr/}bin/unxz ixr, 93 | /{,usr/}bin/unzip ixr, 94 | /{,usr/}bin/vdir ixr, 95 | /{,usr/}bin/wc ixr, 96 | /{,usr/}bin/which ixr, 97 | /{,usr/}bin/xz ixr, 98 | /{,usr/}bin/yes ixr, 99 | /{,usr/}bin/zcat ixr, 100 | /{,usr/}bin/z{,e,f}grep ixr, 101 | /{,usr/}bin/zip ixr, 102 | /{,usr/}bin/zipgrep ixr, 103 | 104 | # uptime 105 | /{,usr/}bin/uptime ixr, 106 | @{PROC}/uptime r, 107 | @{PROC}/loadavg r, 108 | @{PROC}/stat r, 109 | # this is an information leak 110 | deny /{,var/}run/utmp r, 111 | 112 | # Miscellaneous accesses 113 | /etc/mime.types r, 114 | @{PROC}/sys/kernel/hostname r, 115 | @{PROC}/sys/kernel/osrelease r, 116 | 117 | # Read-only for the install directory 118 | @{CLICK_DIR}/@{APP_PKGNAME}/ r, 119 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/ r, 120 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/** mrklix, 121 | 122 | # Read-only home area for other versions 123 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ r, 124 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ r, 125 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** mrkix, 126 | 127 | # Writable home area for this version. 128 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 129 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 130 | 131 | # Read-only system area for other versions 132 | /var/lib/apps/@{APP_PKGNAME}/ r, 133 | /var/lib/apps/@{APP_PKGNAME}/** mrkix, 134 | 135 | # TODO: the write on these is needed in case they doesn't exist, but means an 136 | # app could adjust inode data and affect rollbacks. 137 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ w, 138 | /var/lib/apps/@{APP_PKGNAME}/ w, 139 | 140 | # Writable system area only for this version 141 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 142 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 143 | 144 | # Writable temp area only for this version (launcher will create this 145 | # directory on our behalf so only allow readonly on parent) 146 | /tmp/snapps/@{APP_PKGNAME}/ r, 147 | /tmp/snapps/@{APP_PKGNAME}/** rk, 148 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/ rw, 149 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/** mrwlkix, 150 | 151 | # No abstractions specified 152 | 153 | # Rules specified via policy groups 154 | # Description: Can access the network 155 | # Usage: common 156 | #include 157 | #include 158 | 159 | @{PROC}/sys/net/core/somaxconn r, 160 | 161 | # We want to explicitly deny access to NetworkManager because its DBus API 162 | # gives away too much 163 | deny dbus (receive, send) 164 | bus=system 165 | path=/org/freedesktop/NetworkManager, 166 | deny dbus (receive, send) 167 | bus=system 168 | peer=(name=org.freedesktop.NetworkManager), 169 | 170 | # Do the same for ofono (LP: #1226844) 171 | deny dbus (receive, send) 172 | bus=system 173 | interface="org.ofono.Manager", 174 | 175 | # No read paths specified 176 | 177 | # No write paths specified 178 | 179 | # dbus 180 | #include 181 | 182 | /run/dbus/system_bus_socket rw, 183 | dbus (send,receive) bus=system, 184 | #dbus (bind) bus=system, 185 | 186 | 187 | /proc/*/mounts r, 188 | 189 | # bluetooth 190 | network bluetooth raw, 191 | network bluetooth seqpacket, 192 | capability net_admin, 193 | capability net_raw, 194 | } 195 | -------------------------------------------------------------------------------- /build/snappy/sensortag-cloud-demo/meta/dh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devicehive/IoT-framework/b268664a3e28f7fda786dc872a83879329bbf65d/build/snappy/sensortag-cloud-demo/meta/dh.png -------------------------------------------------------------------------------- /build/snappy/sensortag-cloud-demo/meta/package.yaml: -------------------------------------------------------------------------------- 1 | name: sensortag-cloud-demo 2 | version: 1.0.0 3 | type: app 4 | vendor: DataArt 5 | icon: meta/dh.png 6 | architecture: [amd64, armhf] 7 | frameworks: 8 | - devicehive-iot-toolkit 9 | services: 10 | - name: service 11 | description: "Send data from SensorTag to the cloud" 12 | start: bin/sensortag-cloud.py 13 | security-policy: 14 | apparmor: meta/devicehive.apparmor 15 | -------------------------------------------------------------------------------- /build/snappy/sensortag-cloud-demo/meta/readme.md: -------------------------------------------------------------------------------- 1 | DeviceHive SensorTag to Cloud demo 2 | 3 | Send data from SensorTag to Cloud. 4 | -------------------------------------------------------------------------------- /build/snappy/snappy-clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PACKAGE=${1} 4 | FLAGS=-fv #-i # "-i" is used for interactive confirmation 5 | 6 | if [ "x${PACKAGE}x" = "xx" ]; then 7 | echo "No package name provided!" 8 | echo "Usage: $0 " 9 | exit 1 10 | fi 11 | 12 | while true; do 13 | read -p "Do you really want to clean '$PACKAGE' package [y/n]?" yn 14 | case $yn in 15 | [Yy]* ) 16 | break 17 | ;; 18 | [Nn]* ) 19 | exit 1 20 | ;; 21 | * ) 22 | echo "Please answer Yes or No." 23 | ;; 24 | esac 25 | done 26 | 27 | sudo rm ${FLAGS} /etc/systemd/system/${PACKAGE}_*.service 28 | sudo rm ${FLAGS} /etc/systemd/system/multi-user.target.wants/${PACKAGE}_*.service 29 | sudo rm ${FLAGS} /var/lib/snappy/*/*/${PACKAGE}_* 30 | sudo rm ${FLAGS} /etc/dbus-1/system.d/${PACKAGE}_*.conf 31 | -------------------------------------------------------------------------------- /build/snappy/sysmon/bin/service: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | SNAPP_APP_PATH=$(realpath $(dirname $0)/../) 6 | SNAPP_APP_DATA_PATH=/var/lib$SNAPP_APP_PATH 7 | 8 | # map platform 9 | PLATFORM= 10 | case $(uname -i) in 11 | x86_64) 12 | PLATFORM=x86_64 13 | ;; 14 | armv7l) 15 | PLATFORM=armhf 16 | ;; 17 | *) 18 | echo "Unknown platform" 19 | exit 1 20 | ;; 21 | esac 22 | 23 | # set enviroment 24 | export LD_LIBRARY_PATH="$SNAPP_APP_PATH/lib/$PLATFORM/:$LD_LIBRARY_PATH" 25 | export PATH="$SNAPP_APP_PATH/bin/$PLATFORM/:$PATH" 26 | mkdir -p $SNAPP_APP_DATA_PATH # system create this folder only after service has started for the first time 27 | 28 | # run 29 | $SNAPP_APP_PATH/bin/$PLATFORM/sysmon 30 | -------------------------------------------------------------------------------- /build/snappy/sysmon/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$(dirname "$(readlink -f "$0")")" 4 | 5 | go get github.com/shirou/gopsutil/cpu 6 | go get github.com/godbus/dbus 7 | GOOS=linux go build -o $DIR/bin/x86_64/sysmon $DIR/../../../examples/cpu-stats/cpu-stats.go 8 | GOOS=linux GOARCH=arm GOARM=7 go build -o $DIR/bin/armhf/sysmon $DIR/../../../examples/cpu-stats/cpu-stats.go 9 | -------------------------------------------------------------------------------- /build/snappy/sysmon/meta/devicehive.apparmor: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | ###VAR### 4 | 5 | ###PROFILEATTACH### (attach_disconnected) { 6 | #include 7 | #include 8 | #include 9 | 10 | # for python apps/services 11 | #include 12 | /usr/bin/python{,2,2.[0-9]*,3,3.[0-9]*} ixr, 13 | 14 | # for perl apps/services 15 | #include 16 | /usr/bin/perl{,5*} ixr, 17 | 18 | # for bash 'binaries' (do *not* use abstractions/bash) 19 | # user-specific bash files 20 | /bin/bash ixr, 21 | /bin/dash ixr, 22 | /etc/bash.bashrc r, 23 | /usr/share/terminfo/** r, 24 | /etc/inputrc r, 25 | deny @{HOME}/.inputrc r, 26 | # Common utilities for shell scripts 27 | /{,usr/}bin/{,g,m}awk ixr, 28 | /{,usr/}bin/basename ixr, 29 | /{,usr/}bin/bunzip2 ixr, 30 | /{,usr/}bin/bzcat ixr, 31 | /{,usr/}bin/bzdiff ixr, 32 | /{,usr/}bin/bzgrep ixr, 33 | /{,usr/}bin/bzip2 ixr, 34 | /{,usr/}bin/cat ixr, 35 | /{,usr/}bin/chmod ixr, 36 | /{,usr/}bin/cmp ixr, 37 | /{,usr/}bin/cp ixr, 38 | /{,usr/}bin/cpio ixr, 39 | /{,usr/}bin/cut ixr, 40 | /{,usr/}bin/date ixr, 41 | /{,usr/}bin/dd ixr, 42 | /{,usr/}bin/diff{,3} ixr, 43 | /{,usr/}bin/dir ixr, 44 | /{,usr/}bin/dirname ixr, 45 | /{,usr/}bin/echo ixr, 46 | /{,usr/}bin/{,e,f,r}grep ixr, 47 | /{,usr/}bin/env ixr, 48 | /{,usr/}bin/expr ixr, 49 | /{,usr/}bin/find ixr, 50 | /{,usr/}bin/fmt ixr, 51 | /{,usr/}bin/getopt ixr, 52 | /{,usr/}bin/false ixr, 53 | /{,usr/}bin/head ixr, 54 | /{,usr/}bin/id ixr, 55 | /{,usr/}bin/igawk ixr, 56 | /{,usr/}bin/kill ixr, 57 | /{,usr/}bin/ln ixr, 58 | /{,usr/}bin/line ixr, 59 | /{,usr/}bin/link ixr, 60 | /{,usr/}bin/ls ixr, 61 | /{,usr/}bin/md5sum ixr, 62 | /{,usr/}bin/mkdir ixr, 63 | /{,usr/}bin/mktemp ixr, 64 | /{,usr/}bin/mv ixr, 65 | /{,usr/}bin/pgrep ixr, 66 | /{,usr/}bin/printenv ixr, 67 | /{,usr/}bin/printf ixr, 68 | /{,usr/}bin/ps ixr, 69 | /{,usr/}bin/pwd ixr, 70 | /{,usr/}bin/readlink ixr, 71 | /{,usr/}bin/realpath ixr, 72 | /{,usr/}bin/rev ixr, 73 | /{,usr/}bin/rm ixr, 74 | /{,usr/}bin/rmdir ixr, 75 | /{,usr/}bin/sed ixr, 76 | /{,usr/}bin/seq ixr, 77 | /{,usr/}bin/sleep ixr, 78 | /{,usr/}bin/sort ixr, 79 | /{,usr/}bin/stat ixr, 80 | /{,usr/}bin/tac ixr, 81 | /{,usr/}bin/tail ixr, 82 | /{,usr/}bin/tar ixr, 83 | /{,usr/}bin/tee ixr, 84 | /{,usr/}bin/test ixr, 85 | /{,usr/}bin/tempfile ixr, 86 | /{,usr/}bin/touch ixr, 87 | /{,usr/}bin/tr ixr, 88 | /{,usr/}bin/true ixr, 89 | /{,usr/}bin/uname ixr, 90 | /{,usr/}bin/uniq ixr, 91 | /{,usr/}bin/unlink ixr, 92 | /{,usr/}bin/unxz ixr, 93 | /{,usr/}bin/unzip ixr, 94 | /{,usr/}bin/vdir ixr, 95 | /{,usr/}bin/wc ixr, 96 | /{,usr/}bin/which ixr, 97 | /{,usr/}bin/xz ixr, 98 | /{,usr/}bin/yes ixr, 99 | /{,usr/}bin/zcat ixr, 100 | /{,usr/}bin/z{,e,f}grep ixr, 101 | /{,usr/}bin/zip ixr, 102 | /{,usr/}bin/zipgrep ixr, 103 | 104 | # uptime 105 | /{,usr/}bin/uptime ixr, 106 | @{PROC}/uptime r, 107 | @{PROC}/loadavg r, 108 | @{PROC}/stat r, 109 | # this is an information leak 110 | deny /{,var/}run/utmp r, 111 | 112 | # Miscellaneous accesses 113 | /etc/mime.types r, 114 | @{PROC}/sys/kernel/hostname r, 115 | @{PROC}/sys/kernel/osrelease r, 116 | 117 | # Read-only for the install directory 118 | @{CLICK_DIR}/@{APP_PKGNAME}/ r, 119 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/ r, 120 | @{CLICK_DIR}/@{APP_PKGNAME}/@{APP_VERSION}/** mrklix, 121 | 122 | # Read-only home area for other versions 123 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ r, 124 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ r, 125 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** mrkix, 126 | 127 | # Writable home area for this version. 128 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 129 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 130 | 131 | # Read-only system area for other versions 132 | /var/lib/apps/@{APP_PKGNAME}/ r, 133 | /var/lib/apps/@{APP_PKGNAME}/** mrkix, 134 | 135 | # TODO: the write on these is needed in case they doesn't exist, but means an 136 | # app could adjust inode data and affect rollbacks. 137 | owner @{HOMEDIRS}/*/apps/@{APP_PKGNAME}/ w, 138 | /var/lib/apps/@{APP_PKGNAME}/ w, 139 | 140 | # Writable system area only for this version 141 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/ w, 142 | /var/lib/apps/@{APP_PKGNAME}/@{APP_VERSION}/** wl, 143 | 144 | # Writable temp area only for this version (launcher will create this 145 | # directory on our behalf so only allow readonly on parent) 146 | /tmp/snapps/@{APP_PKGNAME}/ r, 147 | /tmp/snapps/@{APP_PKGNAME}/** rk, 148 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/ rw, 149 | /tmp/snapps/@{APP_PKGNAME}/@{APP_VERSION}/** mrwlkix, 150 | 151 | # No abstractions specified 152 | 153 | # Rules specified via policy groups 154 | # Description: Can access the network 155 | # Usage: common 156 | #include 157 | #include 158 | 159 | @{PROC}/sys/net/core/somaxconn r, 160 | 161 | # We want to explicitly deny access to NetworkManager because its DBus API 162 | # gives away too much 163 | deny dbus (receive, send) 164 | bus=system 165 | path=/org/freedesktop/NetworkManager, 166 | deny dbus (receive, send) 167 | bus=system 168 | peer=(name=org.freedesktop.NetworkManager), 169 | 170 | # Do the same for ofono (LP: #1226844) 171 | deny dbus (receive, send) 172 | bus=system 173 | interface="org.ofono.Manager", 174 | 175 | # No read paths specified 176 | 177 | # No write paths specified 178 | 179 | # dbus 180 | /run/dbus/system_bus_socket rw, 181 | dbus (send,receive) bus=system, 182 | #dbus (bind) bus=system, 183 | 184 | /proc/*/mounts r, 185 | 186 | # bluetooth 187 | network bluetooth raw, 188 | network bluetooth seqpacket, 189 | capability net_admin, 190 | capability net_raw, 191 | } 192 | -------------------------------------------------------------------------------- /build/snappy/sysmon/meta/dh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devicehive/IoT-framework/b268664a3e28f7fda786dc872a83879329bbf65d/build/snappy/sysmon/meta/dh.png -------------------------------------------------------------------------------- /build/snappy/sysmon/meta/package.yaml: -------------------------------------------------------------------------------- 1 | name: sysmon 2 | version: 1.0.0 3 | type: app 4 | vendor: Artyom Astafurov 5 | icon: meta/dh.png 6 | architecture: [amd64, armhf] 7 | frameworks: 8 | - devicehive-iot-toolkit 9 | services: 10 | - name: service 11 | description: "Monitor system stats and send them to the cloud via DeviceHive cloud framework" 12 | start: bin/service 13 | security-policy: 14 | apparmor: meta/devicehive.apparmor 15 | -------------------------------------------------------------------------------- /build/snappy/sysmon/meta/readme.md: -------------------------------------------------------------------------------- 1 | DeviceHive BLE Gateway 2 | 3 | BLE Gateway for DeviceHive. 4 | -------------------------------------------------------------------------------- /devicehive-alljoyn/alljoyn-bridge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devicehive/IoT-framework/b268664a3e28f7fda786dc872a83879329bbf65d/devicehive-alljoyn/alljoyn-bridge.png -------------------------------------------------------------------------------- /devicehive-alljoyn/alljoyn-device-example/alljoyn-device-example.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/godbus/dbus" 5 | "log" 6 | ) 7 | 8 | type AboutService struct { 9 | bus *dbus.Conn 10 | } 11 | 12 | func NewAboutService(bus *dbus.Conn) *AboutService { 13 | bridge := new(AboutService) 14 | bridge.bus = bus 15 | return bridge 16 | } 17 | 18 | // Only one for now, for testing purposes only 19 | func (a *AboutService) GetAboutData(languageTag string) (aboutData map[string]dbus.Variant, err *dbus.Error) { 20 | aboutData = make(map[string]dbus.Variant) 21 | aboutData["DeviceName"] = dbus.MakeVariant("Golang-device") 22 | err = nil 23 | return 24 | } 25 | 26 | func (a *AboutService) Introspect() (xml string, err *dbus.Error) { 27 | xml = ` 28 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | ` 48 | err = nil 49 | return 50 | } 51 | 52 | func main() { 53 | bus, err := dbus.SystemBus() 54 | bus.RequestName("com.devicehive.alljoyn.test", 55 | dbus.NameFlagDoNotQueue) 56 | 57 | if err != nil { 58 | log.Panic(err) 59 | } 60 | 61 | aboutService := NewAboutService(bus) 62 | 63 | bus.Export(aboutService, "/com/devicehive/alljoyn/test/About", "org.alljoyn.About") 64 | bus.Export(aboutService, "/com/devicehive/alljoyn/test/About", "org.freedesktop.DBus.Introspectable") 65 | 66 | // Now try to register ourself in AllJoyn via dbus 67 | go func() { 68 | bridge := bus.Object("com.devicehive.alljoyn.bridge", dbus.ObjectPath("/com/devicehive/alljoyn/bridge")) 69 | res := bridge.Call("com.devicehive.alljoyn.bridge.AddService", 0, "/com/devicehive/alljoyn/test/About", "com.devicehive.alljoyn.test", "/About", "org.alljoyn.About") 70 | log.Printf("Result: %+v", res) 71 | res = bridge.Call("com.devicehive.alljoyn.bridge.StartAllJoyn", 0, "com.devicehive.alljoyn.test") 72 | }() 73 | 74 | select {} 75 | } 76 | -------------------------------------------------------------------------------- /devicehive-alljoyn/basic-service/basic-service.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/godbus/dbus" 5 | "log" 6 | ) 7 | 8 | type BasicService struct { 9 | bus *dbus.Conn 10 | } 11 | 12 | func NewBasicService(bus *dbus.Conn) *BasicService { 13 | bridge := new(BasicService) 14 | bridge.bus = bus 15 | return bridge 16 | } 17 | 18 | func (a *BasicService) GetAboutData(languageTag string) (aboutData map[string]dbus.Variant, err *dbus.Error) { 19 | data := make(map[string]dbus.Variant) 20 | data["DeviceName"] = dbus.MakeVariant("Golang-device") 21 | return data, nil 22 | } 23 | 24 | func (a *BasicService) Cat(inStr1, inStr2 string) (res string, err *dbus.Error) { 25 | return inStr1 + " Dear " + inStr2, nil 26 | } 27 | 28 | func (a *BasicService) Introspect() (xml string, err *dbus.Error) { 29 | xml = ` 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | ` 43 | err = nil 44 | return 45 | } 46 | 47 | func main() { 48 | bus, err := dbus.SystemBus() 49 | bus.RequestName("com.devicehive.alljoyn.test.basic", 50 | dbus.NameFlagDoNotQueue) 51 | 52 | if err != nil { 53 | log.Panic(err) 54 | } 55 | 56 | basicService := NewBasicService(bus) 57 | 58 | bus.Export(basicService, "/com/devicehive/alljoyn/test/basic", "org.alljoyn.About") 59 | bus.Export(basicService, "/com/devicehive/alljoyn/test/basic", "org.alljoyn.Bus.sample") 60 | bus.Export(basicService, "/com/devicehive/alljoyn/test/basic", "org.freedesktop.DBus.Introspectable") 61 | 62 | // Now try to register ourself in AllJoyn via dbus 63 | go func() { 64 | bridge := bus.Object("com.devicehive.alljoyn.bridge", dbus.ObjectPath("/com/devicehive/alljoyn/bridge")) 65 | res := bridge.Call("com.devicehive.alljoyn.bridge.AddService", 0, "/com/devicehive/alljoyn/test/basic", "com.devicehive.alljoyn.test.basic", "/sample", "org.alljoyn.Bus.sample", "") 66 | log.Printf("Result: %+v", res) 67 | res = bridge.Call("com.devicehive.alljoyn.bridge.StartAllJoyn", 0, "com.devicehive.alljoyn.test.basic") 68 | }() 69 | 70 | select {} 71 | } 72 | -------------------------------------------------------------------------------- /devicehive-alljoyn/cfuncs.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "alljoyn.h" 8 | 9 | uint32_t Get_AJ_Message_msgId(); 10 | uint32_t Get_AJ_Message_bodyLen(); 11 | const char * Get_AJ_Message_signature(); 12 | const char * Get_AJ_Message_objPath(); 13 | const char * Get_AJ_Message_iface(); 14 | const char * Get_AJ_Message_member(); 15 | const char * Get_AJ_Message_destination(); 16 | const char* AJ_StatusText(AJ_Status status); 17 | 18 | const char* MyTranslator(uint32_t descId, const char* lang) ; 19 | 20 | AJ_Message * Get_AJ_ReplyMessage(); 21 | 22 | AJ_Message * Get_AJ_Message(); 23 | //void InitNotificationContent(); 24 | AJ_Status AJNS_Producer_Start(); 25 | void SendNotification(uint16_t messageType, char * lang, char * msg); 26 | AJ_BusAttachment * Get_AJ_BusAttachment(); 27 | AJ_Object * Allocate_AJ_Object_Array(uint32_t array_size); 28 | void * Create_AJ_Object(uint32_t index, AJ_Object * array, char* path, AJ_InterfaceDescription* interfaces, uint8_t flags, void* context); 29 | 30 | void * Get_Session_Opts(); 31 | void * Get_Arg(); 32 | AJ_Status AJ_MarshalArgs_cgo(AJ_Message* msg, char * a, char * b, char * c, char * d); 33 | 34 | int UnmarshalPort(); 35 | typedef void * (*AboutPropGetter)(const char* name, const char* language); 36 | 37 | void free (void *__ptr); 38 | AJ_Status MarshalArg(AJ_Message* msg, char * sig, void * value); 39 | AJ_Status AJ_DeliverMsg(AJ_Message* msg); 40 | AJ_Status AJ_MarshalSignal_cgo(AJ_Message* msg, uint32_t msgId, uint32_t sessionId, uint8_t flags, uint32_t ttl); 41 | AJ_Status UnmarshalJoinSessionArgs(AJ_Message* msg, uint16_t * port, uint32_t * sessionId); 42 | AJ_Status UnmarshalLostSessionArgs(AJ_Message* msg, uint32_t * sessionId, uint32_t * reason); 43 | 44 | void SetProperty(char* key, void * value); 45 | void * GetProperty(char* key); 46 | 47 | AJ_Status MyAboutPropGetter(AJ_Message* reply, const char* language); 48 | void AJ_RegisterDescriptionLanguages(const char* const* languages); 49 | 50 | char ** getLanguages(); 51 | //void AJ_PrintXMLWithDescriptions(const AJ_Object* objs, const char* languageTag); 52 | -------------------------------------------------------------------------------- /devicehive-alljoyn/conf/args.go: -------------------------------------------------------------------------------- 1 | package conf 2 | 3 | import "flag" 4 | 5 | const ( 6 | confArgKey = "conf" 7 | confArgDefaultValue = "" 8 | ) 9 | 10 | var ( 11 | confArgValue = "" 12 | ) 13 | 14 | func init() { 15 | flag.StringVar(&confArgValue, confArgKey, confArgDefaultValue, "file with DeviceHive configuration in Yaml") 16 | } 17 | 18 | func parseArgs() { 19 | if !flag.Parsed() { 20 | flag.Parse() 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /devicehive-alljoyn/conf/conf.go: -------------------------------------------------------------------------------- 1 | package conf 2 | 3 | import ( 4 | "io/ioutil" 5 | 6 | "gopkg.in/yaml.v2" 7 | ) 8 | 9 | // All parameters are optional. See defaults in the fix() 10 | type Conf struct { 11 | AJServiceConnectionTimeoutMilliseconds uint32 `yaml:"AJServiceConnectionTimeoutMilliseconds,omitempty"` 12 | AJServiceMsgUnmarshalTimeoutMilliseconds uint32 `yaml:"AJServiceMsgUnmarshalTimeoutMilliseconds,omitempty"` 13 | 14 | AJServiceConnectionPort uint16 `yaml:"AJServiceConnectionPort,omitempty"` 15 | } 16 | 17 | func (c *Conf) fix() { 18 | if c.AJServiceConnectionTimeoutMilliseconds == 0 { 19 | c.AJServiceConnectionTimeoutMilliseconds = 60 * 1000 20 | } 21 | 22 | if c.AJServiceMsgUnmarshalTimeoutMilliseconds == 0 { 23 | c.AJServiceMsgUnmarshalTimeoutMilliseconds = 5 * 1000 24 | } 25 | 26 | if c.AJServiceConnectionPort == 0 { 27 | c.AJServiceConnectionPort = 25 28 | } 29 | } 30 | 31 | func TestConf() *Conf { 32 | c := new(Conf) 33 | c.fix() 34 | return c 35 | } 36 | 37 | func FromArgs() (filepath string, c *Conf, err error) { 38 | parseArgs() 39 | filepath = confArgValue 40 | if len(filepath) == 0 { 41 | c = TestConf() 42 | return 43 | } 44 | c, err = readConf(confArgValue) 45 | return 46 | } 47 | 48 | func readConf(filepath string) (c *Conf, err error) { 49 | yamlFile, err := ioutil.ReadFile(filepath) 50 | if err != nil { 51 | return 52 | } 53 | err = yaml.Unmarshal(yamlFile, c) 54 | 55 | if err == nil { 56 | c.fix() 57 | } 58 | 59 | return 60 | } 61 | -------------------------------------------------------------------------------- /devicehive-alljoyn/lib/hashmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Generic hashmap manipulation functions 3 | * 4 | * Originally by Elliot C Back - http://elliottback.com/wp/hashmap-implementation-in-c/ 5 | * 6 | * Modified by Pete Warden to fix a serious performance problem, support strings as keys 7 | * and removed thread synchronization - http://petewarden.typepad.com 8 | */ 9 | #ifndef __HASHMAP_H__ 10 | #define __HASHMAP_H__ 11 | 12 | #define MAP_MISSING -3 /* No such element */ 13 | #define MAP_FULL -2 /* Hashmap is full */ 14 | #define MAP_OMEM -1 /* Out of Memory */ 15 | #define MAP_OK 0 /* OK */ 16 | 17 | /* 18 | * any_t is a pointer. This allows you to put arbitrary structures in 19 | * the hashmap. 20 | */ 21 | typedef void *any_t; 22 | 23 | /* 24 | * PFany is a pointer to a function that can take two any_t arguments 25 | * and return an integer. Returns status code.. 26 | */ 27 | typedef int (*PFany)(any_t, any_t); 28 | 29 | /* 30 | * map_t is a pointer to an internally maintained data structure. 31 | * Clients of this package do not need to know how hashmaps are 32 | * represented. They see and manipulate only map_t's. 33 | */ 34 | typedef any_t map_t; 35 | 36 | /* 37 | * Return an empty hashmap. Returns NULL if empty. 38 | */ 39 | extern map_t hashmap_new(); 40 | 41 | /* 42 | * Iteratively call f with argument (item, data) for 43 | * each element data in the hashmap. The function must 44 | * return a map status code. If it returns anything other 45 | * than MAP_OK the traversal is terminated. f must 46 | * not reenter any hashmap functions, or deadlock may arise. 47 | */ 48 | extern int hashmap_iterate(map_t in, PFany f, any_t item); 49 | 50 | /* 51 | * Add an element to the hashmap. Return MAP_OK or MAP_OMEM. 52 | */ 53 | extern int hashmap_put(map_t in, char* key, any_t value); 54 | 55 | /* 56 | * Get an element from the hashmap. Return MAP_OK or MAP_MISSING. 57 | */ 58 | extern int hashmap_get(map_t in, char* key, any_t *arg); 59 | 60 | /* 61 | * Remove an element from the hashmap. Return MAP_OK or MAP_MISSING. 62 | */ 63 | extern int hashmap_remove(map_t in, char* key); 64 | 65 | /* 66 | * Get any element. Return MAP_OK or MAP_MISSING. 67 | * remove - should the element be removed from the hashmap 68 | */ 69 | extern int hashmap_get_one(map_t in, any_t *arg, int remove); 70 | 71 | /* 72 | * Free the hashmap 73 | */ 74 | extern void hashmap_free(map_t in); 75 | 76 | /* 77 | * Get the current size of a hashmap 78 | */ 79 | extern int hashmap_length(map_t in); 80 | 81 | #endif -------------------------------------------------------------------------------- /devicehive-alljoyn/readme.md: -------------------------------------------------------------------------------- 1 | # DeviceHive IoT toolkit for AllJoyn 2 | 3 | [AllSeen Alliance]: https://allseenalliance.org 4 | [AllJoyn]: https://allseenalliance.org/framework 5 | 6 | ## Overview 7 | 8 | Driven by the [AllSeen Alliance], [AllJoyn] is an open source software framework that makes it easy for devices and apps to discover and communicate with each other. 9 | 10 | 11 | DeviceHive IoT Toolkit provides AllJoyn bridge that enables developers to expose non AllJpyn devices and applications as AllJoyn virtual devices without need to use AllJoyn C/C++ libraries. 12 | Devices can be described with simple DSL and logic can be implemented on any programming language. 13 | 14 | ![AllJoyn Bridge Diagram](alljoyn-bridge.png?raw=true) 15 | 16 | DeviceHive AllJoyn Bridge can be used on any Embedded Linux device. 17 | 18 | Bridge supports number of AllJoyn standards out of the box and any new can be implemented by adding more interface implementations. Currently supported: 19 | * About 20 | * Configuration 21 | * Events and Actions 22 | * Notification 23 | * ControlPanel 24 | * Lighting Service Framework 25 | 26 | 27 | ## Running in development 28 | 29 | To be able to compile and run devicehive-alljoyn bridge: 30 | 31 | 1. Clone and build `/alljoyn` submodule recursively 32 | 2. Set `LD_LIBRARY_PATH` environment variable to access `libajtcl.so` file 33 | ``` 34 | LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GOPATH/src/github.com/devicehive/IoT-framework/devicehive-alljoyn/alljoyn/core/ajtcl 35 | ``` 36 | 3. Create dbus config file `/etc/dbus-1/system.d/com.devicehive.conf` to allow bridge service register on system bus: 37 | 38 | ```xml 39 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | ``` 50 | 51 | -------------------------------------------------------------------------------- /devicehive-alljoyn/tests/alljoyn-bridge_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | import "encoding/xml" 5 | import "github.com/godbus/dbus/introspect" 6 | import "strings" 7 | 8 | func DummyIntrospectProvider(dbusService, dbusPath string) (*introspect.Node, error) { 9 | var node introspect.Node 10 | // xmlData := ` 11 | // 13 | // 14 | // 15 | // 16 | // 17 | // 18 | // 19 | // 20 | // 21 | // 22 | // 23 | // 24 | // 25 | // 26 | // 27 | // 28 | // 29 | // 30 | // ` 31 | 32 | xmlData := ` 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | ` 46 | 47 | err := xml.NewDecoder(strings.NewReader(xmlData)).Decode(&node) 48 | 49 | if err != nil { 50 | return nil, err 51 | } 52 | 53 | return &node, nil 54 | } 55 | 56 | func TestIntrospect(*testing.T) { 57 | allJoynBridge := NewAllJoynBridge(nil, DummyIntrospectProvider) 58 | allJoynBridge.AddService("/com/devicehive/alljoyn/test", "com.devicehive.alljoyn.test", "/com/devicehive/alljoyn/test", "com.devicehive.alljoyn.test") 59 | } 60 | 61 | func TestGetAllJoynObjects(t *testing.T) { 62 | node, err := DummyIntrospectProvider("", "") 63 | if err != nil { 64 | t.Fail() 65 | } 66 | 67 | obj := GetAllJoynObjects([]*introspect.Node{node}) 68 | PrintObjects(obj) 69 | } 70 | -------------------------------------------------------------------------------- /devicehive-alljoyn/tests/alljoyn-simple-device.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/xml" 5 | "github.com/godbus/dbus/introspect" 6 | "strings" 7 | ) 8 | 9 | func DummyIntrospectProvider(dbusService, dbusPath string) (*introspect.Node, error) { 10 | var node introspect.Node 11 | 12 | xmlData := ` 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | ` 26 | 27 | err := xml.NewDecoder(strings.NewReader(xmlData)).Decode(&node) 28 | 29 | if err != nil { 30 | return nil, err 31 | } 32 | 33 | return &node, nil 34 | } 35 | 36 | // func main() { 37 | // allJoynBridge := NewAllJoynBridge(nil, DummyIntrospectProvider) 38 | // allJoynBridge.AddService("/com/devicehive/alljoyn/test", "org.alljoyn.Bus.sample", "/sample", "org.alljoyn.Bus.sample") 39 | // allJoynBridge.StartAllJoyn("org.alljoyn.Bus.sample") 40 | // select {} 41 | // } 42 | -------------------------------------------------------------------------------- /devicehive-ble/readme.md: -------------------------------------------------------------------------------- 1 | # DeviceHive BLE D-Bus Daemon 2 | 3 | This daemon provides access to BLE peripheral devices via D-Bus. 4 | 5 | ## Consumer example: 6 | 7 | ```python 8 | #!/usr/bin/env python 9 | 10 | import dbus 11 | from dbus.mainloop.glib import DBusGMainLoop 12 | from gi.repository import GObject 13 | import array 14 | 15 | DBusGMainLoop(set_as_default=True) 16 | 17 | def get_ble(): 18 | obj = dbus.SystemBus().get_object("com.devicehive.bluetooth", "/com/devicehive/bluetooth") 19 | return dbus.Interface(obj, "com.devicehive.bluetooth") 20 | 21 | ble = get_ble() 22 | def device_discovered(mac, name, rssi): 23 | if (name == 'DELIGHT'): 24 | ble.ScanStop() 25 | ble.Connect(mac, False) 26 | 27 | def device_connected(mac): 28 | print "Connected to %s" % (mac) 29 | ble.GattWrite(mac, "fff1", "0f0d0300ffffffc800c800c8000059ffff") 30 | 31 | def main(): 32 | ble.ScanStart() 33 | ble.connect_to_signal("PeripheralDiscovered", device_discovered) 34 | ble.connect_to_signal("PeripheralConnected", device_connected) 35 | 36 | GObject.MainLoop().run() 37 | 38 | if __name__ == '__main__': 39 | main() 40 | ``` 41 | -------------------------------------------------------------------------------- /devicehive-bridge/.gitignore: -------------------------------------------------------------------------------- 1 | .idea -------------------------------------------------------------------------------- /devicehive-bridge/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "devicehive-bridge", 3 | "version": "0.0.1", 4 | "description": "DeviceHive BLE to Coloud dbus bridge", 5 | "main": "devicehive-bridge.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/devicehive/IoT-framework" 12 | }, 13 | "keywords": [ 14 | "IoT", 15 | "DeviceHive", 16 | "BLE", 17 | "cloud", 18 | "dbus" 19 | ], 20 | "author": "Sergey Demyanov", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/devicehive/IoT-framework/issues" 24 | }, 25 | "dependencies": { 26 | "dbus-native": "^0.2.0", 27 | "lodash": "^3.7.0" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /devicehive-cloud/conf/args.go: -------------------------------------------------------------------------------- 1 | package conf 2 | 3 | import "flag" 4 | 5 | const ( 6 | confArgKey = "conf" 7 | confArgDefaultValue = "" 8 | ) 9 | 10 | var ( 11 | confArgValue = "" 12 | ) 13 | 14 | func init() { 15 | flag.StringVar(&confArgValue, confArgKey, confArgDefaultValue, "file with DeviceHive configuration in Yaml") 16 | } 17 | 18 | func parseArgs() { 19 | if !flag.Parsed() { 20 | flag.Parse() 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /devicehive-cloud/conf/conf.go: -------------------------------------------------------------------------------- 1 | package conf 2 | 3 | import ( 4 | "io/ioutil" 5 | 6 | "gopkg.in/yaml.v2" 7 | ) 8 | 9 | type Conf struct { 10 | URL string `yaml:"URL,omitempty"` 11 | AccessKey string `yaml:"AccessKey,omitempty"` 12 | 13 | DeviceID string `yaml:"DeviceID,omitempty"` 14 | DeviceName string `yaml:"DeviceName,omitempty"` 15 | DeviceKey string `yaml:"DeviceKey,omitempty"` 16 | 17 | NetworkName string `yaml:"NetworkName,omitempty"` 18 | NetworkKey string `yaml:"NetworkKey,omitempty"` 19 | NetworkDesc string `yaml:"NetworkDescription,omitempty"` 20 | 21 | // Optional 22 | SendNotificatonQueueCapacity uint64 `yaml:"SendNotificatonQueueCapacity,omitempty"` 23 | LoggingLevel string `yaml:"LoggingLevel,omitempty"` 24 | } 25 | 26 | func (c *Conf) fix() { 27 | if c.SendNotificatonQueueCapacity == 0 { 28 | c.SendNotificatonQueueCapacity = 2048 29 | } 30 | 31 | if len(c.LoggingLevel) == 0 { 32 | c.LoggingLevel = "info" 33 | } 34 | } 35 | 36 | func FromArgs() (filepath string, c Conf, err error) { 37 | parseArgs() 38 | filepath = confArgValue 39 | if len(filepath) == 0 { 40 | c = TestConf() 41 | return 42 | } 43 | c, err = readConf(confArgValue) 44 | return 45 | } 46 | 47 | func readConf(filepath string) (c Conf, err error) { 48 | yamlFile, err := ioutil.ReadFile(filepath) 49 | if err != nil { 50 | return 51 | } 52 | err = yaml.Unmarshal(yamlFile, &c) 53 | 54 | if err == nil { 55 | (&c).fix() 56 | } 57 | 58 | return 59 | } 60 | 61 | func TestConf() Conf { 62 | c := Conf{} 63 | 64 | c.URL = "http://52.6.240.235:8080/dh/rest" 65 | c.AccessKey = "1jwKgLYi/CdfBTI9KByfYxwyQ6HUIEfnGSgakdpFjgk=" 66 | 67 | c.DeviceID = "0B24431A-EC99-4887-8B4F-38C3CEAF1D03" 68 | c.DeviceName = "snappy-go-gateway" 69 | c.DeviceKey = "snappy-go-secret-key" 70 | 71 | // c.LoggingLevel = "info" 72 | // c.LoggingLevel = "debug" 73 | c.LoggingLevel = "trace" 74 | 75 | (&c).fix() 76 | return c 77 | } 78 | -------------------------------------------------------------------------------- /devicehive-cloud/devicehive-cloud.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | 7 | "github.com/devicehive/IoT-framework/devicehive-cloud/conf" 8 | "github.com/devicehive/devicehive-go/devicehive" 9 | "github.com/devicehive/devicehive-go/devicehive/log" 10 | 11 | "github.com/godbus/dbus" 12 | ) 13 | 14 | // parse a string to custom JSON 15 | func parseJSON(s string) (dat interface{}, err error) { 16 | b := bytes.Trim([]byte(s), "\x00") 17 | err = json.Unmarshal(b, &dat) 18 | return 19 | } 20 | 21 | // create new DBus error 22 | func newDHError(message string) *dbus.Error { 23 | return dbus.NewError("com.devicehive.Error", 24 | []interface{}{message}) 25 | } 26 | 27 | const ( 28 | DBusConnName = "com.devicehive.cloud" 29 | ) 30 | 31 | func main() { 32 | configFile, config, err := conf.FromArgs() 33 | switch { 34 | case err != nil: 35 | log.Fatalf("Failed to read %q configuration (%s)", configFile, err) 36 | case configFile == "": 37 | log.Warnf("No configuration file provided!") 38 | log.Infof("Test configuration is used: %+v", config) 39 | default: 40 | log.Infof("Starting DeviceHive with %q configuration: %+v", configFile, config) 41 | } 42 | 43 | log.SetLevelByName(config.LoggingLevel) 44 | 45 | bus, err := dbus.SystemBus() 46 | if err != nil { 47 | log.Warnf("Cannot get system bus (error: %s)", err) 48 | log.Infof("Trying to use session bus for testing purposes...") 49 | if bus, err = dbus.SessionBus(); err != nil { 50 | log.Fatalf("Cannot get session bus (error: %s)", err) 51 | return 52 | } 53 | } 54 | 55 | reply, err := bus.RequestName(DBusConnName, dbus.NameFlagDoNotQueue) 56 | switch { 57 | case err != nil: 58 | log.Fatalf("Cannot request name %q (error: %s)", DBusConnName, err) 59 | case reply != dbus.RequestNameReplyPrimaryOwner: 60 | log.Fatalf("The name %q already taken", DBusConnName) 61 | } 62 | 63 | s, err := devicehive.NewService(config.URL, config.AccessKey) 64 | if err != nil { 65 | log.Fatalf("Failed to create DeviceHive service (error: %s)", err) 66 | } 67 | 68 | log.Infof("Starting %v", s) 69 | mainLoop(bus, s, config) 70 | } 71 | -------------------------------------------------------------------------------- /devicehive-cloud/devicehive-test-priority/README.md: -------------------------------------------------------------------------------- 1 | #Instruments for testing SendNotification priority queue 2 | 3 | 4 | ## Parameters in source code 5 | * in configuration file (or `testConf()` in `conf/conf.go`) you can change `SendNotificationQueueCapacity` (for example `23`, default=`2048`) 6 | * see `const sendCommandSleeperSeconds` in `ws/send.go` to simulate duration of sending a notification (for example `10`, default=`0`) 7 | 8 | ## Utilites 9 | * `devicehive-high-send` — sends notification with HIGH priority immediately 10 | * `devicehive-low-sender-loop` — sends notifications with LOW priority with rate is equal one notification per second 11 | 12 | -------------------------------------------------------------------------------- /devicehive-cloud/devicehive-test-priority/devicehive-high-send/devicehive-high-send.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/devicehive/IoT-framework/godbus-helpers/cloud" 7 | ) 8 | 9 | func main() { 10 | c, err := cloud.NewDbusForComDevicehiveCloud() 11 | if err != nil { 12 | log.Fatalf("Creation Dbus wrapper with error: %s", err.Error()) 13 | } 14 | 15 | c.SendNotification("[H I G H N O T I F I C A T I O N]", map[string]interface{}{}, 1000) 16 | } 17 | -------------------------------------------------------------------------------- /devicehive-cloud/devicehive-test-priority/devicehive-low-sender-loop/devicehive-low-sender-loop.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "time" 6 | 7 | "github.com/devicehive/IoT-framework/godbus-helpers/cloud" 8 | ) 9 | 10 | func main() { 11 | c, err := cloud.NewDbusForComDevicehiveCloud() 12 | if err != nil { 13 | log.Fatalf("Creation Dbus wrapper with error: %s", err.Error()) 14 | } 15 | 16 | for { 17 | c.SendNotification("LowNotification", map[string]interface{}{}, 2) 18 | time.Sleep(1 * time.Second) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /devicehive-cloud/exampleconf.yml: -------------------------------------------------------------------------------- 1 | URL: http://playground.devicehive.com/api/rest 2 | AccessKey: 3 | 4 | DeviceID: my-simple-gw 5 | DeviceName: my simple gw 6 | DeviceKey: my-device-secret-key 7 | 8 | LoggingLevel: trace 9 | -------------------------------------------------------------------------------- /devicehive-cloud/main-loop.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/devicehive/IoT-framework/devicehive-cloud/conf" 7 | "github.com/devicehive/devicehive-go/devicehive" 8 | "github.com/devicehive/devicehive-go/devicehive/core" 9 | "github.com/devicehive/devicehive-go/devicehive/log" 10 | 11 | "github.com/godbus/dbus" 12 | "github.com/godbus/dbus/introspect" 13 | "github.com/godbus/dbus/prop" 14 | 15 | "strings" 16 | "time" 17 | ) 18 | 19 | const ( 20 | ComDevicehiveCloudPath = "/com/devicehive/cloud" 21 | ComDevicehiveCloudIface = "com.devicehive.cloud" 22 | 23 | waitTimeout = 30 * time.Second 24 | ) 25 | 26 | // DBus wrapper object 27 | type DBusWrapper struct { 28 | service devicehive.Service 29 | device *core.Device 30 | } 31 | 32 | // send notification 33 | // priority is ignored 34 | func (w *DBusWrapper) SendNotification(name, parameters string, priority uint64) *dbus.Error { 35 | log.Infof("sending notification(name=%q, params=%q, priority=%d)", name, parameters, priority) 36 | dat, err := parseJSON(parameters) 37 | if err != nil { 38 | log.Warnf("failed to convert notification parameters to JSON (error: %s)", err) 39 | return newDHError(err.Error()) 40 | } 41 | 42 | notification := devicehive.NewNotification(name, dat) 43 | err = w.service.InsertNotification(w.device, notification, waitTimeout) 44 | if err != nil { 45 | log.Warnf("failed to send notification (error: %s)", err) 46 | return newDHError(err.Error()) 47 | } 48 | 49 | return nil // OK 50 | } 51 | 52 | // update command result 53 | func (w *DBusWrapper) UpdateCommand(id uint64, status, result string) *dbus.Error { 54 | log.Infof("updating command(id:%d, status=%q, result:%q", id, status, result) 55 | dat, err := parseJSON(result) 56 | if err != nil { 57 | log.Warnf("failed to convert command result to JSON (error: %s)", err) 58 | return newDHError(err.Error()) 59 | } 60 | 61 | command := devicehive.NewCommandResult(id, status, dat) 62 | err = w.service.UpdateCommand(w.device, command, waitTimeout) 63 | if err != nil { 64 | log.Warnf("failed to update command (error: %s)", err) 65 | return newDHError(err.Error()) 66 | } 67 | 68 | return nil // OK 69 | } 70 | 71 | // export main + introspectable DBus objects 72 | func exportDBusObject(bus *dbus.Conn, w *DBusWrapper) { 73 | bus.Export(w, ComDevicehiveCloudPath, ComDevicehiveCloudIface) 74 | 75 | // main service interface 76 | serviceInterface := introspect.Interface{ 77 | Name: ComDevicehiveCloudIface, 78 | Methods: introspect.Methods(w), 79 | Signals: []introspect.Signal{ 80 | { 81 | Name: "CommandReceived", 82 | Args: []introspect.Arg{ 83 | {"id", "t", "out"}, 84 | {"name", "s", "out"}, 85 | {"parameters", "s", "out"}, // JSON string 86 | }, 87 | }, 88 | }, 89 | } 90 | 91 | // main service node 92 | n := &introspect.Node{ 93 | Name: ComDevicehiveCloudPath, 94 | Interfaces: []introspect.Interface{ 95 | introspect.IntrospectData, 96 | prop.IntrospectData, 97 | serviceInterface}, 98 | } 99 | n_obj := introspect.NewIntrospectable(n) 100 | log.Tracef("%q introspectable: %s", ComDevicehiveCloudPath, n_obj) 101 | bus.Export(n_obj, ComDevicehiveCloudPath, "org.freedesktop.DBus.Introspectable") 102 | 103 | // root node 104 | root := &introspect.Node{ 105 | Children: []introspect.Node{ 106 | { Name: strings.TrimPrefix(ComDevicehiveCloudPath, "/") }, 107 | }, 108 | } 109 | root_obj := introspect.NewIntrospectable(root) 110 | log.Tracef("%q introspectable: %s", "/", root_obj) 111 | bus.Export(root_obj, "/", "org.freedesktop.DBus.Introspectable") 112 | } 113 | 114 | // main loop 115 | func mainLoop(bus *dbus.Conn, service devicehive.Service, config conf.Conf) { 116 | // getting server info 117 | info, err := service.GetServerInfo(waitTimeout) 118 | if err != nil { 119 | log.Warnf("Cannot get service info (error: %s)", err) 120 | return 121 | } 122 | 123 | // registering device 124 | device := devicehive.NewDevice(config.DeviceID, config.DeviceName, 125 | devicehive.NewDeviceClass("go-gateway-class", "0.1")) 126 | device.Key = config.DeviceKey 127 | if len(config.NetworkName)!=0 || len(config.NetworkKey)!=0 { 128 | device.Network = devicehive.NewNetwork(config.NetworkName, config.NetworkKey) 129 | device.Network.Description = config.NetworkDesc 130 | } 131 | err = service.RegisterDevice(device, waitTimeout) 132 | if err != nil { 133 | log.Warnf("Cannot register device (error: %s)", err) 134 | return 135 | } 136 | 137 | // start polling commands 138 | listener, err := service.SubscribeCommands(device, info.Timestamp, waitTimeout) 139 | if err != nil { 140 | log.Warnf("Cannot subscribe commands (error: %s)") 141 | return 142 | } 143 | 144 | wrapper := DBusWrapper{service: service, device: device} 145 | exportDBusObject(bus, &wrapper) 146 | 147 | for { 148 | select { 149 | case cmd := <-listener.C: 150 | params := "" 151 | if cmd.Parameters != nil { 152 | buf, err := json.Marshal(cmd.Parameters) 153 | if err != nil { 154 | log.Warnf("Cannot generate JSON from parameters of command %+v (error: %s)", cmd, err) 155 | continue 156 | } 157 | params = string(buf) 158 | } 159 | log.Infof("COMMAND %s -> %s(%v)", config.URL, cmd.Name, params) 160 | bus.Emit(ComDevicehiveCloudPath, ComDevicehiveCloudIface+".CommandReceived", cmd.Id, cmd.Name, params) 161 | } 162 | 163 | //time.Sleep(5 * time.Second) 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /devicehive-cloud/pqueue/consts.go: -------------------------------------------------------------------------------- 1 | package pqueue 2 | 3 | import "errors" 4 | 5 | const StandardQueueCapacity = 2048 6 | 7 | var ListenerShouldNotBeNil = errors.New("Out-channel should not be nil") 8 | -------------------------------------------------------------------------------- /devicehive-cloud/pqueue/heap.go: -------------------------------------------------------------------------------- 1 | package pqueue 2 | 3 | func (q *PriorityQueue) Push(x interface{}) { 4 | q.cond.L.Lock() 5 | q.items = append(q.items, x.(QueueItem)) 6 | q.cond.L.Unlock() 7 | q.cond.Signal() 8 | } 9 | 10 | func (q *PriorityQueue) Pop() interface{} { 11 | q.cond.L.Lock() 12 | 13 | old := q.items 14 | n := len(old) 15 | 16 | x := old[n-1] 17 | q.items = old[0 : n-1] 18 | 19 | q.cond.L.Unlock() 20 | q.cond.Signal() 21 | 22 | return x 23 | } 24 | -------------------------------------------------------------------------------- /devicehive-cloud/pqueue/pqueue.go: -------------------------------------------------------------------------------- 1 | package pqueue 2 | 3 | import ( 4 | "container/heap" 5 | "sync" 6 | "time" 7 | ) 8 | 9 | // type Message []byte 10 | type Message map[string]interface{} 11 | 12 | type QueueItem struct { 13 | Msg Message 14 | Timestamp uint64 15 | Priority uint64 16 | } 17 | 18 | type PriorityQueue struct { 19 | items []QueueItem 20 | cond *sync.Cond 21 | 22 | capacity uint64 23 | out chan Message 24 | } 25 | 26 | func (pq *PriorityQueue) Out() chan Message { 27 | return pq.out 28 | } 29 | 30 | func NewPriorityQueue(capacity uint64, listener chan Message) (*PriorityQueue, error) { 31 | pq := PriorityQueue{} 32 | if listener == nil { 33 | return &pq, ListenerShouldNotBeNil 34 | } 35 | 36 | pq.items = []QueueItem{} 37 | pq.cond = &sync.Cond{L: &sync.Mutex{}} 38 | pq.capacity = capacity 39 | pq.out = listener 40 | 41 | go func() { 42 | defer func() { recover() }() 43 | for { 44 | pq.cond.L.Lock() 45 | for pq.Len() == 0 { 46 | pq.cond.Wait() 47 | } 48 | pq.cond.L.Unlock() 49 | item := heap.Pop(&pq).(QueueItem) 50 | pq.out <- item.Msg 51 | } 52 | }() 53 | return &pq, nil 54 | } 55 | 56 | func (pq *PriorityQueue) Send(m Message, priority uint64) (removed []QueueItem) { 57 | for uint64(pq.Len()) > pq.capacity-1 { 58 | item := heap.Remove(pq, pq.Len()-1).(QueueItem) 59 | removed = append(removed, item) 60 | } 61 | heap.Push(pq, QueueItem{ 62 | Msg: m, 63 | Timestamp: uint64(time.Now().Unix()), 64 | Priority: priority, 65 | }) 66 | return 67 | } 68 | -------------------------------------------------------------------------------- /devicehive-cloud/pqueue/sorting.go: -------------------------------------------------------------------------------- 1 | package pqueue 2 | 3 | func (q PriorityQueue) Len() int { 4 | return len(q.items) 5 | } 6 | 7 | func (q PriorityQueue) Less(i, j int) bool { 8 | return q.items[i].Timestamp*q.items[i].Priority > q.items[j].Timestamp*q.items[j].Priority 9 | } 10 | 11 | func (q PriorityQueue) Swap(i, j int) { 12 | if (i > len(q.items)-1) || (j > len(q.items)-1) || (i < 0) || (j < 0) { 13 | return 14 | } 15 | q.items[i], q.items[j] = q.items[j], q.items[i] 16 | } 17 | -------------------------------------------------------------------------------- /devicehive-cloud/readme.md: -------------------------------------------------------------------------------- 1 | # DeviceHive Cloud Gateway D-Bus Daemon 2 | 3 | ## Decription 4 | `devicehive-cloud` provides D-Bus interface to access DeviceHive cloud server. 5 | It can also be served as a reference implementation of general purpose cloud 6 | conntectivity service (ex: PubNub). It starts as a daemon loading cloud 7 | configuration from `.yml` file. While running it maintains cloud connectivity 8 | and responds to D-Bus API calls from client applications, as well as notifies 9 | applications of incoming messages or status changes. 10 | 11 | ## Installation 12 | ### Ubuntu Snappy Core 13 | Ubuntu Snappy Core runs Raspberry Pi 2, Beagle Bone Black, and a veriety of ARM and 14 | x86 devices, so it can be a good choice for hassle free deployment for a framework. 15 | 16 | Steps: 17 | * Install Ubuntu Snappy Core on your favorite system: https://developer.ubuntu.com/en/snappy/start/ 18 | * Once Snappy is up and running on your device, install DeviceHive IoT Toolkit: 19 | * Download IoT Toolkit snap from: https://github.com/devicehive/IoT-framework/releases/download/1.0.0-RC1/devicehive-iot-toolkit_1.0.0_multi.snap 20 | * Copy it on your Snappy Device: 21 | ``` 22 | scp *.snap ubuntu@snappy-host:~ 23 | ``` 24 | * Install snaps using the following command: 25 | ``` 26 | sudo snappy install devicehive-iot-toolkit_1.0.0_multi.snap --allow-unauthenticated 27 | ``` 28 | If any issues occur during snaps install you can check syslog for details: 29 | ``` 30 | sudo tail -n 100 /var/log/syslog 31 | ``` 32 | 33 | ## Configuration 34 | If you are running `devicehive-cloud` as a part of Snappy Framework you can run 35 | `sudo snappy config devicehive-cloud config.yml`, or if you are running it on other 36 | system as a standalone executable, a configuration file can be supplied 37 | with `--conf` command line argument. 38 | 39 | Sample config: 40 | ``` 41 | URL: http://playground.devicehive.com/api/rest 42 | AccessKey: 43 | 44 | DeviceID: my-simple-gw 45 | DeviceName: my simple gw 46 | ``` 47 | 48 | ## D-Bus configuration for Ubuntu 49 | In some cases to run `devicehive-cloud` additional system configuration 50 | changes should be made. Need to provide appropriate D-Bus security file 51 | `/etc/dbus-1/system.d/com.devicehive.cloud.conf`: 52 | 53 | ``` 54 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | ``` 63 | 64 | ## API Reference 65 | TBD 66 | 67 | ## Building and running it yourself 68 | ###How to make a binary? 69 | ``` 70 | go get github.com/devicehive/IoT-framework/tree/master/devicehive-cloud 71 | go install github.com/devicehive/IoT-framework/tree/master/devicehive-cloud 72 | ``` 73 | 74 | ### How to run? 75 | ``` 76 | $GOPATH/bin/devicehive-cloud --conf deviceconf.yml 77 | ``` 78 | -------------------------------------------------------------------------------- /devicehive-enocean/enocean-daemon: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import sys, os, time 3 | from enocean.consolelogger import init_logging 4 | from enocean.communicators.serialcommunicator import SerialCommunicator 5 | from enocean.protocol.packet import Packet 6 | from enocean.protocol.constants import PACKET, RORG 7 | 8 | import dbus.service 9 | from dbus.mainloop.glib import DBusGMainLoop 10 | from gi.repository import GObject 11 | import threading 12 | import traceback 13 | import json 14 | 15 | try: 16 | import queue 17 | except ImportError: 18 | import Queue as queue 19 | 20 | DBUS_BUS_NAME = "com.devicehive.enocean" 21 | DBUS_BUS_PATH = "/com/devicehive/enocean" 22 | 23 | 24 | class EnoceanService(dbus.service.Object): 25 | def __init__(self, port='/dev/ttyUSB0'): 26 | self.m_service_path = DBUS_BUS_PATH 27 | self.m_poll_thread = None 28 | self.m_port = port 29 | bus_name = dbus.service.BusName(DBUS_BUS_NAME, dbus.SystemBus()) 30 | dbus.service.Object.__init__(self, bus_name, self.m_service_path) 31 | self.init() 32 | 33 | # send when pin state changed 34 | @dbus.service.signal(DBUS_BUS_NAME) 35 | def message_received(self, value): 36 | pass 37 | 38 | # pin state poller 39 | def poller(self): 40 | 41 | while self.m_loop: 42 | try: 43 | self.m_communicator = SerialCommunicator(self.m_port) 44 | p = Packet(PACKET.COMMON_COMMAND, [0x08]) 45 | 46 | self.m_communicator.start() 47 | self.m_communicator.send(p) 48 | print("Connected to device on %s" % self.m_port) 49 | while self.m_communicator.is_alive(): 50 | try: 51 | # Loop to empty the queue... 52 | p = self.m_communicator.receive.get(block=True, timeout=1) 53 | res = None 54 | 55 | print(p) 56 | 57 | if p.type == PACKET.RADIO: 58 | res = {"sender": p.sender_hex} 59 | 60 | if p.type == PACKET.RADIO and p.rorg == RORG.BS4: 61 | for k in p.parse_eep(0x02, 0x05): 62 | res[k] = p.parsed[k] 63 | if p.type == PACKET.RADIO and p.rorg == RORG.BS1: 64 | for k in p.parse_eep(0x00, 0x01): 65 | res[k] = p.parsed[k] 66 | if p.type == PACKET.RADIO and p.rorg == RORG.RPS: 67 | for k in p.parse_eep(0x02, 0x04): 68 | res[k] = p.parsed[k] 69 | 70 | if (res): 71 | s = json.dumps(res) 72 | print(s) 73 | self.message_received(json.dumps(res)) 74 | 75 | except queue.Empty: 76 | time.sleep(0.1) 77 | continue 78 | except (OSError, IOError): 79 | # this error means the usb dongle is not present. 80 | # for now we just ignore and wait. Better solution is requested in issue #9 81 | # (https://github.com/devicehive/IoT-framework/issues/9) 82 | time.sleep(5) 83 | continue 84 | except (KeyboardInterrupt, SystemExit): 85 | print('Exiting..') 86 | sys.exit() 87 | except Exception: 88 | traceback.print_exc(file=sys.stdout) 89 | break 90 | 91 | 92 | # init 93 | # @dbus.service.method(DBUS_BUS_NAME) 94 | def init(self): 95 | init_logging() 96 | self.m_loop = True 97 | self.m_communicator = None 98 | self.m_poll_thread = threading.Thread(target=self.poller) 99 | self.m_poll_thread.start() 100 | 101 | # free all resources 102 | # @dbus.service.method(DBUS_BUS_NAME) 103 | def deinit(self): 104 | self.m_loop = False 105 | if self.m_communicator is not None and self.m_communicator.is_alive(): 106 | self.m_communicator.stop() 107 | self.m_poll_thread.join() 108 | 109 | def main(): 110 | # init d-bus 111 | DBusGMainLoop(set_as_default=True) 112 | 113 | # init d-bus 114 | GObject.threads_init() 115 | dbus.mainloop.glib.threads_init() 116 | 117 | # create root element 118 | enocean_root_service = EnoceanService() 119 | # start mainloop 120 | try: 121 | GObject.MainLoop().run() 122 | except (KeyboardInterrupt, SystemExit): 123 | enocean_root_service.deinit() 124 | sys.exit() 125 | 126 | if __name__ == "__main__": 127 | main() -------------------------------------------------------------------------------- /devicehive-enocean/readme.md: -------------------------------------------------------------------------------- 1 | #DeviceHive EnOcean D-Bus Daemon 2 | 3 | EnOcean daemon for dbus. All EnOcean actuators harvest energy from enviroment and use it to send short message via air to reciver that connect to machine with this framework. This message can be obtain with: 4 | 5 | message_received 6 | 7 | dbus signal of this framework. So, usage is extreamly simple: 8 | 9 | ```` 10 | enocean_manager = bus.get_object(DBUS_BUS_ENOCEAN_NAME, '/com/devicehive/enocean') 11 | enocean = dbus.Interface(enocean_manager, DBUS_BUS_ENOCEAN_NAME) 12 | enocean.connect_to_signal('message_received', message_received) 13 | ```` 14 | just unparse pure data in `message_received` callback and use it. 15 | 16 | 17 | # Running 18 | Current daemon has dependency on `enocean` python3 library: 19 | ``` 20 | pip3 install enocean 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /devicehive-gpio/DBUS-SPEC.md: -------------------------------------------------------------------------------- 1 | # DeviceHive GPIO DBus Spec 2 | 3 | ### Interface com.devicehive.gpio.GpioService 4 | Bus Name: `com.devicehive.gpio` 5 | Path: `/com/devicehive/gpio` 6 | 7 | #### Methods: 8 | `list()` - returns list of available gpio pins 9 | 10 | `add(pin, port)` - Register pin to expose a physical port 11 | 12 | `rm(pin)` - Unregister exposed pin 13 | 14 | `clear()` - Unregister all exposed pins 15 | 16 | `add_profile(pin_port_pairs)` - Register multiple pins 17 | 18 | 19 | #### Introspection: 20 | ```xml 21 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | ``` 83 | 84 | 85 | ### Interface com.devicehive.gpio.GpioPin 86 | Bus Name: `com.devicehive.gpio` 87 | Path: `/com/devicehive/gpio/{PIN}` 88 | 89 | #### Methods: 90 | `init(mode)` - initialize pin. For digital pins mode can be `out` for output, `in` for input, 91 | `rising` or `falling` or `both` for input with enabled notifications 92 | analog pins recieve period in miliseconds as mode. It sends notifications with 93 | analog value every choosen period of time. 94 | 95 | `deinit()` - deinitialize pin and free all resource 96 | 97 | `set_value(value)` - set pin state, where value is ether `0` or `1` 98 | 99 | `set()` - set pin state to `1` 100 | 101 | `clear()` - set pin state to `0` 102 | 103 | `get()` - read pin state or value for analog inputs 104 | 105 | `toggle()` - toggle pin state from `0` to `1` or from `1` to `0` 106 | 107 | 108 | #### Introspection: 109 | ```xml 110 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | ``` 144 | 145 | -------------------------------------------------------------------------------- /devicehive-gpio/README.md: -------------------------------------------------------------------------------- 1 | # DeviceHive GPIO framework 2 | DeviceHive GPIO framework and usage examples. 3 | 4 | > DBus Spec can be found [here](DBUS-SPEC.md) 5 | 6 | ### Running 7 | Run 8 | daemon/gpio-daemon 9 | 10 | ## Device Profiles 11 | 12 | As GPIO pinout is different on every device/board and there is no way to enumerate available pins programatically. So gpio daemon uses pin mapping for each device. Mappings are located in `profiles` folder. Each profile is mapped to the name returned by `/sys/firmware/devicetree/base/model` on the current system. 13 | 14 | -------------------------------------------------------------------------------- /devicehive-gpio/profiles/Raspberry Pi 2 Model B.yaml: -------------------------------------------------------------------------------- 1 | PIN3: 2 2 | PIN5: 3 3 | PIN7: 4 4 | PIN8: 14 5 | PIN10: 15 6 | PIN11: 17 7 | PIN12: 18 8 | PIN13: 27 9 | PIN15: 22 10 | PIN16: 23 11 | PIN18: 24 12 | PIN19: 10 13 | PIN21: 9 14 | PIN22: 25 15 | PIN23: 11 16 | PIN24: 8 17 | PIN26: 7 18 | -------------------------------------------------------------------------------- /devicehive-gpio/profiles/TI AM335x BeagleBone Black.yaml: -------------------------------------------------------------------------------- 1 | PIN3: 38 2 | PIN4: 39 3 | PIN5: 34 4 | PIN6: 35 5 | PIN7: 66 6 | PIN8: 67 7 | PIN9: 69 8 | PIN10: 68 9 | PIN11: 45 10 | PIN12: 44 11 | PIN13: 23 12 | PIN14: 26 13 | PIN15: 47 14 | PIN16: 46 15 | PIN17: 27 16 | PIN18: 65 17 | PIN19: 22 18 | PIN20: 63 19 | PIN21: 62 20 | PIN22: 37 21 | PIN23: 36 22 | PIN24: 33 23 | PIN25: 32 24 | PIN26: 61 25 | PIN27: 86 26 | PIN28: 88 27 | PIN29: 87 28 | PIN30: 89 29 | PIN31: 10 30 | PIN32: 11 31 | PIN33: 9 32 | PIN34: 81 33 | PIN35: 8 34 | PIN36: 80 35 | PIN37: 78 36 | PIN38: 79 37 | PIN39: 76 38 | PIN40: 77 39 | PIN41: 74 40 | PIN42: 75 41 | PIN43: 72 42 | PIN44: 73 43 | PIN45: 70 44 | PIN46: 71 45 | PIN79: AIN4 46 | PIN81: AIN6 47 | PIN82: AIN5 48 | PIN83: AIN2 49 | PIN84: AIN3 50 | PIN85: AIN0 51 | PIN86: AIN1 52 | -------------------------------------------------------------------------------- /examples/alljoyn/common/notification.py: -------------------------------------------------------------------------------- 1 | import core 2 | import dbus.service 3 | 4 | 5 | 6 | MSG_TYPE_INFO = dbus.UInt32(0) 7 | MSG_TYPE_WARNING = dbus.UInt32(1) 8 | MSG_TYPE_EMERGENCY = dbus.UInt32(2) 9 | 10 | ''' 11 | Producer and Dismisser obejcts are not needed as they are implemented in the bridge itself 12 | ''' 13 | 14 | class NotificationService(core.PropertiesServiceInterface): 15 | """Enabling Notifications for alljoyn application""" 16 | def __init__(self, container, path): 17 | core.PropertiesServiceInterface.__init__( 18 | self, container, path, 19 | {'org.alljoyn.Notification': {'Version': dbus.UInt16(1)}} 20 | ) 21 | 22 | def IntrospectionXml(self): 23 | return """ 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | """ + core.PropertiesServiceInterface.IntrospectionXml(self) 40 | 41 | ''' 42 | Arguments versionm msgId, deviceId, deviceName, appId, appName 43 | are ignored and will he filled by the bridge. Use NotifySimple method instead. 44 | ''' 45 | @dbus.service.signal('org.alljoyn.Notification', 46 | signature='qiqssaysa{ss}a{iv}a{ss}') 47 | def Notify(self, version, msgId, msgType, deviceId, deviceName, 48 | appId, appName, langText, attributes, customAttributes): 49 | pass 50 | 51 | 52 | class Notifications(object): 53 | """Wrapper for /info /warning /emergency services""" 54 | def __init__(self, container): 55 | 56 | self._services = { 57 | MSG_TYPE_INFO: NotificationService(container, '/info'), 58 | MSG_TYPE_WARNING: NotificationService(container, 'warning'), 59 | MSG_TYPE_EMERGENCY: NotificationService(container, '/emergency') 60 | } 61 | 62 | def _notify(self, msgType, language, message, attributes = {}, customAttributes = {}): 63 | self._services[msgType].Notify(dbus.UInt16(2), 0, msgType, '', '', '', '', 64 | {language: message}, attributes, customAttributes) 65 | 66 | def info(self, language, message): 67 | self._notify(MSG_TYPE_INFO, language, message) 68 | 69 | def warning(self, language, message): 70 | self._notify(MSG_TYPE_WARNING, language, message) 71 | 72 | def emergency(self, language, message): 73 | self._notify(MSG_TYPE_EMERGENCY, language, message) 74 | -------------------------------------------------------------------------------- /examples/alljoyn/hello.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import time, uuid 4 | import threading 5 | import traceback 6 | import sys 7 | import os 8 | import socket 9 | import collections 10 | import dbus.service 11 | from dbus.mainloop.glib import DBusGMainLoop 12 | from gi.repository import GObject 13 | 14 | scriptDir = os.path.dirname(os.path.realpath(__file__)) 15 | sys.path.append( scriptDir + "/common" ) 16 | 17 | import core 18 | 19 | DBusGMainLoop(set_as_default=True) 20 | 21 | 22 | DBUS_BRIDGE_NAME = 'com.devicehive.alljoyn.bridge' 23 | DBUS_BRIDGE_PATH = '/com/devicehive/alljoyn/bridge' 24 | 25 | DBUS_BUS_NAME = 'com.devicehive.alljoyn.SmartHome' 26 | DBUS_BUS_PATH = '/com/devicehive/alljoyn/SmartHome' 27 | 28 | HELLO_SVC = 'org.allseen.SmartHome.Hello' 29 | 30 | bus = dbus.SystemBus() 31 | bus_name = dbus.service.BusName(DBUS_BUS_NAME, bus) 32 | 33 | 34 | class HelloService(core.PropertiesServiceInterface): 35 | def __init__(self, container): 36 | core.PropertiesServiceInterface.__init__(self, container, "/Service", 37 | {HELLO_SVC : {'Name': 'AllJoyn'}}) 38 | 39 | 40 | def IntrospectionXml(self): 41 | return """ 42 | 43 | 44 | 45 | 46 | 47 | 48 | """ + core.PropertiesServiceInterface.IntrospectionXml(self) 49 | 50 | @dbus.service.method(HELLO_SVC, in_signature='', out_signature='s') 51 | def Greet(self): 52 | print("Hello, %s!" % self.Get(HELLO_SVC, "Name")) 53 | return "Hello, %s!" % self.Get(HELLO_SVC, "Name") 54 | 55 | 56 | class Hello(): 57 | def __init__(self, busname, name): 58 | 59 | self._id = uuid.uuid4().hex 60 | self._name = name 61 | 62 | about_props = { 63 | 64 | 'AppId': dbus.ByteArray(bytes.fromhex(self.id)), 65 | 'DefaultLanguage': 'en', 66 | 'DeviceName': self.name, 67 | 'DeviceId': self.id, 68 | 'AppName': 'Hello', 69 | 'Manufacturer': 'DeviceHive', 70 | 'DateOfManufacture': '2015-10-28', 71 | 'ModelNumber': 'example', 72 | 'SupportedLanguages': ['en'], 73 | 'Description': 'DeviceHive Alljoyn Hello Device', 74 | 'SoftwareVersion': '1.0', 75 | 'HardwareVersion': '1.0', 76 | 'SupportUrl': 'devicehive.com' 77 | 78 | } 79 | 80 | self._container = core.BusContainer(busname, DBUS_BUS_PATH + '/' + self.id) 81 | 82 | self._services = [ 83 | core.AboutService(self._container, about_props) 84 | ,HelloService(self._container) 85 | # ,core.ConfigService(self._container, self.name) 86 | ] 87 | 88 | print("Registered %s on dbus" % self.name) 89 | 90 | @property 91 | def id(self): 92 | return self._id 93 | 94 | @property 95 | def name(self): 96 | return self._name 97 | 98 | def publish(self, bridge): 99 | service = self._services[0] 100 | bridge.AddService(self._container.bus.get_name(), self._container.relative('').rstrip('/'), HELLO_SVC, 101 | # ignore_reply=True 102 | reply_handler=lambda id: print("ID: %s" % id), 103 | error_handler=lambda err: print("Error: %s" % err) 104 | ) 105 | 106 | print("Published %s on bridge" % self.name) 107 | 108 | 109 | def worker(): 110 | try: 111 | bridge = dbus.Interface(bus.get_object(DBUS_BRIDGE_NAME, DBUS_BRIDGE_PATH), 112 | dbus_interface='com.devicehive.alljoyn.bridge') 113 | plug = Hello(bus_name, 'Hello') 114 | plug.publish(bridge) 115 | except Exception as err: 116 | print(err) 117 | traceback.print_exc() 118 | os._exit(1) 119 | 120 | 121 | def main(): 122 | 123 | # init d-bus 124 | GObject.threads_init() 125 | dbus.mainloop.glib.threads_init() 126 | 127 | # start mainloop 128 | loop = GObject.MainLoop() 129 | 130 | worker_thread = threading.Thread(target=worker,) 131 | worker_thread.start() 132 | 133 | try: 134 | loop.run() 135 | except (KeyboardInterrupt, SystemExit): 136 | # for lamp in lamps: 137 | # lamp.deinit() 138 | loop.quit() 139 | worker_thread.join() 140 | 141 | if __name__ == "__main__": 142 | main() 143 | -------------------------------------------------------------------------------- /examples/alljoyn/hello2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import time, uuid 4 | import threading 5 | import traceback 6 | import sys 7 | import os 8 | import socket 9 | import collections 10 | import dbus.service 11 | from dbus.mainloop.glib import DBusGMainLoop 12 | from gi.repository import GObject 13 | 14 | scriptDir = os.path.dirname(os.path.realpath(__file__)) 15 | sys.path.append( scriptDir + "/common" ) 16 | 17 | import core 18 | 19 | DBusGMainLoop(set_as_default=True) 20 | 21 | 22 | DBUS_BRIDGE_NAME = 'com.devicehive.alljoyn.bridge' 23 | DBUS_BRIDGE_PATH = '/com/devicehive/alljoyn/bridge' 24 | 25 | DBUS_BUS_NAME = 'com.devicehive.alljoyn.SmartHome' 26 | DBUS_BUS_PATH = '/com/devicehive/alljoyn/SmartHome' 27 | 28 | HELLO_SVC = 'org.allseen.SmartHome.Hello2' 29 | 30 | bus = dbus.SystemBus() 31 | bus_name = dbus.service.BusName(DBUS_BUS_NAME, bus) 32 | 33 | 34 | class HelloService(core.PropertiesServiceInterface): 35 | def __init__(self, container): 36 | core.PropertiesServiceInterface.__init__(self, container, "/Service", 37 | {HELLO_SVC : {'Name': 'AllJoyn2'}}) 38 | 39 | 40 | def IntrospectionXml(self): 41 | return """ 42 | 43 | 44 | 45 | 46 | 47 | 48 | """ + core.PropertiesServiceInterface.IntrospectionXml(self) 49 | 50 | @dbus.service.method(HELLO_SVC, in_signature='', out_signature='s') 51 | def Greet(self): 52 | print("Hello2, %s!" % self.Get(HELLO_SVC, "Name")) 53 | return "Hello2, %s!" % self.Get(HELLO_SVC, "Name") 54 | 55 | 56 | class Hello(): 57 | def __init__(self, busname, name): 58 | 59 | self._id = uuid.uuid4().hex 60 | self._name = name 61 | 62 | about_props = { 63 | 64 | 'AppId': dbus.ByteArray(bytes.fromhex(self.id)), 65 | 'DefaultLanguage': 'en', 66 | 'DeviceName': self.name, 67 | 'DeviceId': self.id, 68 | 'AppName': 'Hello2', 69 | 'Manufacturer': 'DeviceHive', 70 | 'DateOfManufacture': '2015-10-28', 71 | 'ModelNumber': 'example', 72 | 'SupportedLanguages': ['en'], 73 | 'Description': 'DeviceHive Alljoyn Hello2 Device', 74 | 'SoftwareVersion': '1.0', 75 | 'HardwareVersion': '1.0', 76 | 'SupportUrl': 'devicehive.com' 77 | 78 | } 79 | 80 | self._container = core.BusContainer(busname, DBUS_BUS_PATH + '/' + self.id) 81 | 82 | self._services = [ 83 | core.AboutService(self._container, about_props) 84 | ,HelloService(self._container) 85 | # ,core.ConfigService(self._container, self.name) 86 | ] 87 | 88 | print("Registered %s on dbus" % self.name) 89 | 90 | @property 91 | def id(self): 92 | return self._id 93 | 94 | @property 95 | def name(self): 96 | return self._name 97 | 98 | def publish(self, bridge): 99 | service = self._services[0] 100 | bridge.AddService(self._container.bus.get_name(), self._container.relative('').rstrip('/'), HELLO_SVC, 101 | # ignore_reply=True 102 | reply_handler=lambda id: print("ID: %s" % id), 103 | error_handler=lambda err: print("Error: %s" % err) 104 | ) 105 | 106 | print("Published %s on bridge" % self.name) 107 | 108 | 109 | def worker(): 110 | try: 111 | bridge = dbus.Interface(bus.get_object(DBUS_BRIDGE_NAME, DBUS_BRIDGE_PATH), 112 | dbus_interface='com.devicehive.alljoyn.bridge') 113 | plug = Hello(bus_name, 'Hello2') 114 | plug.publish(bridge) 115 | except Exception as err: 116 | print(err) 117 | traceback.print_exc() 118 | os._exit(1) 119 | 120 | 121 | def main(): 122 | 123 | # init d-bus 124 | GObject.threads_init() 125 | dbus.mainloop.glib.threads_init() 126 | 127 | # start mainloop 128 | loop = GObject.MainLoop() 129 | 130 | worker_thread = threading.Thread(target=worker,) 131 | worker_thread.start() 132 | 133 | try: 134 | loop.run() 135 | except (KeyboardInterrupt, SystemExit): 136 | # for lamp in lamps: 137 | # lamp.deinit() 138 | loop.quit() 139 | worker_thread.join() 140 | 141 | if __name__ == "__main__": 142 | main() 143 | -------------------------------------------------------------------------------- /examples/alljoyn/lighting/terminal-light.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import time, uuid 4 | import threading 5 | import traceback 6 | import sys 7 | import os 8 | import socket 9 | import collections 10 | 11 | import dbus.service 12 | from dbus.mainloop.glib import DBusGMainLoop 13 | try: 14 | from gi.repository import GObject 15 | except ImportError: 16 | import gobject as GObject 17 | 18 | 19 | scriptDir = os.path.dirname(os.path.realpath(__file__)) 20 | sys.path.append( scriptDir + "/../common" ) 21 | 22 | import core, lighting as lsf 23 | 24 | DBusGMainLoop(set_as_default=True) 25 | 26 | 27 | # import json 28 | 29 | DBUS_BRIDGE_NAME = 'com.devicehive.alljoyn.bridge' 30 | DBUS_BRIDGE_PATH = '/com/devicehive/alljoyn/bridge' 31 | 32 | DBUS_BUS_NAME = 'org.allseen.LSF.LampService' 33 | DBUS_BUS_PATH = '/com/devicehive/alljoyn/allseen/LSF/Lamp' 34 | 35 | SVC_NAME = 'org.allseen.LSF.LampService' 36 | 37 | bus = dbus.SystemBus() 38 | bus_name = dbus.service.BusName(DBUS_BUS_NAME, bus) 39 | 40 | 41 | class Lamp(): 42 | def __init__(self, busname, name): 43 | 44 | self._id = '75b715e7e1a8411eb7c4b2719d3d0bc5' #uuid.uuid4().hex 45 | self._name = name 46 | 47 | about_props = { 48 | 49 | 'AppId': dbus.ByteArray(bytes.fromhex(self.id)), 50 | 'DefaultLanguage': 'en', 51 | 'DeviceName': self.name, 52 | 'DeviceId': self.id, 53 | 'AppName': 'TerminalLight', 54 | 'Manufacturer': 'DeviceHive', 55 | 'DateOfManufacture': '2015-07-09', 56 | 'ModelNumber': 'Simulated Light', 57 | 'SupportedLanguages': ['en'], 58 | 'Description': 'DeviceHive Alljoyn Bridge Device', 59 | 'SoftwareVersion': '1.0', 60 | 'HardwareVersion': '1.0', 61 | 'SupportUrl': 'devicehive.com' 62 | 63 | } 64 | 65 | self._container = core.BusContainer(busname, DBUS_BUS_PATH + '/' + self.id) 66 | 67 | lamp_service = lsf.LampService(self._container, self.name) 68 | 69 | self._services = [ 70 | core.AboutService(self._container, about_props), 71 | core.ConfigService(self._container, self.name), 72 | lamp_service 73 | 74 | ] 75 | 76 | print("Registered %s on dbus" % self.name) 77 | 78 | @property 79 | def id(self): 80 | return self._id 81 | 82 | @property 83 | def name(self): 84 | return self._name 85 | 86 | def publish(self, bridge): 87 | 88 | bridge.AddService(self._container.bus.get_name(), self._container.relative('').rstrip('/'), SVC_NAME, 89 | # ignore_reply=True 90 | reply_handler=lambda id: print("ID: %s" % id), 91 | error_handler=lambda err: print("Error: %s" % err) 92 | ) 93 | 94 | print("Published %s on bridge" % self.name) 95 | 96 | 97 | def worker(): 98 | try: 99 | 100 | bridge = dbus.Interface(bus.get_object(DBUS_BRIDGE_NAME, DBUS_BRIDGE_PATH), dbus_interface='com.devicehive.alljoyn.bridge') 101 | time.sleep(2) 102 | 103 | lamp = Lamp(bus_name, 'DeviceHive Terminal Light') 104 | lamp.publish(bridge) 105 | 106 | return 107 | 108 | except Exception as err: 109 | print(err) 110 | traceback.print_exc() 111 | os._exit(1) 112 | 113 | def main(): 114 | 115 | # init d-bus 116 | GObject.threads_init() 117 | dbus.mainloop.glib.threads_init() 118 | # lamps = [LampService(mac) for mac in argv] 119 | 120 | # start mainloop 121 | loop = GObject.MainLoop() 122 | 123 | worker_thread = threading.Thread(target=worker,) 124 | worker_thread.start() 125 | 126 | try: 127 | loop.run() 128 | except (KeyboardInterrupt, SystemExit): 129 | # for lamp in lamps: 130 | # lamp.deinit() 131 | loop.quit() 132 | worker_thread.join() 133 | 134 | if __name__ == "__main__": 135 | main() 136 | -------------------------------------------------------------------------------- /examples/alljoyn/readme.md: -------------------------------------------------------------------------------- 1 | Examples of using GPIO framework. AllJoyn framework. 2 | 3 | 4 | ### real-light.py 5 | Example of proxying BLE(bluetooth low energy) bulb into AllJoyn ligth service. This demo actually convert BLE bulb in to AllJoyn bulb! Change your BLE bulb mac addr in file(at line 486) to mac of your Satechi BLE bulb and run demo. You can modify this demo to control any other BLE bulb, you just need to find out GATT services and characteristic to turn it on and off. After demo has started, you can use any application that works with AllJoyn light service and control your BLE bulbs as AllJoyn bulbs. 6 | 7 | ### terminal-light.py 8 | Example of creating virtual bulb that shows own status in std output. Usage: just run this demo and use any application which can control AllJoyn bulbs. Application will find our virtual bulb as a real one and you can control it. On each turn on or off action demo will print text with current status to std output. 9 | -------------------------------------------------------------------------------- /examples/cloud-ble/cloud-ble.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "log" 7 | ) 8 | 9 | func main() { 10 | cloud, err := NewdbusWrapper("/com/devicehive/cloud", "com.devicehive.cloud") 11 | if err != nil { 12 | log.Panic(err) 13 | } 14 | 15 | ble, err := NewdbusWrapper("/com/devicehive/bluetooth", "com.devicehive.bluetooth") 16 | if err != nil { 17 | log.Panic(err) 18 | } 19 | 20 | ble.RegisterHandler("PeripheralDiscovered", 100, func(args ...interface{}) { 21 | cloud.SendNotification("PeripheralDiscovered", map[string]interface{}{ 22 | "mac": args[0].(string), 23 | "name": args[1].(string), 24 | "rssi": args[2].(int16), 25 | }) 26 | }) 27 | 28 | ble.RegisterHandler("PeripheralConnected", 100, func(args ...interface{}) { 29 | cloud.SendNotification("PeripheralConnected", map[string]interface{}{ 30 | "mac": args[0].(string), 31 | }) 32 | }) 33 | 34 | ble.RegisterHandler("PeripheralDisconnected", 100, func(args ...interface{}) { 35 | cloud.SendNotification("PeripheralDisconnected", map[string]interface{}{ 36 | "mac": args[0].(string), 37 | }) 38 | }) 39 | 40 | ble.RegisterHandler("NotificationReceived", 1, func(args ...interface{}) { 41 | cloud.SendNotification("NotificationReceived", map[string]interface{}{ 42 | "mac": args[0].(string), 43 | "uuid": args[1].(string), 44 | "value": args[2].(string), 45 | }) 46 | }) 47 | 48 | ble.RegisterHandler("IndicationReceived", 1, func(args ...interface{}) { 49 | cloud.SendNotification("IndicationReceived", map[string]interface{}{ 50 | "mac": args[0].(string), 51 | "uuid": args[1].(string), 52 | "value": args[2].(string), 53 | }) 54 | }) 55 | 56 | cloudHandlers := make(map[string]cloudCommandHandler) 57 | 58 | cloudHandlers["connect"] = func(p map[string]interface{}) (map[string]interface{}, error) { 59 | return nil, ble.BleConnect(p["mac"].(string)) 60 | } 61 | 62 | cloudHandlers["scan/start"] = func(map[string]interface{}) (map[string]interface{}, error) { 63 | return nil, ble.BleScanStart() 64 | } 65 | 66 | cloudHandlers["scan/stop"] = func(map[string]interface{}) (map[string]interface{}, error) { 67 | ble.BleScanStop() 68 | return nil, ble.BleScanStop() 69 | } 70 | 71 | cloudHandlers["gatt/read"] = func(p map[string]interface{}) (map[string]interface{}, error) { 72 | return ble.BleGattRead(p["mac"].(string), p["uuid"].(string)) 73 | } 74 | 75 | cloudHandlers["gatt/write"] = func(p map[string]interface{}) (map[string]interface{}, error) { 76 | _, err := ble.BleGattWrite(p["mac"].(string), p["uuid"].(string), p["value"].(string)) 77 | return nil, err 78 | } 79 | 80 | cloudHandlers["gatt/notifications"] = func(p map[string]interface{}) (map[string]interface{}, error) { 81 | _, err := ble.BleGattNotifications(p["mac"].(string), p["uuid"].(string), true) 82 | return nil, err 83 | } 84 | 85 | cloudHandlers["gatt/notifications/stop"] = func(p map[string]interface{}) (map[string]interface{}, error) { 86 | _, err := ble.BleGattNotifications(p["mac"].(string), p["uuid"].(string), false) 87 | return nil, err 88 | } 89 | 90 | cloudHandlers["gatt/indications"] = func(p map[string]interface{}) (map[string]interface{}, error) { 91 | _, err := ble.BleGattIndications(p["mac"].(string), p["uuid"].(string), true) 92 | return nil, err 93 | } 94 | 95 | cloudHandlers["gatt/indications/stop"] = func(p map[string]interface{}) (map[string]interface{}, error) { 96 | _, err := ble.BleGattIndications(p["mac"].(string), p["uuid"].(string), false) 97 | return nil, err 98 | } 99 | 100 | cloud.RegisterHandler("CommandReceived", 1, func(args ...interface{}) { 101 | id := args[0].(uint32) 102 | command := args[1].(string) 103 | params := args[2].(string) 104 | 105 | var dat map[string]interface{} 106 | b := []byte(params) 107 | json.Unmarshal(b, &dat) 108 | 109 | if h, ok := cloudHandlers[command]; ok { 110 | res, err := h(dat) 111 | 112 | if err != nil { 113 | cloud.CloudUpdateCommand(id, fmt.Sprintf("ERROR: %s", err.Error()), nil) 114 | } else { 115 | cloud.CloudUpdateCommand(id, "success", res) 116 | } 117 | 118 | } else { 119 | log.Printf("Unhandled command: %s", command) 120 | } 121 | }) 122 | 123 | select {} 124 | } 125 | -------------------------------------------------------------------------------- /examples/cloud-ble/queue.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "sync" 5 | 6 | "github.com/godbus/dbus" 7 | ) 8 | 9 | type signalHandlerFunc func(args ...interface{}) 10 | type cloudCommandHandler func(map[string]interface{}) (map[string]interface{}, error) 11 | 12 | type signalHandler struct { 13 | handler signalHandlerFunc 14 | priority uint64 15 | } 16 | 17 | type signalItem struct { 18 | handler signalHandler 19 | signal *dbus.Signal 20 | timestamp uint64 21 | } 22 | 23 | type signalQueue struct { 24 | items []signalItem 25 | queueSync sync.Mutex 26 | cond *sync.Cond 27 | } 28 | 29 | func (q signalQueue) Len() int { 30 | return len(q.items) 31 | } 32 | 33 | func (q signalQueue) Less(i, j int) bool { 34 | return q.items[i].timestamp*q.items[i].handler.priority > q.items[j].timestamp*q.items[j].handler.priority 35 | } 36 | 37 | func (q signalQueue) Swap(i, j int) { 38 | if (i > len(q.items)-1) || (j > len(q.items)-1) || (i < 0) || (j < 0) { 39 | return 40 | } 41 | 42 | q.items[i], q.items[j] = q.items[j], q.items[i] 43 | } 44 | 45 | func (q *signalQueue) Push(x interface{}) { 46 | q.cond.L.Lock() 47 | q.items = append(q.items, x.(signalItem)) 48 | q.cond.L.Unlock() 49 | q.cond.Signal() 50 | } 51 | 52 | func (q *signalQueue) Pop() interface{} { 53 | q.cond.L.Lock() 54 | 55 | old := q.items 56 | n := len(old) 57 | 58 | x := old[n-1] 59 | q.items = old[0 : n-1] 60 | 61 | q.cond.L.Unlock() 62 | q.cond.Signal() 63 | 64 | return x 65 | } 66 | -------------------------------------------------------------------------------- /examples/cloud-ble/readme.md: -------------------------------------------------------------------------------- 1 | Example of using BLE and cloud parts of IoT framework. This is a simple wrapper 2 | around GATT protocol. You can connect to any BLE device with GATT implementation 3 | from DeviceHive server. This demo shows how to implement it. It awaits for commands 4 | from cloud and perfoms it. This demo can be used as dedicated application if you 5 | need to control BLE device from cloud. 6 | 7 | ### Building 8 | Run `go build` 9 | 10 | ### Usage 11 | Run application, then you can send commands from cloud. Command list: 12 | 13 | - `connect` - connect to BLE device 14 | - `scan/start` - start scanning, on each found device app will send `PeripheralDiscovered` notification 15 | - `scan/stop` - stop scanning 16 | - `gatt/read` - read characteristic 17 | - `gatt/write` - write characteristic 18 | - `gatt/notifications` - subscribe on characteristic notification. On each BLE notification `NotificationReceived` cloud notification will be sent 19 | - `gatt/notifications/stop` - stop watching on characteristic notification 20 | - `gatt/indications` - subscribe on characteristic indication. On each BLE indication `IndicationReceived` cloud notification will be sent 21 | - `gatt/indications/stop` - stop watching on characteristic indication 22 | 23 | You can receive these notfications from app to cloud: 24 | 25 | - `PeripheralDiscovered` - each time when app founds new BLE device in air 26 | - `PeripheralConnected` - when app succefuly connects to BLE device 27 | - `PeripheralDisconnected` - when app lost connection with BLE device, including normal disconnect. 28 | - `NotificationReceived` - on each BLE notification 29 | - `IndicationReceived` - on each BLE indication 30 | -------------------------------------------------------------------------------- /examples/cloud-ble/wrapper.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "container/heap" 5 | "encoding/json" 6 | "fmt" 7 | "log" 8 | "strings" 9 | "sync" 10 | "time" 11 | 12 | "github.com/godbus/dbus" 13 | ) 14 | 15 | const QueueCapacity = 2048 16 | 17 | type dbusWrapper struct { 18 | conn *dbus.Conn 19 | path, iface string 20 | handlers map[string]signalHandler 21 | handlersSync sync.Mutex 22 | 23 | queue *signalQueue 24 | } 25 | 26 | func NewdbusWrapper(path string, iface string) (*dbusWrapper, error) { 27 | d := new(dbusWrapper) 28 | 29 | conn, err := dbus.SystemBus() 30 | if err != nil { 31 | conn, err = dbus.SessionBus() 32 | if err != nil { 33 | log.Panic(err) 34 | } 35 | } 36 | 37 | d.handlers = make(map[string]signalHandler) 38 | 39 | d.conn = conn 40 | d.path = path 41 | d.iface = iface 42 | d.queue = &signalQueue{cond: &sync.Cond{L: &sync.Mutex{}}} 43 | heap.Init(d.queue) 44 | 45 | filter := fmt.Sprintf("type='signal',path='%[1]s',interface='%[2]s',sender='%[2]s'", path, iface) 46 | log.Printf("Filter: %s", filter) 47 | 48 | conn.Object("org.freedesktop.DBus", "/org/freedesktop/DBus").Call("org.freedesktop.DBus.AddMatch", 0, filter) 49 | 50 | go func() { 51 | ch := make(chan *dbus.Signal, 2*QueueCapacity) 52 | conn.Signal(ch) 53 | for signal := range ch { 54 | if !((strings.Index(signal.Name, iface) == 0) && (string(signal.Path) == path)) { 55 | continue 56 | } 57 | if val, ok := d.handlers[signal.Name]; ok { 58 | for d.queue.Len() > QueueCapacity-1 { 59 | item := heap.Remove(d.queue, d.queue.Len()-1) 60 | log.Printf("Removing %+v from queue", item) 61 | } 62 | heap.Push(d.queue, signalItem{handler: val, signal: signal, timestamp: uint64(time.Now().Unix())}) 63 | } else { 64 | log.Printf("Unhandled signal: %s", signal.Name) 65 | } 66 | } 67 | }() 68 | 69 | go func() { 70 | for { 71 | d.queue.cond.L.Lock() 72 | for d.queue.Len() == 0 { 73 | d.queue.cond.Wait() 74 | } 75 | d.queue.cond.L.Unlock() 76 | item := heap.Pop(d.queue).(signalItem) 77 | item.handler.handler(item.signal.Body...) 78 | } 79 | }() 80 | 81 | return d, nil 82 | } 83 | 84 | func (d *dbusWrapper) call(name string, args ...interface{}) *dbus.Call { 85 | c := d.conn.Object(d.iface, dbus.ObjectPath(d.path)).Call(d.iface+"."+name, 0, args...) 86 | 87 | if c.Err != nil { 88 | log.Printf("Error calling %s: %s", name, c.Err) 89 | } 90 | 91 | return c 92 | } 93 | 94 | func (d *dbusWrapper) SendNotification(name string, parameters interface{}) { 95 | b, _ := json.Marshal(parameters) 96 | // log.Printf("Sending cloud notification: %s", string(b)) 97 | d.call("SendNotification", name, string(b)) 98 | } 99 | 100 | func (d *dbusWrapper) RegisterHandler(signal string, priority uint64, h signalHandlerFunc) { 101 | d.handlersSync.Lock() 102 | d.handlers[d.iface+"."+signal] = signalHandler{priority: priority, handler: h} 103 | d.handlersSync.Unlock() 104 | } 105 | 106 | func (d *dbusWrapper) BleScanStart() error { 107 | c := d.call("ScanStart") 108 | return c.Err 109 | } 110 | 111 | func (d *dbusWrapper) BleConnect(mac string) error { 112 | c := d.call("Connect", mac) 113 | return c.Err 114 | } 115 | 116 | func (d *dbusWrapper) BleScanStop() error { 117 | c := d.call("ScanStop") 118 | return c.Err 119 | } 120 | 121 | func (d *dbusWrapper) BleGattRead(mac, uuid string) (map[string]interface{}, error) { 122 | s := "" 123 | err := d.call("GattRead", mac, uuid).Store(&s) 124 | 125 | res := map[string]interface{}{ 126 | "value": s, 127 | } 128 | 129 | return res, err 130 | } 131 | 132 | func (d *dbusWrapper) BleGattWrite(mac, uuid, message string) (map[string]interface{}, error) { 133 | c := d.call("GattWrite", mac, uuid, message) 134 | return nil, c.Err 135 | } 136 | 137 | func (d *dbusWrapper) BleGattNotifications(mac, uuid string, enable bool) (map[string]interface{}, error) { 138 | c := d.call("GattNotifications", mac, uuid, enable) 139 | return nil, c.Err 140 | } 141 | 142 | func (d *dbusWrapper) BleGattIndications(mac, uuid string, enable bool) (map[string]interface{}, error) { 143 | c := d.call("GattIndications", mac, uuid, enable) 144 | return nil, c.Err 145 | } 146 | 147 | func (d *dbusWrapper) CloudUpdateCommand(id uint32, status string, result map[string]interface{}) { 148 | b, _ := json.Marshal(result) 149 | d.call("UpdateCommand", id, status, string(b)) 150 | } 151 | -------------------------------------------------------------------------------- /examples/cpu-stats/cpu-stats.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "os" 6 | "time" 7 | 8 | "github.com/devicehive/IoT-framework/godbus-helpers/cloud" 9 | "github.com/shirou/gopsutil/cpu" 10 | "github.com/shirou/gopsutil/mem" 11 | ) 12 | 13 | func main() { 14 | cloud, err := cloud.NewDbusForComDevicehiveCloud() 15 | if err != nil { 16 | log.Panic(err) 17 | } 18 | 19 | h, _ := os.Hostname() 20 | 21 | for { 22 | time.Sleep(time.Second) 23 | c, err := cpu.CPUPercent(time.Second, false) 24 | if err != nil { 25 | log.Panic(err) 26 | } 27 | 28 | v, err := mem.VirtualMemory() 29 | if err != nil { 30 | log.Panic(err) 31 | } 32 | 33 | if len(c) > 0 { 34 | cloud.SendNotification("stats", map[string]interface{}{ 35 | "cpu-usage": c[0], 36 | "memory-total": v.Total, 37 | "memory-free": v.Free, 38 | "name": h, 39 | }, 1) 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /examples/dash-xylo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "strconv" 6 | "time" 7 | ) 8 | 9 | type melody struct { 10 | w *dbusWrapper 11 | } 12 | 13 | func NewMelody(w *dbusWrapper) *melody { 14 | m := &melody{w: w} 15 | 16 | return m 17 | } 18 | 19 | func (m *melody) Play(mac string, s string, bpm int) (err error) { 20 | notes := map[rune]string{'c': "060000", 21 | 'd': "0603e8", 22 | 'e': "0607d0", 23 | 'f': "060bb8", 24 | 'g': "060fa0", 25 | 'a': "061388", 26 | 'b': "061770", 27 | 'C': "061b58"} 28 | 29 | noteLen := 1 30 | noteLenStr := "" 31 | prev := '\x00' 32 | m.w.GattWriteNoResp(mac, "af230002-879d-6186-1f49-deca0e85d9c1", "c804") 33 | for _, c := range s { 34 | log.Printf("c = %d", c) 35 | note, ok := notes[c] 36 | switch { 37 | case '0' <= c && c <= '9': 38 | if '0' <= prev && prev <= '9' { 39 | noteLenStr = noteLenStr + string(c) 40 | } else { 41 | noteLenStr = string(c) 42 | } 43 | prev = c 44 | continue 45 | case (ok || (c == '*')): 46 | if '0' <= prev && prev <= '9' { 47 | l, _ := strconv.ParseInt(noteLenStr, 0, 32) 48 | noteLen = int(l) 49 | log.Printf("Note length: %d", noteLen) 50 | } 51 | if ok { 52 | log.Printf("Playing %s", note) 53 | m.w.GattWriteNoResp(mac, "af230002-879d-6186-1f49-deca0e85d9c1", note) 54 | m.w.GattWriteNoResp(mac, "af230002-879d-6186-1f49-deca0e85d9c1", "10") 55 | } 56 | } 57 | prev = c 58 | wait := ((bpm * 1000 / 60) * 4 / noteLen) 59 | log.Printf("Wait: %d", wait) 60 | time.Sleep(time.Duration(wait) * time.Millisecond) 61 | } 62 | 63 | return nil 64 | } 65 | 66 | func main() { 67 | m := new(melody) 68 | m.Play("xxx", "1c2dd4eeee8ffffffff16gggggggggggggggg", 60) 69 | } 70 | -------------------------------------------------------------------------------- /examples/echo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import dbus 4 | import json 5 | from dbus.mainloop.glib import DBusGMainLoop 6 | from gi.repository import GObject 7 | 8 | DBusGMainLoop(set_as_default=True) 9 | 10 | def get_cloud(): 11 | obj = dbus.SystemBus().get_object("com.devicehive.cloud", '/com/devicehive/cloud') 12 | return dbus.Interface(obj, "com.devicehive.cloud") 13 | 14 | cloud = get_cloud() 15 | def command_received(id, name, parameters): 16 | print("new Command received {id:%s, name:%s, parameters:%s}" % (id, name, parameters)) 17 | try: 18 | p = json.loads(parameters) 19 | s = {"command": name, "id": id, "parameters": p} 20 | cloud.SendNotification("echo", json.dumps(s), 0) 21 | cloud.UpdateCommand(dbus.UInt64(id), "OK", parameters) 22 | except dbus.DBusException as e: 23 | print(e) 24 | 25 | def main(): 26 | cloud.connect_to_signal("CommandReceived", command_received) 27 | print("ready to process commands...") 28 | GObject.MainLoop().run() 29 | 30 | if __name__ == '__main__': 31 | try: 32 | main() 33 | except KeyboardInterrupt: 34 | print("stopped") 35 | -------------------------------------------------------------------------------- /examples/enocean/README.md: -------------------------------------------------------------------------------- 1 | Example of using EnOcean part of IoT framework. 2 | 3 | 4 | # enocean-dbus-ble.py 5 | This example turns Bluetooth bulb on/off by enocean switch. It recived data from EnOcean, parse it and apply corresponding action to BLE bulb 6 | -------------------------------------------------------------------------------- /examples/enocean/enocean-dbus-ble.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import dbus 4 | import time 5 | import sys 6 | from dbus.mainloop.glib import DBusGMainLoop 7 | from gi.repository import GObject 8 | import json 9 | 10 | DBUS_BUS_ENOCEAN_NAME = 'com.devicehive.enocean' 11 | DBUS_BUS_BLE_NAME = 'com.devicehive.bluetooth' 12 | 13 | SWITCH_ADDRESS = '00:2A:1A:B8' 14 | BULB_ADDRESS = '20:C3:8F:F5:49:B4' 15 | 16 | bulb_on_value = '0f0d0300ffffffc800c800c8000059ffff' 17 | bulb_off_value = '0f0d0300ffffff0000c800c8000091ffff' 18 | bulb_handle = 0x002b 19 | 20 | DBusGMainLoop(set_as_default=True) 21 | 22 | 23 | def init_bulb(): 24 | bus = dbus.SystemBus() 25 | ble_manager = bus.get_object(DBUS_BUS_BLE_NAME, '/') 26 | bulb_path = ble_manager.Create(BULB_ADDRESS, dbus_interface='com.devicehive.BluetoothManager') 27 | return bus.get_object(DBUS_BUS_BLE_NAME, bulb_path) 28 | 29 | bulb = init_bulb() 30 | 31 | 32 | def turn_bulb(on): 33 | if on: 34 | print('ON') 35 | bulb.Write(bulb_handle, bulb_on_value, False, dbus_interface='com.devicehive.BluetoothDevice') 36 | else: 37 | print('OFF') 38 | bulb.Write(bulb_handle, bulb_off_value, False, dbus_interface='com.devicehive.BluetoothDevice') 39 | 40 | 41 | def message_received(value): 42 | res = json.loads(value) 43 | if res['sender'] == SWITCH_ADDRESS: 44 | if res['R1']['raw_value'] == 2: 45 | turn_bulb(True) 46 | 47 | if res['R1']['raw_value'] == 3: 48 | turn_bulb(False) 49 | 50 | 51 | def main(): 52 | bus = dbus.SystemBus() 53 | enocean_manager = bus.get_object(DBUS_BUS_ENOCEAN_NAME, '/com/devicehive/enocean') 54 | enocean = dbus.Interface(enocean_manager, DBUS_BUS_ENOCEAN_NAME) 55 | enocean.connect_to_signal('message_received', message_received) 56 | 57 | try: 58 | GObject.MainLoop().run() 59 | except KeyboardInterrupt: 60 | pass 61 | 62 | 63 | if __name__ == '__main__': 64 | main() -------------------------------------------------------------------------------- /examples/gpio/adc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import dbus 4 | from dbus.mainloop.glib import DBusGMainLoop 5 | from gi.repository import GObject 6 | import array 7 | import threading 8 | 9 | DBusGMainLoop(set_as_default=True) 10 | 11 | def get_cloud(): 12 | return dbus.Interface(dbus.SystemBus().get_object("com.devicehive.cloud", '/com/devicehive/cloud'), "com.devicehive.cloud") 13 | 14 | cloud = get_cloud() 15 | 16 | def adc_changed(port, value): 17 | print("pin_value_changed port: {} value: {}".format(port, value)) 18 | s = "{\"notification\" : \"emg\", \"parameters\": \"%s\"}" % value 19 | cloud.SendNotification("emg", s, 0) 20 | 21 | def main(): 22 | pin_in = dbus.SystemBus().get_object("com.devicehive.gpio", 23 | "/com/devicehive/gpio/PIN85") 24 | pin_in.init("500", dbus_interface='com.devicehive.gpio.GpioPin') 25 | pin_in.connect_to_signal("pin_value_changed", adc_changed) 26 | 27 | GObject.MainLoop().run() 28 | try: 29 | GObject.MainLoop().run() 30 | except (KeyboardInterrupt, SystemExit): 31 | pin_in.deinit() 32 | 33 | if __name__ == '__main__': 34 | main() 35 | -------------------------------------------------------------------------------- /examples/gpio/gpio-blink-python: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | # Python GPIO to DBUS simple client 4 | 5 | import dbus 6 | import time 7 | import sys 8 | 9 | def main(): 10 | if len(sys.argv) < 2: 11 | print("Choose one of this port: ", [str(x) for x in 12 | dbus.SystemBus().get_object("com.devicehive.gpio", 13 | "/com/devicehive/gpio").list( 14 | dbus_interface='com.devicehive.gpio.GpioService')]) 15 | return 16 | for i in range(1, len(sys.argv)): 17 | pin = dbus.Interface(dbus.SystemBus().get_object("com.devicehive.gpio", 18 | "/com/devicehive/gpio/{}".format(sys.argv[i])), dbus_interface='com.devicehive.gpio.GpioPin') 19 | pin.init("out") 20 | for _x in range(0, 5): 21 | pin.set() 22 | time.sleep(0.05) 23 | pin.clear() 24 | time.sleep(0.1) 25 | pin.deinit() 26 | 27 | 28 | if __name__ == "__main__": 29 | main() 30 | -------------------------------------------------------------------------------- /examples/gpio/gpio-click-python: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | # Python GPIO to DBUS simple client switch 4 | 5 | import dbus 6 | import time 7 | import sys 8 | from dbus.mainloop.glib import DBusGMainLoop 9 | from gi.repository import GObject 10 | 11 | def pin_value_changed(port, value): 12 | global pin_out 13 | print("pin_value_changed port: {} value: {}".format(port, value)) 14 | pin_out.set_value(str(int(value) ^ 1), dbus_interface='com.devicehive.gpio.GpioPin') 15 | 16 | 17 | def main(): 18 | global pin_out 19 | if len(sys.argv) < 3: 20 | print("Choose one of this port: ", [str(x) for x in 21 | dbus.SystemBus().get_object("com.devicehive.gpio", 22 | "/com/devicehive/gpio").list( 23 | dbus_interface='com.devicehive.gpio.GpioService')]) 24 | return 25 | 26 | DBusGMainLoop(set_as_default=True) 27 | 28 | pin_in = dbus.SystemBus().get_object("com.devicehive.gpio.GpioPin", 29 | "/com/devicehive/gpio/{}".format(sys.argv[1])) 30 | pin_in.init("both", dbus_interface='com.devicehive.gpio.GpioPin') 31 | pin_in.connect_to_signal("pin_value_changed", pin_value_changed) 32 | 33 | pin_out = dbus.SystemBus().get_object("com.devicehive.gpio.GpioPin", 34 | "/com/devicehive/gpio/{}".format(sys.argv[2])) 35 | pin_out.init("out", dbus_interface='com.devicehive.gpio.GpioPin') 36 | 37 | try: 38 | GObject.MainLoop().run() 39 | except KeyboardInterrupt: 40 | pass 41 | pin_in.deinit(dbus_interface='com.devicehive.gpio.GpioPin') 42 | pin_out.deinit(dbus_interface='com.devicehive.gpio.GpioPin') 43 | 44 | 45 | if __name__ == "__main__": 46 | main() 47 | -------------------------------------------------------------------------------- /examples/gpio/gpio-switch-python: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | # Python GPIO to DBUS simple client switch 4 | 5 | import dbus 6 | 7 | import os 8 | import yaml 9 | import sys 10 | from dbus.mainloop.glib import DBusGMainLoop 11 | from gi.repository import GObject 12 | 13 | def update_state(): 14 | global leds 15 | global state 16 | for x in range(0, 8): 17 | if x == state: 18 | leds[x].clear(dbus_interface='com.devicehive.gpio.GpioPin'); 19 | else: 20 | leds[x].set(dbus_interface='com.devicehive.gpio.GpioPin'); 21 | 22 | 23 | def right_click(port, value): 24 | global state 25 | if value == "0": 26 | return 27 | if state == 7: 28 | state = 0 29 | else: 30 | state += 1 31 | update_state() 32 | 33 | 34 | def left_click(port, value): 35 | global state 36 | if value == "0": 37 | return 38 | if state == 0: 39 | state = 7 40 | else: 41 | state -= 1 42 | update_state() 43 | 44 | 45 | def get_led(led_pin): 46 | led = dbus.SystemBus().get_object("com.devicehive.gpio.GpioPin", 47 | "/com/devicehive/gpio/{}".format(led_pin)) 48 | led.init("out", dbus_interface='com.devicehive.gpio.GpioPin') 49 | return led 50 | 51 | 52 | def get_button(button_pin, cb): 53 | button = dbus.SystemBus().get_object("com.devicehive.gpio.GpioPin", 54 | "/com/devicehive/gpio/{}".format(button_pin)) 55 | button.init("both", dbus_interface='com.devicehive.gpio.GpioPin') 56 | button.connect_to_signal("pin_value_changed", cb) 57 | return button 58 | 59 | 60 | def main(): 61 | global leds 62 | global state 63 | DBusGMainLoop(set_as_default=True) 64 | 65 | pdir = os.path.realpath(__file__) + "-profiles" 66 | control = dbus.SystemBus().get_object("com.devicehive.gpio", 67 | "/com/devicehive/gpio") 68 | 69 | try: 70 | with open("/sys/firmware/devicetree/base/model", 'r') as hwid: 71 | model = str(hwid.read()).rstrip("\0") 72 | yamlpath = os.path.join(pdir, "{}.yaml".format(model)) 73 | 74 | try: 75 | with open(yamlpath) as yf: 76 | try: 77 | pin_map = yaml.load(yf) 78 | if not pin_map: 79 | raise yaml.scanner.ScannerError("Empty file") 80 | else: 81 | control.clear(dbus_interface='com.devicehive.gpio') 82 | control.add_profile(pin_map, dbus_interface='com.devicehive.gpio') 83 | except yaml.scanner.ScannerError: 84 | raise SyntaxError("File does not contain yaml profile.") 85 | except FileExistsError: 86 | raise 87 | except IOError: 88 | raise FileNotFoundError("Profile file for {} not found.".format(model)) 89 | 90 | except IOError: 91 | raise SystemError("Board not found.") 92 | 93 | 94 | button_1 = get_button("BUTTON1", left_click) 95 | button_2 = get_button("BUTTON2", right_click) 96 | 97 | leds = list() 98 | state = 0 99 | for x in range(1, 9): 100 | leds.append(get_led("LED{}".format(x))) 101 | update_state() 102 | try: 103 | GObject.MainLoop().run() 104 | except KeyboardInterrupt: 105 | for led in leds: 106 | led.deinit() 107 | button_1.deinit(dbus_interface='com.devicehive.gpio.GpioPin') 108 | button_2.deinit(dbus_interface='com.devicehive.gpio.GpioPin') 109 | 110 | 111 | if __name__ == "__main__": 112 | main() 113 | -------------------------------------------------------------------------------- /examples/gpio/gpio-switch-python-profiles/Raspberry Pi 2 Model B.yaml: -------------------------------------------------------------------------------- 1 | BUTTON1: 2 2 | BUTTON2: 5 3 | LED1: 4 4 | LED2: 14 5 | LED3: 15 6 | LED4: 17 7 | LED5: 18 8 | LED6: 27 9 | LED7: 22 10 | LED8: 23 11 | -------------------------------------------------------------------------------- /examples/gpio/gpio-switch-python-profiles/TI AM335x BeagleBone.yaml: -------------------------------------------------------------------------------- 1 | BUTTON1: 66 2 | BUTTON2: 67 3 | LED1: 69 4 | LED2: 68 5 | LED3: 45 6 | LED4: 44 7 | LED5: 23 8 | LED6: 26 9 | LED7: 47 10 | LED8: 46 11 | -------------------------------------------------------------------------------- /examples/gpio/readme.md: -------------------------------------------------------------------------------- 1 | Examples of using GPIO framework. 2 | 3 | #### ADC 4 | adc.py 5 | This programm does initialize one of analog pin and send data to cloud 6 | ```bash 7 | adc.py 8 | ``` 9 | GPIO and clound services are require for launch. 10 | 11 | 12 | #### GPIO Blink 13 | gpio-blink-python.py 14 | 15 | This program does blinking of the LED lamps connected to corresponding gpio pins. 16 | 17 | ```bash 18 | gpio-blink-python [PIN#] ... 19 | ``` 20 | Where PIN# is one of pins on the device connected to LEDs. To list all available pins run app without parameters: 21 | ```bash 22 | gpio-blink-python 23 | ``` 24 | 25 | Example: 26 | ```bash 27 | gpio-blink-python PIN9 PIN10 PIN11 PIN12 PIN13 PIN14 PIN15 PIN16 28 | ``` 29 | 30 | 31 | #### GPIO Click 32 | gpio-click-python.py 33 | 34 | This program turns LED on/off when on a button click. 35 | 36 | ```bash 37 | gpio-click-python BUTTON_PIN LED_PIN 38 | ``` 39 | Where PIN# is one of pins on the device connected to LEDs. To list all available pins run app without parameters: 40 | ```bash 41 | gpio-click-python 42 | ``` 43 | 44 | Example: 45 | ```bash 46 | gpio-click-python PIN9 PIN10 47 | ``` 48 | 49 | 50 | #### GPIO Switch 51 | gpio-switch-python.py 52 | 53 | This program uses 2 buttons to control a set of LEDs. One of the LEDs is turned off and buttons shift turned off led left or right. 54 | It also demonstrate how to use custom profiles for GPIO. 55 | `gpio-switch-python-profiles` directory contains custom profiles for this example. 56 | 57 | ```bash 58 | gpio-switch-python 59 | ``` 60 | 61 | > It is important to connect LEDs and buttons to specific pins for this example. For BBB use 62 | > Buttons: PIN7, PIN8 63 | > LEDS: PIN9, PIN10, PIN11, PIN12, PIN13, PIN14, PIN15, PIN16 64 | -------------------------------------------------------------------------------- /examples/lamp.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import dbus 4 | from dbus.mainloop.glib import DBusGMainLoop 5 | from gi.repository import GObject 6 | import array 7 | 8 | DBusGMainLoop(set_as_default=True) 9 | 10 | def get_ble(): 11 | return dbus.Interface(dbus.SystemBus().get_object("com.devicehive.bluetooth", '/com/devicehive/bluetooth'), "com.devicehive.bluetooth") 12 | 13 | ble = get_ble() 14 | def device_discovered(mac, name, rssi): 15 | if (name == 'SATECHILED-0'): 16 | print("Discovered %s (%s) " % (mac, name)) 17 | ble.ScanStop(ignore_reply=True) 18 | ble.Disconnect(mac, ignore_reply=True) 19 | ble.Connect(mac, False, ignore_reply=True) 20 | 21 | def device_connected(mac): 22 | print("Connected to %s" % (mac)) 23 | try: 24 | ble.GattWrite(mac, "fff3", "0f0d0300ffffff0000c800c8000091ffff", ignore_reply=True) 25 | # ble.GattWrite(mac, "fff3", "0f0d0300ffffffc800c800c8000059ffff", ignore_reply=True) 26 | except dbus.DBusException as e: 27 | print(e) 28 | 29 | def main(): 30 | print('Scanning ...') 31 | ble.connect_to_signal("PeripheralDiscovered", device_discovered) 32 | ble.connect_to_signal("PeripheralConnected", device_connected) 33 | ble.ScanStart(ignore_reply=True) 34 | 35 | GObject.MainLoop().run() 36 | 37 | if __name__ == '__main__': 38 | main() 39 | -------------------------------------------------------------------------------- /examples/pod.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import dbus 4 | from dbus.mainloop.glib import DBusGMainLoop 5 | from gi.repository import GObject 6 | import array 7 | import time 8 | 9 | DBusGMainLoop(set_as_default=True) 10 | 11 | def get_ble(): 12 | obj = dbus.SystemBus().get_object("com.devicehive.bluetooth", "/com/devicehive/bluetooth") 13 | return dbus.Interface(obj, "com.devicehive.bluetooth") 14 | 15 | ble = get_ble() 16 | def device_discovered(mac, name, rssi): 17 | print("Discovered %s" % (name)) 18 | if (name == 'POD'): 19 | ble.ScanStop() 20 | time.sleep(5) 21 | ble.Connect(mac, False) 22 | 23 | def device_connected(mac): 24 | print("Connected to %s" % (mac)) 25 | try: 26 | ble.GattWrite(mac, "ffb2", "aa550f038401e0") 27 | ble.GattNotifications(mac, "ffb2", True) 28 | 29 | except dbus.DBusException as e: 30 | print(e) 31 | 32 | def notification_received(mac, uuid, message): 33 | print("MAC: %s, UUID: %s, Received: %s" % (mac, uuid, message)) 34 | 35 | def main(): 36 | ble.connect_to_signal("PeripheralDiscovered", device_discovered) 37 | ble.connect_to_signal("PeripheralConnected", device_connected) 38 | ble.connect_to_signal("NotificationReceived", notification_received) 39 | 40 | ble.ScanStart() 41 | 42 | GObject.MainLoop().run() 43 | 44 | if __name__ == '__main__': 45 | main() 46 | -------------------------------------------------------------------------------- /examples/readme.md: -------------------------------------------------------------------------------- 1 | ## Examples for DeviceHive D-Bus Framework 2 | 3 | This directory contains various examples of IoT framework usage. 4 | To run each of them you have to install IoT framework on target machine. 5 | Python examples might be run as is, `go` examples should be compiled first. 6 | 7 | ### echo.py 8 | Simple application which uses cloud part of IoT framework. It replyes with echoes 9 | on each sent command. Usage: run the `echo.py`, send command to device (for example 10 | via web admin page) and check command result - it should be the same. At the same 11 | time corresponding "echo" notification should be sent. 12 | 13 | ### cpu-stats.go 14 | Simple application which reads current system state (CPU, memory usage) and sends 15 | it to cloud with some period of time. Usage: run this demo and check DeviceHive 16 | server, it should receive corresponding "stats" notifications. 17 | 18 | ### dash-xylo.go 19 | Simple application that sends some melody for playback to Play-I robot. 20 | These robots uses BLE for connectivity purpose and they have special characterstic. 21 | To make the robot play recorder melody you need to write special value to this 22 | characteristic. 23 | 24 | ### heart-pulse-demo.go 25 | TODO 26 | 27 | ### iot-demo.go 28 | TODO 29 | 30 | ### lamp.py 31 | Simple application which uses Bluetooth low energy part of IoT Framework. 32 | It scans for BLE bulb with name `DELIGHT` and once it found sends command 33 | to turn it ON or OFF. Usage: uncomment action that you need to perform at 34 | line 22-23 and run this demo. 35 | 36 | ### pod.py 37 | TODO 38 | 39 | ### scales.py 40 | TODO 41 | 42 | ### sensortag.py 43 | Simple application which shows how to connect to TI SensorTag. Once connected it 44 | enables accelerometer, receives notification with accelerometer data and prints it 45 | to standard output. Usage: run this demo on machine with BLE, turn on TI Sensor 46 | tag and demo will print accelerometer data. 47 | 48 | ### Directories alljoyn, cloud-ble, enocean, gpio 49 | See corresponding readme file inside of each directory. 50 | -------------------------------------------------------------------------------- /examples/scales.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import dbus 4 | from dbus.mainloop.glib import DBusGMainLoop 5 | from gi.repository import GObject 6 | import array 7 | import time 8 | 9 | DBusGMainLoop(set_as_default=True) 10 | 11 | def get_ble(): 12 | obj = dbus.SystemBus().get_object("com.devicehive.bluetooth", "/com/devicehive/bluetooth") 13 | return dbus.Interface(obj, "com.devicehive.bluetooth") 14 | 15 | ble = get_ble() 16 | def device_discovered(mac, name, rssi): 17 | print("Discovered %s %s" % (name, mac)) 18 | if (mac == 'e4c95cc8bbc1'): 19 | print("Connecting") 20 | ble.ScanStop() 21 | ble.Connect(mac, False) 22 | time.sleep(10) 23 | ble.ScanStart() 24 | 25 | def device_connected(mac): 26 | print("Connected to %s" % (mac)) 27 | try: 28 | ble.GattIndications(mac, "299d64102f6111e281c10800200c9a66", True) 29 | 30 | except dbus.DBusException as e: 31 | print(e) 32 | 33 | def indication_received(mac, uuid, message): 34 | print("MAC: %s, UUID: %s, Received: %s" % (mac, uuid, message)) 35 | 36 | def main(): 37 | ble.connect_to_signal("PeripheralDiscovered", device_discovered) 38 | ble.connect_to_signal("PeripheralConnected", device_connected) 39 | ble.connect_to_signal("IndiacationReceived", indication_received) 40 | 41 | ble.ScanStart() 42 | 43 | GObject.MainLoop().run() 44 | 45 | if __name__ == '__main__': 46 | main() 47 | -------------------------------------------------------------------------------- /examples/sensortag-cloud.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import os, sys, time, threading, traceback 4 | import struct, math, json 5 | import dbus.service 6 | from dbus.mainloop.glib import DBusGMainLoop 7 | from gi.repository import GObject 8 | 9 | DBusGMainLoop(set_as_default=True) 10 | 11 | ble = dbus.Interface(dbus.SystemBus().get_object("com.devicehive.bluetooth", "/com/devicehive/bluetooth"), "com.devicehive.bluetooth") 12 | cloud = dbus.Interface(dbus.SystemBus().get_object("com.devicehive.cloud", "/com/devicehive/cloud"), "com.devicehive.cloud") 13 | 14 | sensors = {} 15 | DEFAULT_PRIORITY = 100 16 | 17 | def accelerometer_handler(mac, uuid, message): 18 | data = bytearray.fromhex(message) 19 | data = struct.unpack('<3b', data) 20 | 21 | x = data[0] / 64.0 22 | y = data[1] / 64.0 23 | z = data[2] / -64.0 24 | 25 | absolute = math.sqrt(x*x + y*y + z*z) 26 | return {'x': x, 'y': y, 'z': z, 'abs': absolute} 27 | 28 | def accelerometer_CC2650_handler(mac, uuid, message): 29 | data = bytearray.fromhex(message) 30 | data = struct.unpack('<3h', data[6:12]) 31 | 32 | x = data[0] * 2.0 / 32768.0 33 | y = data[1] * 2.0 / 32768.0 34 | z = data[2] * 2.0 / 32768.0 35 | 36 | absolute = math.sqrt(x*x + y*y + z*z) 37 | return {'x': x, 'y': y, 'z': z, 'abs': absolute} 38 | 39 | 40 | init = { 41 | 'SensorTag' : { 42 | 'F000AA1104514000b000000000000000' : { 43 | 'notification' : 'accelerometer', 44 | 'write': [('F000AA1204514000b000000000000000', '01'), 45 | ('F000AA1304514000b000000000000000', 'A0')], 46 | 'handler': accelerometer_handler 47 | }, 48 | }, 49 | 'CC2650 SensorTag' : { 50 | 'F000AA8104514000b000000000000000' : { 51 | 'notification' : 'accelerometer', 52 | 'write': [('F000AA8204514000b000000000000000', '3800'), 53 | ('F000AA8304514000b000000000000000', 'A0')], 54 | 'handler': accelerometer_CC2650_handler 55 | }, 56 | } 57 | } 58 | 59 | 60 | def device_discovered(mac, name, rssi): 61 | if 'SensorTag' not in name: return 62 | print("Discovered %s (%s) %s" % (mac, name, rssi)) 63 | if mac in sensors and sensors[mac][1]: return 64 | 65 | sensors[mac] = (name, False) 66 | ble.Connect(mac, False, ignore_reply = True) 67 | 68 | def device_connected(mac): 69 | if mac not in sensors: return 70 | print("Connected: %s (%s)" % (sensors[mac][0], mac)) 71 | name = sensors[mac][0] 72 | sensors[mac] = (name, True) 73 | 74 | if name not in init: 75 | print("Could not find init config for %s" % name) 76 | return 77 | 78 | for char, config in init[name].items(): 79 | print("Configuring: %s (%s) - %s" % (name, mac, char)) 80 | for charname, value in config['write']: 81 | ble.GattWrite(mac, charname, value, ignore_reply = True) 82 | ble.GattNotifications(mac, char, True, ignore_reply = True) 83 | 84 | def device_disconnected(mac): 85 | if mac not in sensors: return 86 | print("Disconnected: %s (%s)" % (sensors[mac][0], mac)) 87 | del sensors[mac] 88 | pass 89 | 90 | def notification_received(mac, uuid, message): 91 | if mac not in sensors: return # unknown device 92 | name = sensors[mac][0] 93 | if name not in init or uuid not in init[name]: return # no handlers for this notification 94 | 95 | handler = init[name][uuid]['handler'] 96 | result = handler(mac, uuid, message) 97 | 98 | notification = init[name][uuid]['notification'] 99 | 100 | print("MAC: %s, UUID: %s => %s" % (mac, uuid, result)) 101 | cloud.SendNotification(notification, json.dumps({ 102 | 'SensorTag': mac, 103 | 'Value': result 104 | }), DEFAULT_PRIORITY 105 | , error_handler=lambda err: print(err) 106 | , reply_handler=lambda *args: None) 107 | 108 | 109 | ble.connect_to_signal("PeripheralDiscovered", device_discovered) 110 | ble.connect_to_signal("PeripheralConnected", device_connected) 111 | ble.connect_to_signal("PeripheralDisconnected", device_disconnected) 112 | ble.connect_to_signal("NotificationReceived", notification_received) 113 | 114 | exiting = threading.Event() 115 | def worker(): 116 | while not exiting.is_set(): 117 | ble.ScanStart() 118 | exiting.wait(5) 119 | ble.ScanStop() 120 | exiting.wait(10) 121 | 122 | def main(): 123 | 124 | # init d-bus 125 | GObject.threads_init() 126 | dbus.mainloop.glib.threads_init() 127 | 128 | # start mainloop 129 | loop = GObject.MainLoop() 130 | 131 | worker_thread = threading.Thread(target=worker,) 132 | worker_thread.start() 133 | 134 | try: 135 | loop.run() 136 | except (KeyboardInterrupt, SystemExit): 137 | exiting.set() 138 | loop.quit() 139 | worker_thread.join() 140 | 141 | if __name__ == "__main__": 142 | main() -------------------------------------------------------------------------------- /examples/sensortag.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import dbus 4 | from dbus.mainloop.glib import DBusGMainLoop 5 | from gi.repository import GObject 6 | import array 7 | 8 | DBusGMainLoop(set_as_default=True) 9 | 10 | def get_ble(): 11 | obj = dbus.SystemBus().get_object("com.devicehive.bluetooth", "/com/devicehive/bluetooth") 12 | return dbus.Interface(obj, "com.devicehive.bluetooth") 13 | 14 | ble = get_ble() 15 | def device_discovered(mac, name, rssi): 16 | print("Discovered %s (%s) %s" % (mac, name, rssi)) 17 | if ((name == 'SensorTag')): 18 | ble.ScanStop() 19 | ble.Connect(mac, True) 20 | 21 | def device_connected(mac): 22 | print("Connected to %s" % (mac)) 23 | try: 24 | ble.GattWrite(mac, "F000AA1204514000b000000000000000", "01") 25 | ble.GattWrite(mac, "F000AA1304514000b000000000000000", "0A") 26 | ble.GattNotifications(mac, "F000AA1104514000b000000000000000", True) 27 | 28 | except dbus.DBusException as e: 29 | print(e) 30 | 31 | def notification_received(mac, uuid, message): 32 | print("MAC: %s, UUID: %s, Received: %s" % (mac, uuid, message)) 33 | 34 | def main(): 35 | ble.ScanStart() 36 | ble.connect_to_signal("PeripheralDiscovered", device_discovered) 37 | ble.connect_to_signal("PeripheralConnected", device_connected) 38 | ble.connect_to_signal("NotificationReceived", notification_received) 39 | 40 | GObject.MainLoop().run() 41 | 42 | if __name__ == '__main__': 43 | main() 44 | 45 | -------------------------------------------------------------------------------- /framework.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devicehive/IoT-framework/b268664a3e28f7fda786dc872a83879329bbf65d/framework.png -------------------------------------------------------------------------------- /godbus-helpers/ble/ble.go: -------------------------------------------------------------------------------- 1 | package ble 2 | 3 | import "github.com/devicehive/IoT-framework/godbus-helpers/dbushelper" 4 | 5 | type Dbus struct{ *dbushelper.Dbus } 6 | 7 | func NewDbus(iface, path string) (*Dbus, error) { 8 | base, err := dbushelper.NewDbus(iface, path) 9 | return &Dbus{base}, err 10 | } 11 | 12 | func NewDbusForComDevicehiveCloud() (*Dbus, error) { 13 | return NewDbus(PathComDevicehiveBluetooth, IfaceComDevicehiveBluetooth) 14 | } 15 | 16 | const ( 17 | PathComDevicehiveBluetooth = "/com/devicehive/bluetooth" 18 | IfaceComDevicehiveBluetooth = "com.devicehive.bluetooth" 19 | ) 20 | -------------------------------------------------------------------------------- /godbus-helpers/cloud/cloud.go: -------------------------------------------------------------------------------- 1 | package cloud 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/godbus/dbus" 7 | 8 | "github.com/devicehive/IoT-framework/godbus-helpers/dbushelper" 9 | ) 10 | 11 | type Dbus struct{ *dbushelper.Dbus } 12 | 13 | func NewDbus(iface, path string) (*Dbus, error) { 14 | base, err := dbushelper.NewDbus(iface, path) 15 | return &Dbus{base}, err 16 | } 17 | 18 | func NewDbusForComDevicehiveCloud() (*Dbus, error) { 19 | return NewDbus(PathComDevicehiveCloud, IfaceComDevicehiveCloud) 20 | } 21 | 22 | func (w *Dbus) SendNotification(name, parameters interface{}, priority uint64) (*dbus.Call, error) { 23 | b, err := json.Marshal(parameters) 24 | if err != nil { 25 | return nil, err 26 | } 27 | c := w.Call("SendNotification", name, string(b), priority) 28 | return c, c.Err 29 | } 30 | 31 | const ( 32 | PathComDevicehiveCloud = "/com/devicehive/cloud" 33 | IfaceComDevicehiveCloud = "com.devicehive.cloud" 34 | ) 35 | -------------------------------------------------------------------------------- /godbus-helpers/dbushelper/dbushelper.go: -------------------------------------------------------------------------------- 1 | package dbushelper 2 | 3 | import "github.com/godbus/dbus" 4 | 5 | // Helpers for github.com/godbus/dbus 6 | 7 | type Dbus struct { 8 | conn *dbus.Conn 9 | path, iface string 10 | } 11 | 12 | func (w *Dbus) Conn() *dbus.Conn { return w.conn } 13 | func (w *Dbus) Path() string { return w.path } 14 | func (w *Dbus) Iface() string { return w.iface } 15 | 16 | func NewDbus(path, iface string) (*Dbus, error) { 17 | w := new(Dbus) 18 | 19 | conn, err := dbus.SystemBus() 20 | if err != nil { 21 | conn, err = dbus.SessionBus() 22 | if err != nil { 23 | return nil, err 24 | } 25 | } 26 | 27 | w.path = path 28 | w.iface = iface 29 | w.conn = conn 30 | return w, nil 31 | } 32 | 33 | func (w *Dbus) Call(name string, args ...interface{}) *dbus.Call { 34 | c := w.conn.Object(w.Iface(), dbus.ObjectPath(w.Path())).Call(w.Iface()+"."+name, 0, args...) 35 | return c 36 | } 37 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # DeviceHive D-Bus Framework 2 | 3 | 4 | Develop apps connected to devices, peripherials and cloud using commonly available linux dbus interface. 5 | 6 | ![](framework.png?raw=true) 7 | 8 | Documentation is here: http://docs.devicehive.com/docs/iot-toolkit-overview 9 | 10 | ## Contents 11 | 12 | Currently this framework contains few components: 13 | 14 | `devicehive-alljoyn` - our custom API to communicate with AllJoyn devices with the easiest way 15 | 16 | `devicehive-ble` - our custom API for access BLE(Bluetooth low energy) GATT services 17 | 18 | `devicehive-cloud` - our API for access to DeviceHive cloud services 19 | 20 | `devicehive-enocean` - our simple API for access to EnOcean devices 21 | 22 | `devicehive-gpio` - our API for access to device's pins 23 | 24 | `examples` - samples of usage out IoT framework 25 | 26 | `build` - build system for our IoT framework 27 | 28 | Each directory contains more detailed information about component, see details there in readme files. 29 | 30 | 31 | ## Cloning 32 | 33 | This repository uses submodules so to clonse fresh copy use command 34 | ``` 35 | git clone --recursive git@github.com:devicehive/IoT-framework.git 36 | ``` 37 | 38 | Or if doing pull to existing repo use 39 | ``` 40 | git pull 41 | git submodule update --init --recursive 42 | ``` 43 | 44 | 45 | ## Building 46 | 47 | To build `Ubuntu Snappy` package navigate to `build/snappy` and run 48 | ``` 49 | # for framework 50 | ./build-framework.sh 51 | 52 | #for sample apps 53 | ./build-apps.sh 54 | ``` 55 | --------------------------------------------------------------------------------