Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

SensorTag as Device #90

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

Venkat2811
Copy link
Contributor

@Venkat2811 Venkat2811 commented Feb 26, 2017

  • Connect with Texas Instrument's SensorTag Device over BLE (Bluetooth Low Energy)
  • Auto-reconnect mechanism as BLE exception occurs frequently

sensors=[Sensors.TEMPERATURE, Sensors.HUMIDITY, Sensors.BAROMETER,
Sensors.BATTERY_LEVEL, Sensors.LIGHTMETER,
Sensors.ACCELEROMETER, Sensors.GYROSCOPE])
sensor_tag = sensor_tag_collector.get_sensor_tag()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be the requirement of get_sensor_tag(), just have one definition for sensor tag device and use it.

Facilitates collecting sensor metrics even in-case of dis-connectivity due to external factors, without any need
of manual restart of the program.

Use this class to collect metrics from SensorTag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be a separate class for collecting metrics, make it part of SensorTagDevice class. Creates confusion and complexity for user.

ALL = 8


class SensorTagDevice(Device, SensorTag):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is SensorTagDevice dependent on SensorTag ? Any specific requirement, I`m not clear with this implementation.

"""

def __init__(self, name, device_mac, entity_type="Device"):
Device.__init__(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use super

:return: None
"""
log.info("Connecting to SensorTag Device: {0} with MAC_ADDRESS: {1}".format(self.device_name, self.device_mac))
self.tag = SensorTagDevice(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be part of user code(Initializing Device class) shouldn't be in the core Liota.

self.metrics.append(reg_mem_free_metric)

# Connects to the SensorTag device over BLE
self.sensor_tag_collector = SensorTagCollector(device_name=config['DeviceName'], device_mac=config['DeviceMac'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a separate device package and metrics package. Initialization of device shouldn't be part of this device metrics package.

ureg = pint.UnitRegistry()


def read_cpu_procs():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just keep the device metrics in this package, don`t combine the device metrics and edge system metrics in the same package.

sampling_function=read_cpu_procs
)
reg_cpu_procs_metric = iotcc.register(cpu_procs_metric)
iotcc.create_relationship(iotcc_edge_system, reg_cpu_procs_metric)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just keep the package dependent on the device metrics only.


# create a data center object, IoTCC in this case, using websocket as a transport layer
iotcc = IotControlCenter(config['IotCCUID'], config['IotCCPassword'],
WebSocketDccComms(url=config['WebSocketUrl']))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use MQTT DCC Comms.

Returns SensorTagDevice entity.
:return: SensorTagDevice entity object.
"""
return self.tag
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to discuss about this tag implementation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this tag comments.

@KohliDev
Copy link
Contributor

We need to discuss some of the implementations.

@Venkat2811
Copy link
Contributor Author

Addressed review comments

Returns SensorTagDevice entity.
:return: SensorTagDevice entity object.
"""
return self.tag
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this tag comments.

@@ -0,0 +1,155 @@
# -*- coding: utf-8 -*-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just rename the path as "packages/examples/metrics".As you are making the new folder I`ll prefer if you can move the entities in the specific folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay will rename it. For packages, we need to move device and metric entities separately. This will result changes in many files. In the interest of keeping no.of files changed for a PR less, I'll raise a separate one just for refactoring once this is merged.

temperature_metric = Metric(
name="AmbientTemperature",
unit=ureg.degC,
interval=0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the interval be other than "0"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We provide sampling interval here
So, to collect from SensorTag, it must be zero.

@@ -0,0 +1,232 @@
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------------#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you are making the new folder I`ll prefer if you can move the entities in the specific folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have separate folder for model_simulated examples. This is the first actual device. DHT examples can go in here.

@@ -0,0 +1,155 @@
# -*- coding: utf-8 -*-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably you can move all the metrics associated package in this folder.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants