- 积分
- 6053
- 金钱
- 3980
- 威望
- 0
- 贡献
- 0
- HASS币
- 145
论坛元老
流水无味
- 积分
- 6053
- 金钱
- 3980
- HASS币
- 145
|
本帖最后由 xieahui 于 2019-5-6 16:29 编辑
24元的那个GPS模块F大获取的JSON是下面这样的格式
求大神帮忙转换下只需要longitude和latitude的JSON格式
然后MQTT给homeassistant
{
"ret": 0,
"msg": "OK",
"data": [
{
"imei": "862964024393013",
"name": "RW67",
"dev_type": "W1",
"device_info": 0,
"device_info_new": 4,
"seconds": 20387,
"gps_time": 1556757183,
"sys_time": 1556757179,
"heart_time": 1556777550,
"server_time": 1556777566,
"lng": 121.15726,
"lat": 28.338941,
"course": ……………………
"group_id": 0
}
]
}
//帮忙转换成下面这种格式让HA-MQTT-device_tracker
{
"longitude": 121.15726,
"latitude": 28.338941
}
下面是node red的大神帮忙转换下啊 不懂JSON自己去百度google搞不定
以下是nodered代码或文件
[{"id":"8924f1d0.5a5fb","type":"tab","label":"1","disabled":false,"info":""},{"id":"9a1fa073.93115","type":"mqtt out","z":"8924f1d0.5a5fb","name":"","topic":"phone/location/tracker","qos":"","retain":"","broker":"64f0b1f0.c4999","x":580,"y":220,"wires":[]},{"id":"bafaf3da.574a","type":"inject","z":"8924f1d0.5a5fb","name":"手动输入GPS","topic":"","payload":"{ "ret": 0, "msg": "OK", "data": [ { "imei": "862964024393013", "name": "RW67", "dev_type": "W1", "device_info": 0, "device_info_new": 4, "seconds": 20387, "gps_time": 1556757183, "sys_time": 1556757179, "heart_time": 1556777550, "server_time": 1556777566, "lng": 121.15726, "lat": 28.338941, "course": 88, "speed": 11, "status": "01390488000000000001000000000000", "power": "51%", "location": "GPS", "acc": "-1", "acc_seconds": 0, "group_id": 0 } ] }","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":250,"y":220,"wires":[["9a1fa073.93115","26d49fba.9442c","40f39ac0.ecbec4"]]},{"id":"40f39ac0.ecbec4","type":"debug","z":"8924f1d0.5a5fb","name":"成功","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":590,"y":280,"wires":[]},{"id":"26d49fba.9442c","type":"function","z":"8924f1d0.5a5fb","name":"解析求助","func":"const longitude = msg.payload.msg\nconst latitude = msg.payload.msg\nreturn {longitude,latitude}\n\n//我乱写的","outputs":1,"noerr":0,"x":420,"y":280,"wires":[["40f39ac0.ecbec4"]]},{"id":"64f0b1f0.c4999","type":"mqtt-broker","z":"","name":"","broker":"192.168.203.205","port":"1883","clientid":"203205","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
flows-求助.rar
(987 Bytes, 下载次数: 11)
|
|