From ddc6f8d0e2506920a9e1b3c7cb7438e79e3bfc2c Mon Sep 17 00:00:00 2001 From: GPrathap Date: Tue, 5 Jan 2016 08:50:29 +0530 Subject: [PATCH 1/2] features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py --- .../src/main/resources/agent/README.md | 49 +++++++++---------- .../main/resources/agent/RaspberryService.sh | 1 - .../src/main/resources/agent/startService.sh | 2 +- .../src/main/resources/agent/testAgent.sh | 4 +- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md index bd47154704..f7956c23d5 100644 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md @@ -1,45 +1,42 @@ -# Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -# WSO2 Inc. licenses this file to you under the Apache License, -# Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. -# You may obtain a copy of the License at -# http://www.apache.org/licenses/LICENSE-2.0 -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. +## Copyright and license + +Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +WSO2 Inc. licenses this file to you under the Apache License,Version 2.0 (the "License"); you may not use this file except +in compliance with the License.You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. -------------- testAgent.sh -------------- This script is used to run this service in a testing environment. It can be run on a real Raspberry Pi device or in a -virtual environment. -If this runs on a real Raspberry Pi device, you need to install Adafruit Python DHT Sensor Library and RPi.GPIO Python Library.To install Adafruit Python DHT Sensor Library, follow the -instructions given here https://github.com/adafruit/Adafruit_Python_DHT. -To install RPi.GPIO Python Library, sudo apt-get install rpi.gpio +virtual environment.If this runs on a real Raspberry Pi device, you need to install [Adafruit Python DHT Sensor Library](https://github.com/adafruit/Adafruit_Python_DHT). +To install Adafruit Python DHT Sensor Library: follow the instructions given here https://github.com/adafruit/Adafruit_Python_DHT. -To run: sudo ./testAgent.sh and follow the instructions. +To run: ` sudo ./testAgent.sh ` and follow the instructions. ------------------- startService.sh ------------------- After testing, this script can be used to deploy this application as a service on Raspberry Pi which will get loaded during boot up process. -To run: sudo ./startService.sh -Note: You should have to provide following arguments in RaspberryService.sh as shown below. - -DAEMON_OPTS="-l /usr/local/src/RaspberryAgent/RaspberryStats.log -m N -i 56" --l ----> file to write log --i ----> time interval between successive data pushes to the wso2 IoT Server --m ----> weather is going to run on the real device or not +create a service: + ` sudo ./startService.sh ` start service: - service /etc/init.d/RaspberryService.sh start + ` sudo service RaspberryService.sh start ` stop service: - service /etc/init.d/RaspberryService.sh stop + ` sudo service RaspberryService.sh stop ` + +restart service: + ` sudo service RaspberryService.sh restart ` + +get current state of the service: + ` sudo service RaspberryService.sh status ` + + diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh index 7473ae0e7d..c4588c9905 100644 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh @@ -31,7 +31,6 @@ ### END INIT INFO PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin -# Change the next 3 lines to suit where you install your script and what you want to call it DESC="This service is used to publish events from the Raspberry Pi to the WSO2 Device Cloud" NAME=RaspberryStats diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh index 7e236beb2c..2d1b08b286 100644 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh @@ -33,4 +33,4 @@ sudo update-rc.d -f RaspberryService.sh remove sudo cp $currentDir/RaspberryService.sh /etc/init.d sudo chmod +x /etc/init.d/RaspberryService.sh sudo update-rc.d RaspberryService.sh defaults -sudo service /etc/init.d/RaspberryService.sh start +sudo service RaspberryService.sh start diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh index 4fab6da8db..8ea2a99cb0 100644 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh @@ -96,7 +96,7 @@ while true; do done cp deviceConfig.properties ./src -if [ $mode -eq "N" ]; then +if [ "$mode" = "N" ]; then sudo apt-get install rpi.gpio fi @@ -111,4 +111,4 @@ fi echo "--------------------------------------------------------------------------" echo "| Successfully Started " -echo "| -------------------------- " \ No newline at end of file +echo "| -------------------------- " \ No newline at end of file From cbac367254ecafd88056077f818a069c4f08a1d3 Mon Sep 17 00:00:00 2001 From: GPrathap Date: Tue, 5 Jan 2016 08:59:40 +0530 Subject: [PATCH 2/2] updated startup scripts --- .../src/main/resources/agent/README.md | 6 ++++-- .../src/main/resources/agent/RaspberryService.sh | 1 - .../src/main/resources/agent/src/RaspberryAgent.py | 4 ++-- .../src/main/resources/agent/src/iotUtils.py | 3 +-- .../src/main/resources/agent/startService.sh | 7 +++++++ .../src/main/resources/agent/testAgent.sh | 8 ++++---- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md index f7956c23d5..1500c82751 100644 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md @@ -25,6 +25,9 @@ during boot up process. create a service: ` sudo ./startService.sh ` + +get current state of the service: + ` sudo service RaspberryService.sh status ` start service: ` sudo service RaspberryService.sh start ` @@ -35,8 +38,7 @@ stop service: restart service: ` sudo service RaspberryService.sh restart ` -get current state of the service: - ` sudo service RaspberryService.sh status ` + diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh index c4588c9905..e32907e541 100644 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh @@ -46,7 +46,6 @@ PIDFILE=/var/run/$DAEMON_NAME.pid DAEMON_OPTS="-l /usr/local/src/RaspberryAgent/RaspberryStats.log -m N -i 60" # This next line determines what user the script runs as. -# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python. DAEMON_USER=root #pi # Load the VERBOSE setting and other rcS variables diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py index 793aa42d8b..956d1fb0cf 100644 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py @@ -54,8 +54,8 @@ LOG_LEVEL = logging.INFO # Could be e.g. "DEBUG" or "WARNING" # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Python version # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -if sys.version_info<(2,7,5): - sys.stderr.write("You need python 2.7.5 or later to run this script\n") +if sys.version_info<(2,7,0): + sys.stderr.write("You need python 2.7.0 or later to run this script\n") exit(1) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.py b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.py index fa05965b13..1419f91d65 100644 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.py +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.py @@ -31,6 +31,7 @@ import running_mode global HOST_NAME HOST_NAME = "0.0.0.0" # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +HTTP_SERVER_PORT = 5678 # http server port which is listning on global LAST_TEMP LAST_TEMP = 25 # The Last read temperature value from the DHT sensor. Kept globally @@ -40,9 +41,7 @@ TEMPERATURE_READING_INTERVAL_REAL_MODE = 3 TEMPERATURE_READING_INTERVAL_VIRTUAL_MODE = 60 TEMP_PIN = 4 TEMP_SENSOR_TYPE = 11 - BULB_PIN = 11 # The GPIO Pin# in RPi to which the LED is connected -HTTP_SERVER_PORT = 5678 # http server port which is listning on global GPIO # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh index 2d1b08b286..e073b10924 100644 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh @@ -20,6 +20,13 @@ #!/usr/bin/env bash +echo "----------------------------------------------------------------" +echo "| WSO2 IOT Sample " +echo "| RaspiAgent " +echo "| ---------------- " +echo "| ....initializing service-start-script " +echo "----------------------------------------------------------------" + destination="/usr/local/src/RaspberryAgent" currentDir=$PWD if [ ! -d "$destination" ] diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh index 8ea2a99cb0..b9d24532bf 100644 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh @@ -21,10 +21,10 @@ #!/bin/bash echo "----------------------------------------------------------------" -echo "| WSO2 IOT Sample " -echo "| RaspiAgent " -echo "| ---------------- " -echo "| ....initializing startup-script " +echo "| WSO2 IOT Sample " +echo "| RaspiAgent " +echo "| ---------------- " +echo "| ....initializing startup-script " echo "----------------------------------------------------------------" currentDir=$PWD