From bbaaf6e91dd7204aabf70bf1892807749d22cd5f Mon Sep 17 00:00:00 2001 From: amarendra-dianomic Date: Wed, 29 Aug 2018 11:53:12 +0530 Subject: [PATCH 01/11] Fixes and refactoring per FOGL-1724 --- packages/Debian/armhf/DEBIAN/postinst | 6 ---- python/foglamp/plugins/south/pt100/pt100.py | 32 ++++++++++++++------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/Debian/armhf/DEBIAN/postinst b/packages/Debian/armhf/DEBIAN/postinst index 0996f7f..79699af 100755 --- a/packages/Debian/armhf/DEBIAN/postinst +++ b/packages/Debian/armhf/DEBIAN/postinst @@ -31,11 +31,5 @@ set_files_ownership () { chown -R root:root /usr/local/foglamp/python/foglamp/plugins/south/pt100 } -add_service () { - output=$(curl -sX POST http://localhost:8081/foglamp/service -d '{"name": "pt100", "type": "south", "plugin": "pt100", "enabled": true}') - echo $output -} - set_files_ownership -add_service echo "PT100 plugin is now installed." diff --git a/python/foglamp/plugins/south/pt100/pt100.py b/python/foglamp/plugins/south/pt100/pt100.py index 84003b4..ba220c9 100644 --- a/python/foglamp/plugins/south/pt100/pt100.py +++ b/python/foglamp/plugins/south/pt100/pt100.py @@ -25,19 +25,28 @@ _DEFAULT_CONFIG = { 'plugin': { - 'description': 'PT100 Poll Plugin', - 'type': 'string', - 'default': 'pt100' + 'description': 'PT100 Poll Plugin', + 'type': 'string', + 'default': 'pt100', + 'readonly': 'true' + }, + 'assetNamePrefix': { + 'description': 'Asset prefix', + 'type': 'string', + 'default': "PT100", + 'order': "1" }, 'pins': { 'description': 'Chip select pins to check', 'type': 'string', - 'default': '8' + 'default': '8', + 'order': "3" }, 'pollInterval': { 'description': 'The interval between poll calls to the South device poll routine expressed in milliseconds.', 'type': 'integer', - 'default': '5000' + 'default': '5000', + 'order': "2" }, } @@ -105,14 +114,14 @@ def plugin_poll(handle): temperature = probe.readTemp() time_stamp = str(datetime.datetime.now(tz=datetime.timezone.utc)) data.append({ - 'asset': 'PT100/temperature{}'.format(probe.csPin), - 'timestamp': time_stamp, + 'asset': '{}/temperature{}'.format(handle['assetNamePrefix']['value'], probe.csPin), + 'timestamp': utils.local_timestamp(), 'key': str(uuid.uuid4()), 'readings': { "temperature": temperature } }) - except (Exception, RuntimeError, pexpect.exceptions.TIMEOUT) as ex: + except (Exception, RuntimeError) as ex: _LOGGER.exception("PT100 exception: {}".format(str(ex))) raise exceptions.DataRetrievalError(ex) @@ -140,10 +149,11 @@ def plugin_reconfigure(handle, new_config): # Plugin should re-initialize and restart if key configuration is changed if 'pollInterval' in diff: - new_handle = copy.deepcopy(new_config) - new_handle['restart'] = 'no' + plugin_shutdown(handle) + new_handle = plugin_init(new_config) + new_handle['restart'] = 'yes' else: - new_handle = copy.deepcopy(handle) + new_handle = copy.deepcopy(new_config) new_handle['restart'] = 'no' return new_handle From b29716c27980d4ddac40c691ed4d8c36675e1e15 Mon Sep 17 00:00:00 2001 From: amarendra-dianomic Date: Thu, 30 Aug 2018 11:49:13 +0530 Subject: [PATCH 02/11] assetNamePrefix changed to include / --- python/foglamp/plugins/south/pt100/pt100.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/foglamp/plugins/south/pt100/pt100.py b/python/foglamp/plugins/south/pt100/pt100.py index ba220c9..003a915 100644 --- a/python/foglamp/plugins/south/pt100/pt100.py +++ b/python/foglamp/plugins/south/pt100/pt100.py @@ -33,7 +33,7 @@ 'assetNamePrefix': { 'description': 'Asset prefix', 'type': 'string', - 'default': "PT100", + 'default': "PT100/", 'order': "1" }, 'pins': { @@ -114,7 +114,7 @@ def plugin_poll(handle): temperature = probe.readTemp() time_stamp = str(datetime.datetime.now(tz=datetime.timezone.utc)) data.append({ - 'asset': '{}/temperature{}'.format(handle['assetNamePrefix']['value'], probe.csPin), + 'asset': '{}temperature{}'.format(handle['assetNamePrefix']['value'], probe.csPin), 'timestamp': utils.local_timestamp(), 'key': str(uuid.uuid4()), 'readings': { From 775a9923c38cb67f20043c728ec81e18e183d59b Mon Sep 17 00:00:00 2001 From: amarendra-dianomic Date: Thu, 30 Aug 2018 12:38:02 +0530 Subject: [PATCH 03/11] plugin_reconfigure() refactored --- python/foglamp/plugins/south/pt100/pt100.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/python/foglamp/plugins/south/pt100/pt100.py b/python/foglamp/plugins/south/pt100/pt100.py index 003a915..f70f696 100644 --- a/python/foglamp/plugins/south/pt100/pt100.py +++ b/python/foglamp/plugins/south/pt100/pt100.py @@ -143,18 +143,8 @@ def plugin_reconfigure(handle, new_config): Raises: """ _LOGGER.info("Old config for PT100 plugin {} \n new config {}".format(handle, new_config)) - - # Find diff between old config and new config - diff = utils.get_diff(handle, new_config) - - # Plugin should re-initialize and restart if key configuration is changed - if 'pollInterval' in diff: - plugin_shutdown(handle) - new_handle = plugin_init(new_config) - new_handle['restart'] = 'yes' - else: - new_handle = copy.deepcopy(new_config) - new_handle['restart'] = 'no' + new_handle = copy.deepcopy(new_config) + new_handle['restart'] = 'no' return new_handle From 36dd27d258202c1b2e73e50b298a93ef5f392145 Mon Sep 17 00:00:00 2001 From: amarendra-dianomic Date: Thu, 30 Aug 2018 18:06:12 +0530 Subject: [PATCH 04/11] Feedback changes --- python/foglamp/plugins/south/pt100/pt100.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/python/foglamp/plugins/south/pt100/pt100.py b/python/foglamp/plugins/south/pt100/pt100.py index f70f696..380a3d2 100644 --- a/python/foglamp/plugins/south/pt100/pt100.py +++ b/python/foglamp/plugins/south/pt100/pt100.py @@ -112,7 +112,6 @@ def plugin_poll(handle): try: for probe in probes: temperature = probe.readTemp() - time_stamp = str(datetime.datetime.now(tz=datetime.timezone.utc)) data.append({ 'asset': '{}temperature{}'.format(handle['assetNamePrefix']['value'], probe.csPin), 'timestamp': utils.local_timestamp(), @@ -148,18 +147,6 @@ def plugin_reconfigure(handle, new_config): return new_handle -def _plugin_stop(handle): - """ Stops the plugin doing required cleanup, to be called prior to the South device service being shut down. - - Args: - handle: handle returned by the plugin initialisation call - Returns: - Raises: - """ - GPIO.cleanup() - _LOGGER.info('PT100 poll plugin stop.') - - def plugin_shutdown(handle): """ Shutdowns the plugin doing required cleanup, to be called prior to the South device service being shut down. @@ -168,5 +155,5 @@ def plugin_shutdown(handle): Returns: Raises: """ - _plugin_stop(handle) + GPIO.cleanup() _LOGGER.info('PT100 poll plugin shut down.') From 2a705a70120958f8b08691459e6458dcecde3842 Mon Sep 17 00:00:00 2001 From: Vaibhav Singhal Date: Fri, 21 Sep 2018 17:55:23 +0530 Subject: [PATCH 05/11] changed version --- VERSION.south.pt100 | 4 +- packages/Debian/armhf/DEBIAN/preinst | 57 ---------------------------- 2 files changed, 2 insertions(+), 59 deletions(-) delete mode 100755 packages/Debian/armhf/DEBIAN/preinst diff --git a/VERSION.south.pt100 b/VERSION.south.pt100 index eb500d0..41cb7f7 100644 --- a/VERSION.south.pt100 +++ b/VERSION.south.pt100 @@ -1,2 +1,2 @@ -foglamp_south_pt100_version=1.0.0 -foglamp_version>=1.3 +foglamp_south_pt100_version=1.1.0 +foglamp_version>=1.4 diff --git a/packages/Debian/armhf/DEBIAN/preinst b/packages/Debian/armhf/DEBIAN/preinst deleted file mode 100755 index ca6281e..0000000 --- a/packages/Debian/armhf/DEBIAN/preinst +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/sh - -##-------------------------------------------------------------------- -## Copyright (c) 2018 OSIsoft, LLC -## -## Licensed 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. -##-------------------------------------------------------------------- - -##-------------------------------------------------------------------- -## -## @preinst DEBIAN/preinst -## This script is used to execute post installation tasks. -## -## Author: Ivan Zoratti, Ashwin Gopalakrishnan -## -##-------------------------------------------------------------------- - -set -e -get_foglamp_script () { - foglamp_script=$(dpkg -L foglamp | grep 'foglamp/bin/foglamp$') - echo $foglamp_script -} - -is_foglamp_running () { - set +e - foglamp_script=$(get_foglamp_script) - foglamp_status_output=$($foglamp_script status 2>&1 | grep 'FogLAMP Uptime') - rc=$((!$?)) - echo $rc - set -e -} - -install_pip3_package() { - sudo pip3 install RPi.GPIO -} - -# main - -# exit if foglamp is not running -IS_FOGLAMP_RUNNING=$(is_foglamp_running) -if [ "$IS_FOGLAMP_RUNNING" -eq "0" ] -then - echo "*** ERROR. FogLAMP is currently not running. Start FogLAMP and try again. ***" - exit 1 -fi - -install_pip3_package From 824c209d50c82816b40ff8442934accb9a3455b5 Mon Sep 17 00:00:00 2001 From: Vaibhav Singhal Date: Mon, 26 Nov 2018 12:59:43 +0530 Subject: [PATCH 06/11] make_deb modified to build only on arm architecture --- make_deb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/make_deb b/make_deb index 47ddf5e..988e6ba 100755 --- a/make_deb +++ b/make_deb @@ -16,7 +16,7 @@ ## limitations under the License. ##-------------------------------------------------------------------- ## -## Author: Ivan Zoratti +## Author: Ivan Zoratti, Vaibhav Singhal ## @@ -38,7 +38,6 @@ do find "${GIT_ROOT}/packages/Debian/build" -maxdepth 1 | grep '.*\.[0-9][0-9][0-9][0-9]' | xargs rm -rf echo "Done." exit 0 - shift ;; cleanall) if [ -d "${GIT_ROOT}/packages/Debian/build" ]; then @@ -49,7 +48,6 @@ do echo "No build folder, skipping cleanall" fi exit 0 - shift ;; *) echo "${usage}" @@ -58,6 +56,11 @@ do esac done +if [ "$(dpkg --print-architecture)" != "armhf" ]; then + echo "Package building is only supported on armhf architecture!!" + exit 0 +fi + architecture="armhf" version=`cat ${GIT_ROOT}/VERSION.south.pt100 | tr -d ' ' | grep 'foglamp_south_pt100_version=' | head -1 | sed -e 's/\(.*\)=\(.*\)/\2/g'` foglamp_version=`cat ${GIT_ROOT}/VERSION.south.pt100 | tr -d ' ' | grep 'foglamp_version' | head -1 | sed -e 's/\(.*\)version\(.*\)/\2/g'` From c3ea701768102d999330ab1dc5d1993a998c9ebb Mon Sep 17 00:00:00 2001 From: ashish-jabble Date: Wed, 2 Jan 2019 19:15:30 +0530 Subject: [PATCH 07/11] displayName attribute added --- python/foglamp/plugins/south/pt100/pt100.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/python/foglamp/plugins/south/pt100/pt100.py b/python/foglamp/plugins/south/pt100/pt100.py index 380a3d2..1c90ce1 100644 --- a/python/foglamp/plugins/south/pt100/pt100.py +++ b/python/foglamp/plugins/south/pt100/pt100.py @@ -34,19 +34,22 @@ 'description': 'Asset prefix', 'type': 'string', 'default': "PT100/", - 'order': "1" + 'order': "1", + 'displayName': 'Asset Name Prefix' }, 'pins': { 'description': 'Chip select pins to check', 'type': 'string', 'default': '8', - 'order': "3" + 'order': "3", + 'displayName': 'GPIO Pin' }, 'pollInterval': { 'description': 'The interval between poll calls to the South device poll routine expressed in milliseconds.', 'type': 'integer', 'default': '5000', - 'order': "2" + 'order': "2", + 'displayName': 'Poll Interval' }, } From 136fd1f585952ef71d63fff7223431bf62c69691 Mon Sep 17 00:00:00 2001 From: ashish-jabble Date: Thu, 3 Jan 2019 12:13:38 +0530 Subject: [PATCH 08/11] feedback fixes --- python/foglamp/plugins/south/pt100/pt100.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/foglamp/plugins/south/pt100/pt100.py b/python/foglamp/plugins/south/pt100/pt100.py index 1c90ce1..afca406 100644 --- a/python/foglamp/plugins/south/pt100/pt100.py +++ b/python/foglamp/plugins/south/pt100/pt100.py @@ -10,6 +10,7 @@ import datetime import json import uuid +import logging import RPi.GPIO as GPIO from foglamp.plugins.south.pt100.max31865 import * @@ -45,7 +46,7 @@ 'displayName': 'GPIO Pin' }, 'pollInterval': { - 'description': 'The interval between poll calls to the South device poll routine expressed in milliseconds.', + 'description': 'The interval between poll calls, expressed in milliseconds.', 'type': 'integer', 'default': '5000', 'order': "2", @@ -53,7 +54,7 @@ }, } -_LOGGER = logger.setup(__name__, level=20) +_LOGGER = logger.setup(__name__, level=logging.INFO) def plugin_info(): From 28d5f66ad619844487f14c1481b6265739d47c3c Mon Sep 17 00:00:00 2001 From: ashish-jabble Date: Thu, 3 Jan 2019 07:15:03 +0000 Subject: [PATCH 09/11] package built under packages/build; consistency fix across all plugins --- .gitignore | 4 ++-- make_deb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index d62aa2a..d013c66 100644 --- a/.gitignore +++ b/.gitignore @@ -9,10 +9,10 @@ *.idea # Build -packages/Debian/build/ +packages/build/ # Compiled Object files *.pyc # Test -.pytest_cache \ No newline at end of file +.pytest_cache diff --git a/make_deb b/make_deb index 988e6ba..3354dbd 100755 --- a/make_deb +++ b/make_deb @@ -35,14 +35,14 @@ do case "$i" in clean) echo -n "Cleaning the build folder from older versions..." - find "${GIT_ROOT}/packages/Debian/build" -maxdepth 1 | grep '.*\.[0-9][0-9][0-9][0-9]' | xargs rm -rf + find "${GIT_ROOT}/packages/build" -maxdepth 1 | grep '.*\.[0-9][0-9][0-9][0-9]' | xargs rm -rf echo "Done." exit 0 ;; cleanall) - if [ -d "${GIT_ROOT}/packages/Debian/build" ]; then + if [ -d "${GIT_ROOT}/packages/build" ]; then echo -n "Cleaning the build folder..." - rm -rf ${GIT_ROOT}/packages/Debian/build/* + rm -rf ${GIT_ROOT}/packages/build/* echo "Done." else echo "No build folder, skipping cleanall" @@ -64,7 +64,7 @@ fi architecture="armhf" version=`cat ${GIT_ROOT}/VERSION.south.pt100 | tr -d ' ' | grep 'foglamp_south_pt100_version=' | head -1 | sed -e 's/\(.*\)=\(.*\)/\2/g'` foglamp_version=`cat ${GIT_ROOT}/VERSION.south.pt100 | tr -d ' ' | grep 'foglamp_version' | head -1 | sed -e 's/\(.*\)version\(.*\)/\2/g'` -BUILD_ROOT="${GIT_ROOT}/packages/Debian/build" +BUILD_ROOT="${GIT_ROOT}/packages/build" # Final package name package_name="foglamp-south-pt100-${version}-${architecture}" From e83d811c77d1d3eecd0d9f768e36b2aa864672b3 Mon Sep 17 00:00:00 2001 From: ashish-jabble Date: Fri, 11 Jan 2019 14:05:11 +0530 Subject: [PATCH 10/11] FOGL-2295 pollInterval removal and copyright fixes --- LICENSE | 2 +- make_deb | 2 +- packages/Debian/armhf/DEBIAN/postinst | 2 +- python/foglamp/plugins/south/pt100/pt100.py | 19 +++++-------------- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/LICENSE b/LICENSE index 261eeb9..a4d3b5d 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2018 Dianomic Systems Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/make_deb b/make_deb index 3354dbd..7f1c4d7 100755 --- a/make_deb +++ b/make_deb @@ -1,7 +1,7 @@ #!/bin/bash ##-------------------------------------------------------------------- -## Copyright (c) 2018 OSIsoft, LLC +## Copyright (c) 2018 Dianomic Systems ## ## Licensed under the Apache License, Version 2.0 (the "License"); ## you may not use this file except in compliance with the License. diff --git a/packages/Debian/armhf/DEBIAN/postinst b/packages/Debian/armhf/DEBIAN/postinst index 79699af..9a21fbd 100755 --- a/packages/Debian/armhf/DEBIAN/postinst +++ b/packages/Debian/armhf/DEBIAN/postinst @@ -1,7 +1,7 @@ #!/bin/sh ##-------------------------------------------------------------------- -## Copyright (c) 2018 OSIsoft, LLC +## Copyright (c) 2018 Dianomic Systems ## ## Licensed under the Apache License, Version 2.0 (the "License"); ## you may not use this file except in compliance with the License. diff --git a/python/foglamp/plugins/south/pt100/pt100.py b/python/foglamp/plugins/south/pt100/pt100.py index afca406..c91c33c 100644 --- a/python/foglamp/plugins/south/pt100/pt100.py +++ b/python/foglamp/plugins/south/pt100/pt100.py @@ -20,7 +20,7 @@ __author__ = "Ashwin Gopalakrishnan" -__copyright__ = "Copyright (c) 2018 OSIsoft, LLC" +__copyright__ = "Copyright (c) 2018 Dianomic Systems" __license__ = "Apache 2.0" __version__ = "${VERSION}" @@ -44,14 +44,7 @@ 'default': '8', 'order': "3", 'displayName': 'GPIO Pin' - }, - 'pollInterval': { - 'description': 'The interval between poll calls, expressed in milliseconds.', - 'type': 'integer', - 'default': '5000', - 'order': "2", - 'displayName': 'Poll Interval' - }, + } } _LOGGER = logger.setup(__name__, level=logging.INFO) @@ -80,7 +73,7 @@ def plugin_init(config): """ Initialise the plugin. Args: - config: JSON configuration document for the South device configuration category + config: JSON configuration document for the South plugin configuration category Returns: handle: JSON object to be used in future calls to the plugin Raises: @@ -110,7 +103,6 @@ def plugin_poll(handle): DataRetrievalError """ probes = handle['probes'] - time_stamp = str(datetime.datetime.now(tz=datetime.timezone.utc)) data = list() try: @@ -135,7 +127,7 @@ def plugin_poll(handle): def plugin_reconfigure(handle, new_config): """ Reconfigures the plugin - it should be called when the configuration of the plugin is changed during the operation of the South device service; + it should be called when the configuration of the plugin is changed during the operation of the South service; The new configuration category should be passed. Args: @@ -147,12 +139,11 @@ def plugin_reconfigure(handle, new_config): """ _LOGGER.info("Old config for PT100 plugin {} \n new config {}".format(handle, new_config)) new_handle = copy.deepcopy(new_config) - new_handle['restart'] = 'no' return new_handle def plugin_shutdown(handle): - """ Shutdowns the plugin doing required cleanup, to be called prior to the South device service being shut down. + """ Shutdowns the plugin doing required cleanup, to be called prior to the South service being shut down. Args: handle: handle returned by the plugin initialisation call From 6f6e08e4f52cb428714efd801e881d21a259b8eb Mon Sep 17 00:00:00 2001 From: dianomicbot Date: Thu, 7 Feb 2019 14:54:55 +0000 Subject: [PATCH 11/11] VERSION changed --- VERSION.south.pt100 | 4 ++-- python/foglamp/plugins/south/pt100/pt100.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION.south.pt100 b/VERSION.south.pt100 index 41cb7f7..1b1d782 100644 --- a/VERSION.south.pt100 +++ b/VERSION.south.pt100 @@ -1,2 +1,2 @@ -foglamp_south_pt100_version=1.1.0 -foglamp_version>=1.4 +foglamp_south_pt100_version=1.5.0 +foglamp_version>=1.5 diff --git a/python/foglamp/plugins/south/pt100/pt100.py b/python/foglamp/plugins/south/pt100/pt100.py index c91c33c..b5cdf79 100644 --- a/python/foglamp/plugins/south/pt100/pt100.py +++ b/python/foglamp/plugins/south/pt100/pt100.py @@ -61,7 +61,7 @@ def plugin_info(): return { 'name': 'PT100 Poll Plugin', - 'version': '1.0', + 'version': '1.5.0', 'mode': 'poll', 'type': 'south', 'interface': '1.0',