• 使用Rest连接MindSphere IoT Extention


    ==官网链接==

    https://cumulocity.com/guides/device-sdk/rest/#overview

    ==概述==

    启动阶段将设备连接到Cumulocity IoT,并更新清单中的设备数据。它还执行操作所需的清理任务。它包括以下步骤:

    • 步骤0:请求设备凭据(如果尚未请求)。
    • 步骤1:检查设备是否已经注册。
    • 步骤2:如果没有,请在清单中创建设备,然后
    • 步骤3:注册设备。
    • 步骤4:如果是,请更新清单中的设备。
    • 步骤5:发现子设备并在清单中创建或更新它们。
    • 步骤6:完成需要重新启动的操作并订阅新操作。

    启动阶段

    循环阶段如下。它会不断更新清单,写入测量值,警报和事件并根据需要执行操作。可以将其视为设备关闭之前执行的设备“主循环”。该循环包括以下步骤:

    循环阶段

    数据的参考模型可以在设备管理库参考指南传感器库中找到。

    ==Authorization==

    使用BasicAuth,输入用户名和密码。

    ==创建一个新设备==

    POST:https://{tenant}.mciotextension.cn1.mindsphere-in.cn/inventory/managedObjects

    Content-Type:application/vnd.com.nsn.cumulocity.managedObject+json

    Accept:application/vnd.com.nsn.cumulocity.managedObject+json

    Request Body:

    {
        "c8y_IsDevice" : {},
        "name" : "RestDevice0408"
    }

    Response Body:

    {
        "owner": "{username}",
        "additionParents": {
            "self": "https://{tenant}.mciotextension.cn1.mindsphere-in.cn/inventory/managedObjects/21802/additionParents",
            "references": []
        },
        "childDevices": {
            "self": "https://{tenant}.mciotextension.cn1.mindsphere-in.cn/inventory/managedObjects/21802/childDevices",
            "references": []
        },
        "childAssets": {
            "self": "https://{tenant}.mciotextension.cn1.mindsphere-in.cn/inventory/managedObjects/21802/childAssets",
            "references": []
        },
        "creationTime": "2020-04-08T15:15:57.302+08:00",
        "lastUpdated": "2020-04-08T15:15:57.302+08:00",
        "childAdditions": {
            "self": "https://{tenant}.mciotextension.cn1.mindsphere-in.cn/inventory/managedObjects/21802/childAdditions",
            "references": []
        },
        "name": "RestDevice0408",
        "assetParents": {
            "self": "https://{tenant}.mciotextension.cn1.mindsphere-in.cn/inventory/managedObjects/21802/assetParents",
            "references": []
        },
        "deviceParents": {
            "self": "https://{tenant}.mciotextension.cn1.mindsphere-in.cn/inventory/managedObjects/21802/deviceParents",
            "references": []
        },
        "self": "https://{tenant}.mciotextension.cn1.mindsphere-in.cn/inventory/managedObjects/21802",
        "id": "21802",
        "c8y_IsDevice": {}
    }

    Postman截图

    ==注册设备==

    创建新设备后,现在可以按照步骤1中所述将其与内置标识符相关联。这确保了该设备在下一次启动后就可以在Cumulocity IoT中找到自己。

    如果不进行设备注册,后面也无法通过c8y_Serial获取设备。

    POST:https://{tenant}.mciotextension.cn1.mindsphere-in.cn/identity/globalIds/21802/externalIds

    Content-Type:application/vnd.com.nsn.cumulocity.externalId+json

    Accept:application/vnd.com.nsn.cumulocity.externalId+json

    Request Body:

    {
        "type" : "c8y_Serial",
        "externalId" : "serial202004081525"
    }

    ==更新设备==

    PUT:https://{tenant}.mciotextension.cn1.mindsphere-in.cn/inventory/managedObjects/21802

    Content-Type:application/vnd.com.nsn.cumulocity.managedObject+json

    Request Body:

    {
        "c8y_Software": {
            "pi-driver": "pi-driver-3.4.6.jar",
            "pi4j-gpio-extension": "pi4j-gpio-extension-0.0.5.jar"
        }
    }

    Postman截图:

    ==发送测量数据==

    POST:https://{tenant}.mciotextension.cn1.mindsphere-in.cn/measurement/measurements

    Content-Type:application/vnd.com.nsn.cumulocity.measurement+json

    Request Body:

    {
        "source": {
            "id": "21802"
        },
        "time": "2020-04-08T15:52:40.152",
        "type": "mytype",
        "MyMeasurement": {
            "AR_TEST_VAR1": {
                "value": 15,
                "unit": "dBm"
            },
            "AR_TEST_VAR2": {
                "value": 25,
                "unit": "%"
            },
            "AR_TEST_VAR3": {
                "value": 30,
                "unit": ""
            }
        }
    }

    Postman截图:

    --END--

  • 相关阅读:
    java基础(初始化和清理)
    jquery的常用操作(转载)+ 开发中经常犯的错误总结(原创) (不断补充)
    java基础常见错误归纳(值传递和引用传递)
    FormPanel 综合使用 忆江南
    MyEclipse下Jquery代码自动提示 忆江南
    HQL查询 忆江南
    MD5密码保护 忆江南
    FormPanel数据提交 忆江南
    新手上路
    编码总结,以及对BOM的理解
  • 原文地址:https://www.cnblogs.com/quchunhui/p/12626796.html
Copyright © 2020-2023  润新知