AWS IoT规则查询语句用于数组JSON负载。

huangapple go评论90阅读模式
英文:

AWS IoT Rule Query Statement for the Array JSON payload

问题

如何使用AWS IoT规则查询语句从以下MQTT有效负载中获取温度和湿度到'example'主题?

  1. [
  2. {
  3. "timestamp": "2019-08-26T14:21:46Z",
  4. "type": "Gateway",
  5. "mac": "XXYYZZXXYYZZ",
  6. "gatewayFree": 96,
  7. "gatewayLoad": 0.26
  8. },
  9. {
  10. "timestamp": "2019-08-26T14:21:46Z",
  11. "type": "S1",
  12. "mac": "XXYYZZXXYYXX",
  13. "bleName": "",
  14. "rssi": -53,
  15. "battery": 100,
  16. "temperature": 0.69,
  17. "humidity": 37.28
  18. },
  19. {
  20. "timestamp": "2019-08-26T14:21:46Z",
  21. "type": "iBeacon",
  22. "mac": "XXYYZZXXYYYY",
  23. "bleName": "",
  24. "ibeaconUuid": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
  25. "ibeaconMajor": 0,
  26. "ibeaconMinor": 0,
  27. "rssi": -64,
  28. "ibeaconTxPower": -59,
  29. "battery": 0
  30. }
  31. ]

到目前为止,我在AWS IoT SQL参考文档中找不到相关信息。

英文:

How to use AWS IoT Rule Query Statement to get temperature and humidity from the following MQTT payload to 'example' topic?

  1. [
  2. {
  3. "timestamp": "2019-08-26T14:21:46Z",
  4. "type": "Gateway",
  5. "mac": "XXYYZZXXYYZZ",
  6. "gatewayFree": 96,
  7. "gatewayLoad": 0.26
  8. },
  9. {
  10. "timestamp": "2019-08-26T14:21:46Z",
  11. "type": "S1",
  12. "mac": "XXYYZZXXYYXX",
  13. "bleName": "",
  14. "rssi": -53,
  15. "battery": 100,
  16. "temperature": 0.69,
  17. "humidity": 37.28
  18. },
  19. {
  20. "timestamp": "2019-08-26T14:21:46Z",
  21. "type": "iBeacon",
  22. "mac": "XXYYZZXXYYYY",
  23. "bleName": "",
  24. "ibeaconUuid": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
  25. "ibeaconMajor": 0,
  26. "ibeaconMinor": 0,
  27. "rssi": -64,
  28. "ibeaconTxPower": -59,
  29. "battery": 0
  30. }
  31. ]

So far, I cannot find it on AWS IoT SQL Reference.

答案1

得分: 2

尝试这个,它正在工作!

  1. SELECT (SELECT temperature, humidity from input) as output FROM 'iot/topic'

我已经修改了输入JSON,添加了一个,请参见下面的内容。

这是修改后的输入:

  1. {
  2. "input": [ ... your json array elements ... ]
  3. }

这是输出:

  1. {
  2. "output": [
  3. {},
  4. {
  5. "temperature": 0.69,
  6. "humidity": 37.28
  7. },
  8. {}
  9. ]
  10. }

祝好,
拉姆

英文:

Try this, it's working!

  1. SELECT (SELECT temperature, humidity from input) as output FROM 'iot/topic'

I have modified the input JSON to have a key -- see below.

Here is the modified input:

  1. {
  2. "input": [ ... your json array elements ... ]
  3. }

Here is the output:

  1. {
  2. "output": [
  3. {},
  4. {
  5. "temperature": 0.69,
  6. "humidity": 37.28
  7. },
  8. {}
  9. ]
  10. }

cheers,
ram

答案2

得分: 0

{
"sql": "SELECT * FROM 'iot/example' WHERE mac = 'XXYYZZXXYYXX'",
...
}

Cheers!

英文:

Also try this one...

  1. {
  2. "sql": "SELECT * FROM 'iot/example' WHERE mac = 'XXYYZZXXYYXX'",
  3. ...
  4. }

Cheers!

huangapple
  • 本文由 发表于 2020年1月4日 01:01:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/59582464.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定