iot mysql_IoT Studio服务开发MySQL数据流转示例Demo

本文介绍了如何使用阿里云IoT Studio的云数据库MySQL节点,通过服务开发实现跨区域的数据流转。详细步骤包括物联网产品和设备的创建、业务服务构建,以及云数据库MySQL节点的配置和建表语句。此教程适用于需要通过公网地址将物联网数据存入远程MySQL数据库的场景。
摘要由CSDN通过智能技术生成

概述

阿里云物联网平台的规则引擎功能支持将数据流转到MySQL数据库,但是仅支持同区域(上海--华东二)的数据流转,这里介绍使用IoT Studio服务开发:云数据库MySQL节点,通过MySQL数据库的公网地址,完成跨区域的数据流转。

Step By Step

物联网产品及设备的创建

1、创建产品

5592307c3b291074406a6e1147fb3ef2.png

2、导入物模型

cb76076bfdecae7eb629197712010a6f.png

8cdcb32cd3c47d5b280d5db17c40894c.png

da6cd606e32fcb11e32b22e680c2a025.png

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、添加设备

1a0758260f82c5cdef6b001609a280fc.png

IoT Studio绑定产品+设备

1、创建项目

4a176a66e9b809625197abeb82d347e7.png

2、项目创建完成后分别关联创建的产品和设备

c7faca52b8ed18947b0c0c447b6f03a3.png

3、新建业务服务

1805807e8dea5e6ea8d74326649b5403.png

7b13bd8d49076b91cb844a75cf039e6c.png

4、业务流程搭建

315db889d8dabc7676d0fb83b119cdd5.png

6ba9b2907953730a8a51889ce40cf309.png

994dc83b48e3b83d2434762c7b7d872c.png

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 SQL---------*/

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、部署调试

e3bf174b3c2f2f10c16b918ee0360277.png

28f5f93c6df64eb642b2c9944dfd4193.png

8bad394bb19f215af8468e0150288968.png

2、数据流转查看

885d3a7330f1021655c29bd57a85eeaa.png

3、流程测试正常后,发布即可

5c4a0ffea455a0ddbb3df80676a0013c.png

参考链接

来源:oschina

链接:https://my.oschina.net/u/4258260/blog/3209185

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值