# 我的第一個雲端軟體 - NodeRED
## 1. 建立 "NodeRED" app
step 1: Login IBM Cloud https://cloud.ibm.com/login
step 2: 點選 "型錄" , 然後在左邊的選單中, 點選 "軟體" 後,再勾選 "入門範本套件", 就可以看到 Node-RED APP 範本套件 .
step 3: 點選 "Node-RED APP" 範本套件. "選取地區" 用預設值 "達拉斯", "定價方案" 點選 "精選". 使用預設的名稱(此名稱必須是"唯一"),然後點選右邊的 "建立" 按鈕.
## 2 部署 "NodeRED" app
step 1: 點選右邊的 "部屬您的應用程式" 按鈕
step 2: 部屬目標點選 "Cloud Foundry"
step 3: 點選建立 "IBM Cloud API 金鑰", 新建含有完整存取權的API金鑰, 並點選 "確定".
step 4: 往下拉並點選 "下一頁", 開始配置配屬自動化服務.
step 5: 點選 "Delivery Pipelines" 開始部署應用程式.
step 6: 等待部署完畢後, 開啟儀表板, 下拉 Cloud Foundry 應用程式並點選剛建立好的應用程式.
step 7: 點選頁面上方的 "訪問應用程式URL" 連結
step 8: 待 NodeRED 主控台顯示後, 點選 "下一頁", 並輸入 "Username" 及 "Password", 並點選 "Next" 按鈕. (請記下登入帳號及密碼) 避免日後忘記無法登入.
step 9: 點選 "Finish" 按鈕
step 10: 點選 "Get your Node-Red flow editor" 並輸入帳號及密碼, 登錄到 Node-Red 流程編輯器.
## 3. 設計/部署 IoT 流程
step 1: 登入 NodeRED 編輯器
step 2: 點選右邊的下拉式選單, 點選 "節點管理", 點選 "安裝" 頁面, 並搜尋 "ibmiot", 再安裝該程式.
step 3: 點選右邊的下拉式選單, 點選 "匯入", 將下列程式碼貼入對話框中, 點選 "新流程", 再點選 "匯入" 按鈕.
```json=
[{"id":"a5397b96.7a2838","type":"function","z":"e85ad8f2.359ef8","name":"temp","func":"return{payload:msg.payload.d.temp};","outputs":1,"x":836,"y":290,"wires":[["d84e493b.bf121"]]},{"id":"d84e493b.bf121","type":"switch","z":"e85ad8f2.359ef8","name":"temp thresh","property":"payload","rules":[{"t":"lte","v":"40"},{"t":"gt","v":"40"}],"checkall":"true","outputs":2,"x":985,"y":291,"wires":[["e1391083.435be"],["91efb4b4.3257f8"]]},{"id":"27a6cd52.56eefa","type":"debug","z":"e85ad8f2.359ef8","name":"cpustatus","active":true,"complete":"false","x":1296,"y":288,"wires":[]},{"id":"eeb38441.81e0f","type":"debug","z":"e85ad8f2.359ef8","name":"device data","active":true,"complete":"false","x":836,"y":201,"wires":[]},{"id":"e1391083.435be","type":"template","z":"e85ad8f2.359ef8","name":"safe","field":"payload","fieldType":"msg","syntax":"mustache","template":"Temperature({{payload}}) within safe limits","x":1149,"y":242,"wires":[["27a6cd52.56eefa"]]},{"id":"91efb4b4.3257f8","type":"template","z":"e85ad8f2.359ef8","name":"danger","field":"payload","fieldType":"msg","syntax":"mustache","template":"Temperature ({{payload}}) critical","x":1148,"y":336,"wires":[["27a6cd52.56eefa"]]},{"id":"ebeca570.9840c","type":"ibmiot in","z":"e85ad8f2.359ef8","authentication":"quickstart","apiKey":"","inputType":"evt","deviceId":"1c3118b56997","applicationId":"","deviceType":"+","eventType":"+","commandType":"","format":"json","name":"IBM IoT App In","service":"quickstart","allDevices":"","allApplications":"","allDeviceTypes":true,"allEvents":true,"allCommands":"","allFormats":"","x":622,"y":295,"wires":[["eeb38441.81e0f","a5397b96.7a2838"]]}]
```
step 4: 在另一個視窗開啟 IoT simulator, 複製模擬器右上方的ID.
http://quickstart.internetofthings.ibmcloud.com/iotsensor
step 5: 點選 "IBM IoT App in" 節點, 並將模擬器的 ID 貼入 "Device ID" 欄位.
step 6: 點選右上方 "部署" 按鈕.
step 7: 由 debug 視窗觀察模擬器的數字變化.