天天看點

mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群

概述

阿裡雲物聯網平台的規則引擎功能支援将資料流轉到MySQL資料庫,但是僅支援同區域(上海--華東二)的資料流轉,這裡介紹使用IoT Studio服務開發:雲資料庫MySQL節點,通過MySQL資料庫的公網位址,完成跨區域的資料流轉。

Step By Step

物聯網産品及裝置的建立

1、建立産品

mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群

2、導入物模型

mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群
mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群
mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群

model.json

{

"schema":"https://iotx-tsl.oss-ap-southeast-1.aliyuncs.com/schema.json",

"profile":{

"productKey":""

},

"properties":[

{

"identifier":"Distance",

"name":"距離",

"accessMode":"rw",

"required":false,

"dataType":{

"type":"double",

"specs":{

"min":"0",

"max":"10000",

"unit":"m",

"step":"1"

}

}

},

{

"identifier":"GeoLocation",

"name":"自定義地理位置",

"accessMode":"rw",

"required":false,

"dataType":{

"type":"struct",

"specs":[

{

"identifier":"Longitude",

"name":"經度",

"dataType":{

"type":"double",

"specs":{

"min":"-180",

"max":"180",

"unit":"°",

"step":"0.01"

}

}

},

{

"identifier":"Latitude",

"name":"緯度",

"dataType":{

"type":"double",

"specs":{

"min":"-90",

"max":"90",

"unit":"°",

"step":"0.01"

}

}

},

{

"identifier":"CoordinateSystem",

"name":"坐标系統",

"dataType":{

"type":"enum",

"specs":{

"1":"WGS_84",

"2":"GCJ_02"

}

}

}

]

}

},

{

"identifier":"CellSignalStrength",

"name":"信号強度",

"accessMode":"r",

"required":false,

"dataType":{

"type":"int",

"specs":{

"min":"-128",

"max":"127",

"unit":"dBm",

"step":"1"

}

}

}

],

"events":[

{

"identifier":"post",

"name":"post",

"type":"info",

"required":true,

"desc":"屬性上報",

"method":"thing.event.property.post",

"outputData":[

{

"identifier":"Distance",

"name":"距離",

"dataType":{

"type":"double",

"specs":{

"min":"0",

"max":"10000",

"unit":"m",

"step":"1"

}

}

},

{

"identifier":"GeoLocation",

"name":"自定義地理位置",

"dataType":{

"type":"struct",

"specs":[

{

"identifier":"Longitude",

"name":"經度",

"dataType":{

"type":"double",

"specs":{

"min":"-180",

"max":"180",

"unit":"°",

"step":"0.01"

}

}

},

{

"identifier":"Latitude",

"name":"緯度",

"dataType":{

"type":"double",

"specs":{

"min":"-90",

"max":"90",

"unit":"°",

"step":"0.01"

}

}

},

{

"identifier":"CoordinateSystem",

"name":"坐标系統",

"dataType":{

"type":"enum",

"specs":{

"1":"WGS_84",

"2":"GCJ_02"

}

}

}

]

}

},

{

"identifier":"CellSignalStrength",

"name":"信号強度",

"dataType":{

"type":"int",

"specs":{

"min":"-128",

"max":"127",

"unit":"dBm",

"step":"1"

}

}

}

]

}

],

"services":[

{

"identifier":"set",

"name":"set",

"required":true,

"callType":"async",

"desc":"屬性設定",

"method":"thing.service.property.set",

"inputData":[

{

"identifier":"Distance",

"name":"距離",

"dataType":{

"type":"double",

"specs":{

"min":"0",

"max":"10000",

"unit":"m",

"step":"1"

}

}

},

{

"identifier":"GeoLocation",

"name":"自定義地理位置",

"dataType":{

"type":"struct",

"specs":[

{

"identifier":"Longitude",

"name":"經度",

"dataType":{

"type":"double",

"specs":{

"min":"-180",

"max":"180",

"unit":"°",

"step":"0.01"

}

}

},

{

"identifier":"Latitude",

"name":"緯度",

"dataType":{

"type":"double",

"specs":{

"min":"-90",

"max":"90",

"unit":"°",

"step":"0.01"

}

}

},

{

"identifier":"CoordinateSystem",

"name":"坐标系統",

"dataType":{

"type":"enum",

"specs":{

"1":"WGS_84",

"2":"GCJ_02"

}

}

}

]

}

}

],

"outputData":[

]

},

{

"identifier":"get",

"name":"get",

"required":true,

"callType":"async",

"desc":"屬性擷取",

"method":"thing.service.property.get",

"inputData":[

"Distance",

"GeoLocation",

"CellSignalStrength"

],

"outputData":[

{

"identifier":"Distance",

"name":"距離",

"dataType":{

"type":"double",

"specs":{

"min":"0",

"max":"10000",

"unit":"m",

"step":"1"

}

}

},

{

"identifier":"GeoLocation",

"name":"自定義地理位置",

"dataType":{

"type":"struct",

"specs":[

{

"identifier":"Longitude",

"name":"經度",

"dataType":{

"type":"double",

"specs":{

"min":"-180",

"max":"180",

"unit":"°",

"step":"0.01"

}

}

},

{

"identifier":"Latitude",

"name":"緯度",

"dataType":{

"type":"double",

"specs":{

"min":"-90",

"max":"90",

"unit":"°",

"step":"0.01"

}

}

},

{

"identifier":"CoordinateSystem",

"name":"坐标系統",

"dataType":{

"type":"enum",

"specs":{

"1":"WGS_84",

"2":"GCJ_02"

}

}

}

]

}

},

{

"identifier":"CellSignalStrength",

"name":"信号強度",

"dataType":{

"type":"int",

"specs":{

"min":"-128",

"max":"127",

"unit":"dBm",

"step":"1"

}

}

}

]

}

]

}

