node-red retiveive JSON或CSV提要到InfluxDB

时间:2017-05-13 07:36:49

标签: javascript json csv node-red

版本

  • Node-RED v0.16.2
  • InfluxDB v1.2.2
  • Grafana v4.2.0
  • Ubuntu 16.04.2

我想从当地的官方气象站检索一些天气观测资料。我可以选择csv& JSON

  • 我尝试使用Node-RED检索JSON Feed。
  • 我使用了一个HTTP请求节点,该节点返回一个已解析的JSON对象

它返回这个嵌套数组:

对象

  • 观察: 对象
    • 通知: 数组[1]
    • 0: 对象
      • 版权所有:"版权所有2017年澳大利亚联邦,气象局。有关详细信息,请参阅:urlhere urlhere"
      • copyright_url:" urlhere"
      • disclaimer_url:" urlhere"
      • feedback_url:" urlhere"
    • 标题: 数组[1]
    • 0: 对象
      • refresh_message:"于美国东部时间2017年5月2日星期二下午9:32发布"
      • ID:" IDV60801"
      • main_ID:" IDV60800"
      • 名称:" Moorabbin Airport"
      • state_time_zone:" VIC"
      • time_zone:" EST"
      • product_name:"天气观察"
      • 州:" Victoria"
    • 数据: 数组[155]
    • [0 ... 9]
      • 0: 对象
      • sort_order: 0
      • wmo: 94870
      • 名称:" Moorabbin Airport"
      • history_product:" IDV60801"
      • local_date_time:" 02/09:30 pm"
      • local_date_time_full:" 20170502213000"
      • aifstime_utc:" 20170502113000"
      • lat: -38
      • lon: 145.1
      • apparent_t: 5.4
      • 云:" - "
      • cloud_base_m: null
      • cloud_oktas: null
      • cloud_type:" - "
      • cloud_type_id: null
      • delta_t: 2.5
      • gust_kmh: 19
      • gust_kt: 10
      • air_temp: 9
      • 露水: 3.2
      • 按: 1025.8
      • press_msl: 1025.8
      • press_qnh: 1025.8
      • press_tend:" - "
      • rain_trace:" 1.0"
      • rel_hum: 67
      • sea_state:" - "
      • swell_dir_worded:" - "
      • swell_height: null
      • swell_period: null
      • vis_km:" 10"
      • 天气:" - "
      • wind_dir:" ESE"
      • wind_spd_kmh: 11
      • * wind_spd_kt:** 6

我只想要 data:数组,所以我使用了一个函数节点" Extract Value"使用此代码:

msg.payload = msg.payload.observations.data[0] return msg;

上面的函数返回了这个对象:

  • sort_order: 0
  • wmo: 94870
  • 名称:" Moorabbin Airport"
  • history_product:" IDV60801"
  • local_date_time:" 02/09:30 pm"
  • local_date_time_full:" 20170502213000"
  • aifstime_utc:" 20170502113000"
  • lat: -38
  • lon: 145.1
  • apparent_t: 5.4
  • 云:" - "
  • cloud_base_m: null
  • cloud_oktas: null
  • cloud_type:" - "
  • cloud_type_id: null
  • delta_t: 2.5
  • gust_kmh: 19
  • gust_kt: 10
  • air_temp: 9
  • 露水: 3.2
  • 按: 1025.8
  • press_msl: 1025.8
  • press_qnh: 1025.8
  • press_tend:" - "
  • rain_trace:" 1.0"
  • rel_hum: 67
  • sea_state:" - "
  • swell_dir_worded:" - "
  • swell_height: null
  • swell_period: null
  • vis_km:" 10"
  • 天气:" - "
  • wind_dir:" ESE"
  • wind_spd_kmh: 11
  • wind_spd_kt: 6

如果我通过存储节点将其放入InfluxDB,我收到此错误:

  

错误:发生400错误请求错误:{"错误":"无法解析&bom-obs-moorabbin-airport aifstime_utc = \" 20170513070000 \& #34;,air_temp = 13.6,apparent_t = 10.6,浊= \" - \",cloud_base_m = NULL,cloud_oktas = NULL,cloud_type = \" - \",cloud_type_id =空,delta_t = 2.9,dewpt = 7.6,gust_kmh = 17,gust_kt = 9,history_product = \" IDV60801 \",LAT = -38,LOCAL_DATE_TIME = \" 13/05:00 \ ",local_date_time_full = \" 20170513170000 \",lon = 145.1,name = \" Moorabbin Airport \",press = 1023.5,press_msl = 1023.5,press_qnh = 1023.5, press_tend = \" - \",rain_trace = \" 0.0 \",rel_hum = 67,sea_state = \" - \",排序顺序= 0, swell_dir_worded = \" - \",swell_height = NULL,swell_period = NULL,vis_km = \" 10 \",天气= \" - \&#34 ;, wind_dir = \" SSW \",wind_spd_kmh = 13,wind_spd_kt = 7,wmo = 94870':无效号码"}

相反,如果我在" Extract Value"之间插入一个JSON节点。 &安培; InfluxDB存储节点,这是我得到的调试输出:

  

" {" sort_order":0," wmo":94870," name":" Moorabbin Airport",& #34; history_product":" IDV60801"" LOCAL_DATE_TIME":" 13/05:00 pm"," local_date_time_full":&# 34; 20170513170000"" aifstime_utc":" 20170513070000"" LAT": - 38" LON":145.1&# 34; apparent_t":10.6,"云":" - "" cloud_base_m":空," cloud_oktas":空, " cloud_type":" - "" cloud_type_id":空," delta_t":2.9," gust_kmh&#34 ;: 17," gust_kt":9," air_temp":13.6," dewpt":7.6,​​"按":1023.5," press_msl":1023.5," press_qnh":1023.5," press_tend":" - "" rain_trace":" 0.0"" rel_hum":67," sea_state":" - "" swell_dir_worded":" - "" swell_height":空," swell_period":空," vis_km":" 10""天气和#34;:" - "" wind_dir":" SSW""瓦特ind_spd_kmh":13," wind_spd_kt":7}"

当我将该JSON节点附加到InfluxDB存储节点时,没有抛出任何错误,但在InfluxDB中没有我可以在Grafana中查看,绘图或制表的值。

从该网站获取上述Feed并将其导入InfluxDB的最佳方法是什么,以便我可以在Grafana中以图形方式查看它?

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

return {
  payload: {
    data : msg.payload.observations.data[0]
  }
};