天天看點

IoT Studio服務開發MySQL資料流轉示例Demo

Step By Step

物聯網産品及裝置的建立

1、建立

産品
IoT Studio服務開發MySQL資料流轉示例Demo

2、導入物模型

IoT Studio服務開發MySQL資料流轉示例Demo
IoT Studio服務開發MySQL資料流轉示例Demo
IoT Studio服務開發MySQL資料流轉示例Demo

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服務開發MySQL資料流轉示例Demo

IoT Studio綁定産品+裝置

1、建立項目

IoT Studio服務開發MySQL資料流轉示例Demo

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

IoT Studio服務開發MySQL資料流轉示例Demo

3、建立業務服務

IoT Studio服務開發MySQL資料流轉示例Demo
IoT Studio服務開發MySQL資料流轉示例Demo

4、業務流程搭建

IoT Studio服務開發MySQL資料流轉示例Demo
IoT Studio服務開發MySQL資料流轉示例Demo
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 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、部署調試

IoT Studio服務開發MySQL資料流轉示例Demo
IoT Studio服務開發MySQL資料流轉示例Demo
IoT Studio服務開發MySQL資料流轉示例Demo

2、資料流轉檢視

IoT Studio服務開發MySQL資料流轉示例Demo

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

IoT Studio服務開發MySQL資料流轉示例Demo

參考連結

雲資料庫MySQL IoT Studio 服務開發概述