Json 节点红色:解释REST服务URL
我目前正在使用IBM Bluemix IoT Quickstart进行一些实验。对于那些不知道这一点的人来说,这是一个物联网传感器模拟器,可以用来控制温度和湿度值 我希望使用web服务连接器查找温度读数。我将如何解释此服务的服务URL 另外(但不是那么重要!)我看到网站/test/没有显示温度读数。你知道为什么吗 下面是web服务用来显示温度的jsonJson 节点红色:解释REST服务URL,json,ibm-cloud,iot,node-red,Json,Ibm Cloud,Iot,Node Red,我目前正在使用IBM Bluemix IoT Quickstart进行一些实验。对于那些不知道这一点的人来说,这是一个物联网传感器模拟器,可以用来控制温度和湿度值 我希望使用web服务连接器查找温度读数。我将如何解释此服务的服务URL 另外(但不是那么重要!)我看到网站/test/没有显示温度读数。你知道为什么吗 下面是web服务用来显示温度的json [ { "id": "e42c6f27.46cca", "type": "function", "z": "3ed4
[
{
"id": "e42c6f27.46cca",
"type": "function",
"z": "3ed49b1f.4c1164",
"name": "temp",
"func": "return {payload:msg.payload.d.temp};",
"outputs": 1,
"noerr": 0,
"x": 422.5,
"y": 775,
"wires": [
[
"c76cd036.bc2ba"
]
]
},
{
"id": "f47256cd.a18b78",
"type": "template",
"z": "3ed49b1f.4c1164",
"name": "",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "The temperature is\n{{payload}}\n",
"output": "str",
"x": 775,
"y": 953,
"wires": [
[
"22b54d74.028ae2"
]
]
},
{
"id": "22b54d74.028ae2",
"type": "http response",
"z": "3ed49b1f.4c1164",
"name": "",
"statusCode": "",
"headers": {
},
"x": 1064,
"y": 955,
"wires": [
]
},
{
"id": "243d218a.fe14ae",
"type": "http in",
"z": "3ed49b1f.4c1164",
"name": "",
"url": "test",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 432,
"y": 993,
"wires": [
[
"f47256cd.a18b78"
]
]
},
{
"id": "429ffb9e.7ed404",
"type": "ibmiot in",
"z": "3ed49b1f.4c1164",
"authentication": "quickstart",
"apiKey": "",
"inputType": "evt",
"deviceId": "3bd1c8df5ed2",
"applicationId": "",
"deviceType": "iotqs-sensor",
"eventType": "+",
"commandType": "",
"format": "json",
"name": "IBM IoT App In",
"service": "quickstart",
"allDevices": false,
"allApplications": false,
"allDeviceTypes": true,
"allEvents": true,
"allCommands": false,
"allFormats": false,
"x": 269,
"y": 550,
"wires": [
[
"55064d15.005804",
"c34674a2.7ea0d8",
"2356b867.1c3d68",
"c7ee16c4.493fc8",
"e42c6f27.46cca"
]
]
},
{
"id": "55064d15.005804",
"type": "debug",
"z": "3ed49b1f.4c1164",
"name": "name",
"active": true,
"complete": "payload.d.name",
"x": 717.5,
"y": 551,
"wires": [
]
},
{
"id": "c34674a2.7ea0d8",
"type": "debug",
"z": "3ed49b1f.4c1164",
"name": "Temperature",
"active": true,
"complete": "payload.d.temp",
"x": 717.5,
"y": 651,
"wires": [
]
},
{
"id": "2356b867.1c3d68",
"type": "debug",
"z": "3ed49b1f.4c1164",
"name": "Humidity",
"active": true,
"complete": "payload.d.humidity",
"x": 717.5,
"y": 751,
"wires": [
]
},
{
"id": "c7ee16c4.493fc8",
"type": "debug",
"z": "3ed49b1f.4c1164",
"name": "Object Temperature",
"active": true,
"complete": "payload.d.objectTemp",
"x": 717.5,
"y": 851,
"wires": [
]
},
{
"id": "c76cd036.bc2ba",
"type": "json",
"z": "3ed49b1f.4c1164",
"name": "",
"pretty": true,
"x": 531,
"y": 894,
"wires": [
[
"f47256cd.a18b78"
]
]
}
]
此流程存在一些问题:
- JSON节点不是必需的,因为msg.payload已经是JSON了
节点的输出读数被发送到iot
节点,只有当流从API调用返回结果时才需要该节点http响应
节点的输出不包含msg.payload,因此http in
节点没有要格式化的内容template
- 将输出对象
存储到名为“LastReaders”的流上下文变量中msg.payload.d
- 使用带有url/last/:type的
节点中的
http作为api端点,以检索给定传感器类型的最后一个值(如果已安装
,则可以直接从右侧边栏测试端点)节点红色节点摆动器
- 使用交换机节点根据传感器类型路由api调用,以检索最后一次读取并通过
节点返回输出字符串http响应
httpRoot
或httpNodeRoot
url前缀,这将优先于api url——这可能就是您在尝试访问url“”时没有结果的原因。检查http in节点上的注释,了解类似以下内容:
url将与/red相对
在这种情况下,您需要使用api url“”
以下是我创建的流,以及用于测试值的注入节点(因为我没有可用的ibmiot输入节点):
请注意,我将api url更改为使用
/last/{type}
语法。。。其中,{type}
替换为msg.payload.d
对象中的字段名称。非常感谢!
[
{
"id": "5ebe7dff.780724",
"type": "template",
"z": "7299298e.a9f058",
"name": "output value",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "Last {{sensor}} reading:\n{{payload}}\n",
"output": "str",
"x": 630,
"y": 720,
"wires": [
[
"cb13c651.0ef458",
"efabaec0.9bd7a"
]
]
},
{
"id": "cb13c651.0ef458",
"type": "http response",
"z": "7299298e.a9f058",
"name": "",
"statusCode": "",
"headers": {},
"x": 790,
"y": 760,
"wires": []
},
{
"id": "361c51b4.f519ae",
"type": "http in",
"z": "7299298e.a9f058",
"name": "",
"url": "/last/:type",
"method": "get",
"upload": false,
"swaggerDoc": "59b72c5b.bc0fb4",
"x": 150,
"y": 640,
"wires": [
[
"c2fb1169.b76e8",
"61234f00.7faf1"
]
]
},
{
"id": "884f3eb9.e22be",
"type": "debug",
"z": "7299298e.a9f058",
"name": "payload.d values",
"active": true,
"console": "false",
"complete": "payload.d",
"x": 470,
"y": 480,
"wires": []
},
{
"id": "fef6db49.919728",
"type": "comment",
"z": "7299298e.a9f058",
"name": "Save the last readings to flow context",
"info": "",
"x": 210,
"y": 440,
"wires": []
},
{
"id": "81bfb514.a63348",
"type": "change",
"z": "7299298e.a9f058",
"name": "save readings",
"rules": [
{
"t": "set",
"p": "lastReadings",
"pt": "flow",
"to": "payload.d",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 460,
"y": 520,
"wires": [
[]
]
},
{
"id": "9573eab5.84e548",
"type": "comment",
"z": "7299298e.a9f058",
"name": "API endpoints to retrieve sensor values",
"info": "",
"x": 210,
"y": 600,
"wires": []
},
{
"id": "c2fb1169.b76e8",
"type": "switch",
"z": "7299298e.a9f058",
"name": "sensor type",
"property": "req.params.type",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "temp",
"vt": "str"
},
{
"t": "eq",
"v": "humidity",
"vt": "str"
},
{
"t": "eq",
"v": "objectTemp",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"outputs": 4,
"x": 250,
"y": 700,
"wires": [
[
"4eb4657b.cd0b0c"
],
[
"801c0b28.320308"
],
[
"a7833d28.f58f"
],
[
"e30f26ce.a084b8"
]
]
},
{
"id": "4eb4657b.cd0b0c",
"type": "change",
"z": "7299298e.a9f058",
"name": "Temperature",
"rules": [
{
"t": "set",
"p": "sensor",
"pt": "msg",
"to": "Temperature",
"tot": "str"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "lastReadings.temp",
"tot": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 450,
"y": 680,
"wires": [
[
"5ebe7dff.780724"
]
]
},
{
"id": "801c0b28.320308",
"type": "change",
"z": "7299298e.a9f058",
"name": "Humidity",
"rules": [
{
"t": "set",
"p": "sensor",
"pt": "msg",
"to": "Humidity",
"tot": "str"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "lastReadings.humidity",
"tot": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 440,
"y": 720,
"wires": [
[
"5ebe7dff.780724"
]
]
},
{
"id": "a7833d28.f58f",
"type": "change",
"z": "7299298e.a9f058",
"name": "Object Temp",
"rules": [
{
"t": "set",
"p": "sensor",
"pt": "msg",
"to": "Object Temp",
"tot": "str"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "lastReadings.objectTemp",
"tot": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 450,
"y": 760,
"wires": [
[
"5ebe7dff.780724"
]
]
},
{
"id": "61234f00.7faf1",
"type": "debug",
"z": "7299298e.a9f058",
"name": "API params",
"active": false,
"console": "false",
"complete": "true",
"x": 450,
"y": 640,
"wires": []
},
{
"id": "efabaec0.9bd7a",
"type": "debug",
"z": "7299298e.a9f058",
"name": "API out",
"active": true,
"console": "false",
"complete": "payload",
"x": 800,
"y": 720,
"wires": []
},
{
"id": "b019dd18.1806e",
"type": "inject",
"z": "7299298e.a9f058",
"name": "test values",
"topic": "",
"payload": "{\"d\":{\"temp\":21,\"humidity\":69,\"objectTemp\":\"NA\"}}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"x": 150,
"y": 520,
"wires": [
[
"81bfb514.a63348",
"884f3eb9.e22be"
]
]
},
{
"id": "e30f26ce.a084b8",
"type": "change",
"z": "7299298e.a9f058",
"name": "invalid type",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "Error! Unknown sensor type...",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 450,
"y": 800,
"wires": [
[
"cb13c651.0ef458"
]
]
},
{
"id": "e02d2f38.842d8",
"type": "ibmiot in",
"z": "7299298e.a9f058",
"authentication": "quickstart",
"apiKey": "",
"inputType": "evt",
"deviceId": "3bd1c8df5ed2",
"applicationId": "",
"deviceType": "iotqs-sensor",
"eventType": "+",
"commandType": "",
"format": "json",
"name": "IBM IoT App In",
"service": "quickstart",
"allDevices": false,
"allApplications": false,
"allDeviceTypes": true,
"allEvents": true,
"allCommands": false,
"allFormats": false,
"x": 150,
"y": 480,
"wires": [
[
"884f3eb9.e22be",
"81bfb514.a63348"
]
]
},
{
"id": "59b72c5b.bc0fb4",
"type": "swagger-doc",
"z": "",
"summary": "Retrieve last sensor reading",
"description": "",
"tags": "",
"consumes": "",
"produces": "",
"parameters": [
{
"name": "type",
"in": "path",
"description": "Sensor type",
"required": true,
"type": "string"
}
],
"responses": {},
"deprecated": false
}
]