IoT Studio服务开发MySQL数据流转示例Demo
概述
阿里云物联网平台的规则引擎功能支持将数据流转到MySQL数据库,但是仅支持同区域(上海--华东二)的数据流转,这里介绍使用IoT Studio服务开发:云数据库MySQL节点,通过MySQL数据库的公网地址,完成跨区域的数据流转。
Step By Step
物联网产品及设备的创建
1、创建产品
2、导入物模型
model.json
{ "schema":"https://iotx-tsl.oss-ap-southeast-1.aliyuncs.com/schema.json", "profile":{ "productKey":"<替换为自己产品的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、添加设备
IoT Studio绑定产品+设备
1、创建项目
2、项目创建完成后分别关联创建的产品和设备
3、新建业务服务
4、业务流程搭建
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、部署调试
2、数据流转查看
3、流程测试正常后,发布即可
参考链接
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
gowe 1.0.2 发布,Golang 多微信号 SDK
gowe,golang多微信号SDK,readygo子项目API文档 感谢https://gitee.com/xiaochengtech/wechat提供的基础代码 go get gitee.com/chunanyong/gowe 支持境内普通商户和境内服务商(境外和银行服务商没有条件测试) 全部参数和返回值均使用struct类型传递 缓存前置,使用项目现有的缓存体系 原生支持多微信号 支持跳板请求微信API服务.例如内网服务器没有网络出口权限,可以使用Nginx跳板请求微信API服务 原生支持集群部署
- 下一篇
聊聊ThreadLocal那些事
前言 这篇文章聊聊 ThreadLocal,我们经常会在一些开源中间件的源码中见到它的身影,比较常见的用途是保存上下文信息,还有就是保证了线程安全。 实际上,ThreadLocal 为每个线程提供一个单独的变量,确是一种保证线程安全的手段,ThreadLocal 创建的变量只能被当前线程访问,其他线程不得干涉。 ThreadLocal API 使用 ThreadLocal 其实非常简单,直接看下面的示例: public class ThreadLocalSimpleDateFormat { private static final ThreadLocal<SimpleDateFormat> formatter = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyyMMss HHmm")); public String formatDate(Date date) { return formatter.get().format(date); } } 使用 withIntial() 静态方法 初始化变量 调用 g...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
-
Docker使用Oracle官方镜像安装(12C,18C,19C)
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS8编译安装MySQL8.0.19
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
推荐阅读
最新文章
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- CentOS6,CentOS7官方镜像安装Oracle11G
- SpringBoot2整合Redis,开启缓存,提高访问速度
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- Hadoop3单机部署,实现最简伪集群
- MySQL8.0.19开启GTID主从同步CentOS8
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果