Eclipse Ditto 物模型相关代码

一、概述

本文主要就Hello World 教程 • Eclipse Ditto™ • 数字孪生框架 文章做一个梳理,归纳。

二、完整代码如下

复制代码
{
  "thingId": "io.eclipseprojects.ditto:floor-lamp-0815",
  "policyId": "io.eclipseprojects.ditto:floor-lamp-0815",
  "definition": "https://eclipse-ditto.github.io/ditto-examples/wot/models/floor-lamp-1.0.0.tm.jsonld",
  "attributes": {
    "manufacturer": "",
    "serialNo": ""
  },
  "features": {
    "Spot1": {
      "definition": [
        "https://eclipse-ditto.github.io/ditto-examples/wot/models/dimmable-colored-lamp-1.0.0.tm.jsonld",
        "https://eclipse-ditto.github.io/ditto-examples/wot/models/colored-lamp-1.0.0.tm.jsonld",
        "https://eclipse-ditto.github.io/ditto-examples/wot/models/switchable-1.0.0.tm.jsonld"
      ],
      "properties": {
        "dimmer-level": 0,
        "color": { "r": 0, "g": 0, "b": 0 },
        "on": false
      }
    },
    "Spot2": {
      "definition": [
        "https://eclipse-ditto.github.io/ditto-examples/wot/models/dimmable-colored-lamp-1.0.0.tm.jsonld",
        "https://eclipse-ditto.github.io/ditto-examples/wot/models/colored-lamp-1.0.0.tm.jsonld",
        "https://eclipse-ditto.github.io/ditto-examples/wot/models/switchable-1.0.0.tm.jsonld"
      ],
      "properties": {
        "dimmer-level": 0,
        "color": { "r": 0, "g": 0, "b": 0 },
        "on": false
      }
    },
    "Spot3": {
      "definition": [
        "https://eclipse-ditto.github.io/ditto-examples/wot/models/dimmable-colored-lamp-1.0.0.tm.jsonld",
        "https://eclipse-ditto.github.io/ditto-examples/wot/models/colored-lamp-1.0.0.tm.jsonld",
        "https://eclipse-ditto.github.io/ditto-examples/wot/models/switchable-1.0.0.tm.jsonld"
      ],
      "properties": {
        "dimmer-level": 0,
        "color": { "r": 0, "g": 0, "b": 0 },
        "on": false
      }
    },
    "ConnectionStatus": {
      "definition": [
        "https://eclipse-ditto.github.io/ditto-examples/wot/models/connection-status-1.0.0.tm.jsonld"
      ],
      "properties": {
        "readySince": "",
        "readyUntil": ""
      }
    },
    "PowerConsumptionAwareness": {
      "definition": [
        "https://eclipse-ditto.github.io/ditto-examples/wot/models/power-consumption-aware-1.0.0.tm.jsonld"
      ],
      "properties": {
        "reportPowerConsumption": {}
      }
    },
    "SmokeDetection": {
      "definition": [
        "https://eclipse-ditto.github.io/ditto-examples/wot/models/smoke-detector-1.0.0.tm.jsonld"
      ]
    },
    "Status-LED": {
      "definition": [
        "https://eclipse-ditto.github.io/ditto-examples/wot/models/colored-lamp-1.0.0.tm.jsonld",
        "https://eclipse-ditto.github.io/ditto-examples/wot/models/switchable-1.0.0.tm.jsonld"
      ],
      "properties": {
        "color": { "r": 0, "g": 0, "b": 0 },
        "on": false
      }
    }
  }
}

三、创建一个物模型

(1)创建"落地灯"的数字孪生设备

bash 复制代码
curl -u ditto:ditto -X PUT -H 'Content-Type: application/json' -d '{
  "definition": "https://eclipse-ditto.github.io/ditto-examples/wot/models/floor-lamp-1.0.0.tm.jsonld",
  "attributes": {
    "manufacturer": "ACME",
    "serialNo": "0815666337"
  }
}' 'http://localhost:8080/api/2/things/io.eclipseprojects.ditto:floor-lamp-0815'

(2)通过ID查询该设备

bash 复制代码
curl -u ditto:ditto -X GET \
  'http://localhost:8080/api/2/things/io.eclipseprojects.ditto:floor-lamp-0815' | jq

# if you have python installed, that's an alternative for pretty-printing:
curl -u ditto:ditto -X GET \
  'http://localhost:8080/api/2/things/io.eclipseprojects.ditto:floor-lamp-0815' | python -m json.tool

(3)添加带有状态的功能

添加一个特征来表示灯的第一个聚光灯。特征保存动态状态数据,如 传感器读数或设备配置:

bash 复制代码
curl -u ditto:ditto -X PUT -H 'Content-Type: application/json' -d '{
  "properties": {
    "on": false,
    "dimmer-level": 0,
    "color": { "r": 0, "g": 0, "b": 0 }
  }
}' 'http://localhost:8080/api/2/things/io.eclipseprojects.ditto:floor-lamp-0815/features/Spot1'

(4)检索当前灯的状态

例如:检索 当前开关状态:Spot1

bash 复制代码
curl -u ditto:ditto -X GET \
  'http://localhost:8080/api/2/things/io.eclipseprojects.ditto:floor-lamp-0815/features/Spot1/properties/on'

四、更新物模型数据

(1)通过更新灯具属性来点亮灯具:on

bash 复制代码
curl -u ditto:ditto -X PUT -H 'Content-Type: application/json' -d 'true' \
  'http://localhost:8080/api/2/things/io.eclipseprojects.ditto:floor-lamp-0815/features/Spot1/properties/on'

(2)查询产品

bash 复制代码
curl -u ditto:ditto -X GET \
  'http://localhost:8080/api/2/search/things?filter=eq(attributes/manufacturer,"ACME")'
相关推荐
苏生Susheng5 分钟前
【软件实施】Linux企业运维常用命令手册
java·linux·运维·服务器·springboot·springcloud·软件实施
想要成为老金高手6 分钟前
Kubernetes 调度器详解:从 nodeName 到污点容忍
java·容器·kubernetes
吴长建先生重名了9 分钟前
ElasticSearch 检索系统性能优化实战:基准测试
java
西索斯coding18 分钟前
doubao-seed-2.1-turbo 调用一直 401 怎么办?pro 版同样的 Key 却正常——5 分钟排查定位指南
java·服务器·数据库·ai
OsDepK23 分钟前
xcode应用构建至testflight测试流程
ide·macos·xcode
旧梦952724 分钟前
Java SortedMap 接口详解:从入门到实战
java·开发语言
莫陌尛.28 分钟前
Java_this构造方法
java·开发语言
2601_962297251 小时前
C# vs Java vs Python:YOLO工业部署性能对比实战
java·python·c·工业视觉·性能对比
计算机毕设定制辅导-无忧学长1 小时前
《基于SpringBoot的马术俱乐部管理系统》
java·spring boot·后端
Dreams°1231 小时前
【Java后端+Vue前后端分离:内网正常、公网访问异常|5个高频经典踩坑完整复盘】
java·开发语言·vue.js