fixed error due to merge
import copy
import datetime
import uuid
+import json
import asyncio
-from foglamp.services.south import exceptions
+
from foglamp.plugins.south.common.sensortag_cc2650 import *
+from foglamp.services.south import exceptions
from foglamp.common import logger
from foglamp.services.south.ingest import Ingest
@@ -50,7 +52,6 @@ sensortag_characteristics = characteristics
def plugin_info():
""" Returns information about the plugin.
-
Args:
Returns:
dict: plugin information
@@ -69,7 +70,6 @@ def plugin_info():
def plugin_init(config):
""" Initialise the plugin.
-
Args:
config: JSON configuration document for the South device configuration category
Returns:
@@ -100,16 +100,14 @@ def plugin_init(config):
data['notification_handles'] = tag.get_notification_handles()
data['characteristics'] = sensortag_characteristics
data['tag'] = tag
- _LOGGER.info('SensorTagCC2650 {} async fetching initialized'.format(bluetooth_adr))
+ _LOGGER.info('SensorTagCC2650 {} Async fetching initialized'.format(bluetooth_adr))
return data
def plugin_start(handle):
""" Extracts data from the sensor and returns it in a JSON document as a Python dict.
-
Available for async mode only.
-
Args:
handle: handle returned by the plugin initialisation call
Returns:
@@ -173,10 +171,19 @@ def plugin_start(handle):
await asyncio.sleep(1)
continue
- # expect, if successful, will return the index of the pattern "Notification handle = " which ideally
+ # expect, if succesfull, will return the index of the pattern "Notification handle = " which ideally
# should appear at col 0. If not, then pexpect.TIMEOUT will be raised. Also, this choice of pattern
- # will help in splitting at line#176.
- if pattern_index == 0:
+ # will help in splitting at line#190.
+ if pattern_index != 0:
+ attempt_count += 1
+ if attempt_count > 15:
+ _LOGGER.error("SensorTagCC2650 {} async timeout")
+ print("TIMEOUT!!")
+ break
+ else:
+ await asyncio.sleep(1)
+ continue
+
after = tag.con.after
hex_string = after.split()[3:]
@@ -187,7 +194,7 @@ def plugin_start(handle):
break
print(cnt, "****", hex_string)
- # Allow some breathing time for event loop to finish the background tasks.
+ # Allow some breathing time for event loop to finish the background tasks such as responding to ping etc
if cnt % 10 == 0:
await asyncio.sleep(.5)
@@ -308,9 +315,6 @@ def plugin_start(handle):
await Ingest.add_readings(asset='TI Sensortag CC2650/{}'.format(data['asset']),
timestamp=data['timestamp'], key=data['key'],
readings=data['readings'])
- else:
- _LOGGER.error("SensorTagCC2650 async timeout")
- print("TIMEOUT!!")
except (Exception, RuntimeError) as ex:
_LOGGER.exception("SensorTagCC2650 async {} exception: {}".format(bluetooth_adr, str(ex)))
raise exceptions.DataRetrievalError(ex)
