diff --git a/code/aliyun_object_model.json b/code/aliyun_object_model.json index d8c9dce..cf2316e 100644 --- a/code/aliyun_object_model.json +++ b/code/aliyun_object_model.json @@ -307,6 +307,18 @@ "dataType": { "type": "int" } + }, + { + "identifier": "temperature", + "dataType": { + "type": "double" + } + }, + { + "identifier": "humidity", + "dataType": { + "type": "double" + } } ], "events": [ diff --git a/code/modules b/code/modules index 188281c..fb1fb63 160000 --- a/code/modules +++ b/code/modules @@ -1 +1 @@ -Subproject commit 188281ceb713fab3cd56e2525fb0e365e039db3c +Subproject commit fb1fb63157f4472eca64743099ffa2bd475a63d7 diff --git a/code/quec_object_model.json b/code/quec_object_model.json index 1e245ab..85767bb 100644 --- a/code/quec_object_model.json +++ b/code/quec_object_model.json @@ -2,9 +2,42 @@ "profile":{ "tslVersion":"1.1.0", "productKey":"p11275", - "version":"20220428155940369" + "version":"20220622194658344" }, + "services":[ + { + "outputData":[ + { + "$ref":"#/properties/id/19" + } + ], + "inputData":[ + { + "$ref":"#/properties/id/2" + } + ], + "code":"test_service", + "name":"test_service", + "subType":"ASYNC", + "id":5, + "sort":38, + "type":"SERVICE", + "desc":"" + } + ], "properties":[ + { + "specs":{ + "length":"512" + }, + "code":"query_device_info", + "dataType":"TEXT", + "name":"查询设备信息", + "subType":"RW", + "id":2, + "type":"PROPERTY", + "desc":"" + }, { "specs":[ { @@ -808,22 +841,6 @@ "type":"PROPERTY", "desc":"" }, - { - "specs":{ - "unit":"s", - "min":"0", - "max":"2147483647", - "step":"1" - }, - "code":"work_mode_timeline", - "dataType":"INT", - "name":"休眠策略参考时间", - "subType":"RW", - "id":44, - "sort":35, - "type":"PROPERTY", - "desc":"" - }, { "specs":{ "unit":"s", @@ -839,6 +856,54 @@ "sort":36, "type":"PROPERTY", "desc":"-1:一直等待直到读取到数据才进行返回\n0:不等待,读取接口返回数据后立即返回\n>0: 等待超时时间,单位秒" + }, + { + "specs":{ + "unit":"s", + "min":"3600", + "max":"2147483647", + "step":"1" + }, + "code":"work_mode_timeline", + "dataType":"INT", + "name":"休眠策略参考时间", + "subType":"RW", + "id":1, + "sort":37, + "type":"PROPERTY", + "desc":"" + }, + { + "specs":{ + "unit":"℃", + "min":"-40", + "max":"125", + "step":"0.01" + }, + "code":"temperature", + "dataType":"DOUBLE", + "name":"设备温度", + "subType":"R", + "id":7, + "sort":39, + "type":"PROPERTY", + "desc":"" + }, + { + "specs":{ + "unit":"%", + "min":"0", + "max":"100", + "step":"0.01" + }, + "code":"humidity", + "dataType":"DOUBLE", + "name":"设备湿度", + "subType":"R", + "id":39, + "sort":40, + "type":"PROPERTY", + "desc":"" } ], "events":[ diff --git a/code/tracker.py b/code/tracker.py index 0ca418e..aa9e194 100644 --- a/code/tracker.py +++ b/code/tracker.py @@ -22,11 +22,12 @@ from usr.modules.sensor import Sensor from usr.modules.battery import Battery from usr.modules.history import History from usr.modules.logging import getLogger +from usr.modules.location import Location from usr.modules.mpower import LowEnergyManage from usr.modules.remote import RemotePublish, RemoteSubscribe from usr.modules.aliyunIot import AliYunIot, AliObjectModel from usr.modules.quecthing import QuecThing, QuecObjectModel -from usr.modules.location import Location +from usr.modules.temp_humidity_sensor import TempHumiditySensor from usr.settings import PROJECT_NAME, PROJECT_VERSION, \ DEVICE_FIRMWARE_NAME, DEVICE_FIRMWARE_VERSION, settings, SYSConfig from usr.tracker_collector import Collector @@ -99,6 +100,7 @@ def tracker(): battery = Battery() data_call = dataCall low_energy = LowEnergyManage() + temp_humidity_sensor = TempHumiditySensor() usb = USB() if USB is not None else None power_key = PowerKey() if PowerKey is not None else None locator = Location(current_settings["LocConfig"]["gps_mode"], current_settings["LocConfig"]["locator_init_params"]) @@ -185,6 +187,8 @@ def tracker(): collector.add_module(locator) # Add History to Collector for getting history data. collector.add_module(history) + # Add TempHumiditySensor to Collector for getting temperature and humidity + collector.add_module(temp_humidity_sensor) # LowEnergyManage initialization work_cycle_period = current_settings["user_cfg"]["work_cycle_period"] diff --git a/code/tracker_collector.py b/code/tracker_collector.py index d1d7583..45ae634 100644 --- a/code/tracker_collector.py +++ b/code/tracker_collector.py @@ -21,6 +21,7 @@ from usr.modules.battery import Battery from usr.modules.history import History from usr.modules.logging import getLogger from usr.modules.mpower import LowEnergyManage +from usr.modules.temp_humidity_sensor import TempHumiditySensor from usr.modules.common import Singleton, LOWENERGYMAP from usr.modules.location import Location, GPSMatch, GPSParse, _loc_method from usr.settings import PROJECT_NAME, PROJECT_VERSION, DEVICE_FIRMWARE_NAME, DEVICE_FIRMWARE_VERSION, \ @@ -51,6 +52,7 @@ class Collector(Singleton): self.__sensor = None self.__locator = None self.__history = None + self.__temp_humidity_sensor = None self.__gps_match = GPSMatch() self.__gps_parse = GPSParse() @@ -301,6 +303,16 @@ class Collector(Singleton): return {} + def __get_temp_humidity(self): + data = {} + on_res = self.__temp_humidity_sensor.on() + if on_res: + temperature, humidity = self.__temp_humidity_sensor.read() + data["temperature"] = temperature + data["humidity"] = humidity + self.__temp_humidity_sensor.off() + return data + def add_module(self, module): """add modules for collecting data""" if isinstance(module, Controller): @@ -321,6 +333,9 @@ class Collector(Singleton): elif isinstance(module, History): self.__history = module return True + elif isinstance(module, TempHumiditySensor): + self.__temp_humidity_sensor = module + return True return False @@ -448,6 +463,9 @@ class Collector(Singleton): check_battery_energy = self.__check_battery_energy(battery_data.get("energy")) device_data.update(check_battery_energy) + temp_humidity_data = self.__get_temp_humidity() + device_data.update(temp_humidity_data) + # TODO: Add other machine info. return device_data diff --git a/object_model_demo/ali_cloud_object_model.json b/object_model_demo/ali_cloud_object_model.json index e4c497a..2291165 100644 --- a/object_model_demo/ali_cloud_object_model.json +++ b/object_model_demo/ali_cloud_object_model.json @@ -641,6 +641,38 @@ "step": "1" } } + }, + { + "identifier": "temperature", + "name": "设备温度", + "accessMode": "r", + "required": false, + "dataType": { + "type": "double", + "specs": { + "min": "-40", + "max": "125", + "unit": "°C", + "unitName": "摄氏度", + "step": "0.01" + } + } + }, + { + "identifier": "humidity", + "name": "设备湿度", + "accessMode": "r", + "required": false, + "dataType": { + "type": "double", + "specs": { + "min": "0", + "max": "100", + "unit": "%RH", + "unitName": "相对湿度", + "step": "0.01" + } + } } ], "events": [ @@ -1224,6 +1256,34 @@ "step": "1" } } + }, + { + "identifier": "temperature", + "name": "设备温度", + "dataType": { + "type": "double", + "specs": { + "min": "-40", + "max": "125", + "unit": "°C", + "unitName": "摄氏度", + "step": "0.01" + } + } + }, + { + "identifier": "humidity", + "name": "设备湿度", + "dataType": { + "type": "double", + "specs": { + "min": "0", + "max": "100", + "unit": "%RH", + "unitName": "相对湿度", + "step": "0.01" + } + } } ] }, @@ -1619,7 +1679,9 @@ "voltage", "current_speed", "work_mode_timeline", - "loc_gps_read_timeout" + "loc_gps_read_timeout", + "temperature", + "humidity" ], "outputData": [ { @@ -2194,6 +2256,34 @@ "step": "1" } } + }, + { + "identifier": "temperature", + "name": "设备温度", + "dataType": { + "type": "double", + "specs": { + "min": "-40", + "max": "125", + "unit": "°C", + "unitName": "摄氏度", + "step": "0.01" + } + } + }, + { + "identifier": "humidity", + "name": "设备湿度", + "dataType": { + "type": "double", + "specs": { + "min": "0", + "max": "100", + "unit": "%RH", + "unitName": "相对湿度", + "step": "0.01" + } + } } ] } diff --git a/object_model_demo/quec_cloud_object_model.json b/object_model_demo/quec_cloud_object_model.json index ca2db56..85767bb 100644 --- a/object_model_demo/quec_cloud_object_model.json +++ b/object_model_demo/quec_cloud_object_model.json @@ -2,9 +2,42 @@ "profile":{ "tslVersion":"1.1.0", "productKey":"p11275", - "version":"20220526133940091" + "version":"20220622194658344" }, + "services":[ + { + "outputData":[ + { + "$ref":"#/properties/id/19" + } + ], + "inputData":[ + { + "$ref":"#/properties/id/2" + } + ], + "code":"test_service", + "name":"test_service", + "subType":"ASYNC", + "id":5, + "sort":38, + "type":"SERVICE", + "desc":"" + } + ], "properties":[ + { + "specs":{ + "length":"512" + }, + "code":"query_device_info", + "dataType":"TEXT", + "name":"查询设备信息", + "subType":"RW", + "id":2, + "type":"PROPERTY", + "desc":"" + }, { "specs":[ { @@ -839,6 +872,38 @@ "sort":37, "type":"PROPERTY", "desc":"" + }, + { + "specs":{ + "unit":"℃", + "min":"-40", + "max":"125", + "step":"0.01" + }, + "code":"temperature", + "dataType":"DOUBLE", + "name":"设备温度", + "subType":"R", + "id":7, + "sort":39, + "type":"PROPERTY", + "desc":"" + }, + { + "specs":{ + "unit":"%", + "min":"0", + "max":"100", + "step":"0.01" + }, + "code":"humidity", + "dataType":"DOUBLE", + "name":"设备湿度", + "subType":"R", + "id":39, + "sort":40, + "type":"PROPERTY", + "desc":"" } ], "events":[