第一步:在節(jié)點(diǎn)管里下載“weather”揩魂,并安裝,如下圖:
第二步:在側(cè)邊欄找到“weather”并拖入流程炮温,如下圖:
第三步:在流程中拖入“function”火脉,并寫入以下代碼,如下圖:
let code;
code = msg.payload.current.weather;
switch(code) {
case '0':
status = '晴'
break;
case '1':
status = '多云'
break;
case '2':
status = '陰'
break;
case '3':
status = '陣雨'
break;
case '4':
status = '雷陣雨'
break;
case '5':
status = '雷陣雨并伴有冰雹'
break;
case '6':
status = '雨夾雪'
break;
case '7':
status = '小雨'
break;
case '8':
status = '中雨'
break;
case '9':
status = '大雨'
break;
case '10':
status = '暴雨'
break;
case '11':
status = '大暴雨'
break;
case '12':
status = '特大暴雨'
break;
case '13':
status = '陣雪'
break;
case '14':
status = '小雪'
break;
case '15':
status = '中雪'
break;
case '16':
status = '大雪'
break;
case '17':
status = '暴雪'
break;
case '18':
status = '霧'
break;
case '19':
status = '凍雨'
break;
case '20':
status = '沙塵暴'
break;
case '21':
status = '小雨轉(zhuǎn)中雨'
break;
case '22':
status = '中雨轉(zhuǎn)大雨'
break;
case '23':
status = '大雨轉(zhuǎn)暴雨'
break;
case '24':
status = '暴雨轉(zhuǎn)大暴雨'
break;
case '25':
status = '大暴雨轉(zhuǎn)特大暴雨'
break;
case '26':
status = '小雪轉(zhuǎn)中雪'
break;
case '27':
status = '中雪轉(zhuǎn)大雪'
break;
case '28':
status = '大雪轉(zhuǎn)暴雪'
break;
case '29':
status = '浮沉'
break;
case '30':
status = '揚(yáng)沙'
break;
case '31':
status = '強(qiáng)沙塵暴'
break;
case '32':
status = '颮'
break;
case '33':
status = '龍卷風(fēng)'
break;
case '34':
status = '若高吹雪'
break;
case '35':
status = '輕霧'
break;
case '53':
status = '霾'
break;
case '99':
status = '未知'
break;
default:
status = '無(wú)數(shù)據(jù)'
break;
}
return msg;
第四步:在流程中拖入“debug”柒啤,用于監(jiān)測(cè)調(diào)試窗口倦挂,如下圖:
第五步:在流程中拖入“l(fā)ink in”、“l(fā)inkout”用于做輸入輸出鏈接担巩,如下圖:
第六步:根據(jù)需要顯示的數(shù)據(jù)方援,在流程中拖入“function”,標(biāo)注相對(duì)應(yīng)的功能涛癌,這里我做的比較全面犯戏,依次按照順序代碼如下:
1,獲取天氣類型:
var result = {
payload: ""
}
var tq = msg.payload.current.weather;
switch(tq) {
case '0':
result.payload = '晴'
break;
case '1':
result.payload = '多云'
break;
case '2':
result.payload = '陰'
break;
case '3':
result.payload = '陣雨'
break;
case '4':
result.payload = '雷陣雨'
break;
case '5':
result.payload = '雷陣雨并伴有冰雹'
break;
case '6':
result.payload = '雨夾雪'
break;
case '7':
result.payload = '小雨'
break;
case '8':
result.payload = '中雨'
break;
case '9':
result.payload = '大雨'
break;
case '10':
result.payload = '暴雨'
break;
case '11':
result.payload = '大暴雨'
break;
case '12':
result.payload = '特大暴雨'
break;
case '13':
result.payload = '陣雪'
break;
case '14':
result.payload = '小雪'
break;
case '15':
result.payload = '中雪'
break;
case '16':
result.payload = '大雪'
break;
case '17':
result.payload = '暴雪'
break;
case '18':
result.payload = '霧'
break;
case '19':
result.payload = '凍雨'
break;
case '20':
result.payload = '沙塵暴'
break;
case '21':
result.payload = '小雨轉(zhuǎn)中雨'
break;
case '22':
result.payload = '中雨轉(zhuǎn)大雨'
break;
case '23':
result.payload = '大雨轉(zhuǎn)暴雨'
break;
case '24':
result.payload = '暴雨轉(zhuǎn)大暴雨'
break;
case '25':
result.payload = '大暴雨轉(zhuǎn)特大暴雨'
break;
case '26':
result.payload = '小雪轉(zhuǎn)中雪'
break;
case '27':
result.payload = '中雪轉(zhuǎn)大雪'
break;
case '28':
result.payload = '大雪轉(zhuǎn)暴雪'
break;
case '29':
result.payload = '浮沉'
break;
case '30':
result.payload = '揚(yáng)沙'
break;
case '31':
result.payload = '強(qiáng)沙塵暴'
break;
case '32':
result.payload = '颮'
break;
case '33':
result.payload = '龍卷風(fēng)'
break;
case '34':
result.payload = '若高吹雪'
break;
case '35':
result.payload = '輕霧'
break;
case '53':
result.payload = '霾'
break;
case '99':
result.payload = '未知'
break;
default:
result.payload = '無(wú)數(shù)據(jù)'
break;
}
return result;
2拳话,獲取體感溫度:
var result = {
payload: msg.payload.current.feelsLike.value
}
return result;
3先匪,獲取當(dāng)前溫度:
var result = {
payload: msg.payload.current.temperature.value
}
return result;
4,獲取當(dāng)前濕度:
var result = {
payload: msg.payload.current.humidity.value
}
return result;
5呀非,獲取當(dāng)前氣壓:
var result = {
payload: msg.payload.current.pressure.value
}
return result;
6猖败,獲取當(dāng)前風(fēng)速:
var result = {
payload: msg.payload.current.wind.speed.value
}
return result;
7恩闻,獲取當(dāng)前空氣質(zhì)量:
var result = {
payload: msg.payload.aqi.aqi
}
return result;
8,獲取當(dāng)前PM2.5:
var result = {
payload: msg.payload.aqi.pm25
}
return result;
9侠草,獲取未來(lái)14天的氣溫狀態(tài):
var payload = [{
"series": ["最低溫度", "最高溫度"],
"data": [
// [{ "x": 1504029632890, "y": 50 },
// { "x": 1504029636001, "y": 40 },
// { "x": 1504029638656, "y": 20 },
// { "x": 1504029640666, "y": 20 }
// ],
// [{ "x": 1504029633514, "y": 6 },
// { "x": 1504029636622, "y": 7 },
// { "x": 1504029639539, "y": 6 }
// ]
],
"labels": []
}];
var lTemp = [];
var hTemp = [];
var values = msg.payload.forecastDaily.temperature.value;
var date = new Date();
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);
var x = date.getTime();
for(var i in values) {
lTemp.push({
"x": x,
"y": values[i]['to']
});
hTemp.push({
"x": x,
"y": values[i]['from']
});
x = new Date(x + 24 * 60 * 60 * 1000).getTime();
}
payload[0].data.push(lTemp);
payload[0].data.push(hTemp);
return {
'payload': payload
};
10褂微,獲取PM10:
var result = {
payload: msg.payload.aqi.pm10
}
return result;
11宠蚂,獲取一氧化碳CO:
var result = {
payload: msg.payload.aqi.co
}
return result;
12:獲取二氧化氮NO2:
var result = {
payload: msg.payload.aqi.co
}
return result;
13:獲取臭氧O3:
var result = {
payload: msg.payload.aqi.o3
}
return result;
14:獲取二氧化硫SO2:
var result = {
payload: msg.payload.aqi.so2
}
return result;
15:獲取數(shù)據(jù)來(lái)源:
var result = {
payload: msg.payload.aqi.src
}
return result;
第七步:如果還想對(duì)一些獲取到的數(shù)據(jù)進(jìn)行進(jìn)一步的說(shuō)明,可以參考調(diào)試窗口的一些信息呀癣,如下圖:
第八步:在流程里鏈接相應(yīng)的模塊,如下圖:
第九步:進(jìn)入U(xiǎn)I界面,看一下效果列另,具體的一些表現(xiàn)方式還可以根據(jù)自己的實(shí)際需要調(diào)整,我做的如下圖拷姿,以供參考:
以上僅為個(gè)人參考網(wǎng)絡(luò)上眾多資料的一些實(shí)施操作描滔。