# Node-RED 連結MQTT 資料上傳至 Google Sheet服務
> [color=#40f1ef][name=LHB阿好伯, 2021/03/20][:earth_africa:](https://www.facebook.com/LHB0222/)
###### tags: `Node-RED`
![](https://i.imgur.com/XVmvGUI.jpg)
[TOC]
# 安裝節點
https://flows.nodered.org/node/node-red-contrib-google-sheets
搜尋google就可以看到本次使用的node-red-contrib-google-sheets套件
![](https://i.imgur.com/jcWfdjT.png)
![](https://i.imgur.com/ctcZ3kN.png)
在使用這節點之前需先完成
新增一個Google服務帳戶
下載服務帳戶的JSON金鑰
授予該帳戶訪問Google Sheet API的權限
最後再與服務帳戶的電子郵件地址共享Google Sheet
例如 nodered@nodered-12345.iam.gserviceaccount.com
# 連結google服務
## 建立服務帳戶
[:radio_button: 點擊我建立服務帳戶](https://console.cloud.google.com/iam-admin/serviceaccounts?_ga=2.184919274.-272657095.1578084478)
![](https://i.imgur.com/EAqtAty.png)
![](https://i.imgur.com/K7W3fYB.png)
![](https://i.imgur.com/Q7uPjVQ.png)
## 取得帳戶金鑰
點選帳戶信箱
![](https://i.imgur.com/AFEB6Sp.png)
建立或新增金鑰
![](https://i.imgur.com/nUdFLet.png)
![](https://i.imgur.com/q3RApNZ.png)
![](https://i.imgur.com/u1zV1Jx.png)
貼到節點中
![](https://i.imgur.com/beJpzpK.png)
## 開啟Google Sheet & Drive API
![](https://i.imgur.com/zciTrE6.png)
![](https://i.imgur.com/1H8xgj2.png)
![](https://i.imgur.com/Uu8fPsz.png)
![](https://i.imgur.com/VI6gb8F.png)
## 共用試算表
![](https://i.imgur.com/AFEB6Sp.png)
![](https://i.imgur.com/TPfKX1H.png)
# 測試結果
建立一個最基本的節點測試
![](https://i.imgur.com/s7kcVOP.png)
## 節點資料
```
[{"id":"86531bb5.4a6e48","type":"tab","label":"流程2","disabled":false,"info":""},{"id":"bb9215b2.f64bc8","type":"mqtt in","z":"86531bb5.4a6e48","name":"MQTT","topic":"","qos":"0","datatype":"utf8","broker":"","x":170,"y":180,"wires":[["8268adb1.6c9df"]]},{"id":"8268adb1.6c9df","type":"GSheet","z":"86531bb5.4a6e48","creds":"","method":"get","action":"","sheet":"","cells":"","flatten":false,"name":"Google Sheet","x":440,"y":180,"wires":[[]],"inputLabels":["1"],"outputLabels":["2"]}]
```
![](https://i.imgur.com/6DaTAoq.png)
### 試算表ID位置
![](https://i.imgur.com/megiG31.png)
[Node-RED 連結MQTT 資料上傳至 Google Sheet服務](https://youtu.be/KGNMTgtTqpE)
{%youtube KGNMTgtTqpE %}
JavaScript自1970年1月1日(UTC)
# [使用R Shiny抓取Google Sheet資料繪製圖片](/_FxwDfRATf-sQu2FzvKmOQ)
# 參考資料
https://flows.nodered.org/flow/a36ccbcfc43c264cda892383fe034fe3
https://flows.nodered.org/node/node-red-contrib-google-sheets
🌟全文可以至下方連結觀看或是補充
https://hackmd.io/@LHB-0222/NodeRED-GSeet
全文分享至
https://www.facebook.com/LHB0222/
https://www.instagram.com/ahb0222/
有疑問想討論的都歡迎於下方留言
喜歡的幫我分享給所有的朋友 \o/
有所錯誤歡迎指教
# [:page_with_curl: 全部文章列表](https://hackmd.io/@LHB-0222/AllWritings)
![](https://i.imgur.com/47HlvGH.png)