add: Get and report device temperature and humidity to cloud. update: add temperature and hmidity to cloud object model

This commit is contained in:
JackSun 2022-06-23 09:04:02 +08:00
parent 4431b0bdae
commit c0670fd056
7 changed files with 275 additions and 21 deletions

View File

@ -307,6 +307,18 @@
"dataType": {
"type": "int"
}
},
{
"identifier": "temperature",
"dataType": {
"type": "double"
}
},
{
"identifier": "humidity",
"dataType": {
"type": "double"
}
}
],
"events": [

@ -1 +1 @@
Subproject commit 188281ceb713fab3cd56e2525fb0e365e039db3c
Subproject commit fb1fb63157f4472eca64743099ffa2bd475a63d7

View File

@ -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":[

View File

@ -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"]

View File

@ -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

View File

@ -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"
}
}
}
]
}

View File

@ -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":[