注意: 替換自己産品的ProductKey

3、添加裝置

mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群

IoT Studio綁定産品+裝置

1、建立項目

mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群

2、項目建立完成後分别關聯建立的産品和裝置

mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群

3、建立業務服務

mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群
mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群

4、業務流程搭建

mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群
mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群
mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群

5、雲資料庫MySQL節點配置介紹

5.1 MySQL的版本

請使用MySQL5.7或MySQL5.6版本,其它版本相容性會有問題,可能會出現連接配接異常。

5.2 參數配置

{

"table": "iotdevice1",

"rows": [

{

"CellSignalStrength": "{{query.props.CellSignalStrength.value}}",

"Distance": "{{query.props.Distance.value}}",

"Longitude": "{{query.props.GeoLocation.value.Latitude}}",

"Latitude": "{{query.props.GeoLocation.value.Longitude}}"

}

]

}

也可以是(注意節點Id按照具體節點情況修改):

{

"table": "iotdevice1",

"rows": [

{

"CellSignalStrength": "{{payload.props.CellSignalStrength.value}}",

"Distance": "{{query.props.Distance.value}}",

"Longitude": "{{query.props.GeoLocation.value.Latitude}}",

"Latitude": "{{node.node_339cdef0.props.GeoLocation.value.Longitude}}"

}

]

}

payload表示上一個節點輸出參數;query表示輸入節點的參數;node.nodeId表示指定某一節點的輸出參數。

5.3 MySQL建表語句

CREATE TABLE `iotdevice1` (

`CellSignalStrength` int(11) DEFAULT NULL,

`Distance` double DEFAULT NULL,

`Longitude` double DEFAULT NULL,

`Latitude` double DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8

裝置線上模拟測試

1、部署調試

mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群
mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群
mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群

2、資料流轉檢視

mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群

3、流程測試正常後,釋出即可

mysql 阿裡雲iot 資料_IoT Studio服務開發MySQL資料流轉示例Demo-阿裡雲開發者社群

參考連結