WebIoT

ESP32 ghi dữ liệu cảm biến lên Google Sheets miễn phí — không cần server

BiLiChip · 10:30:59 3/12/2026 · 0 lượt xem

Muốn xem log nhiệt độ/độ ẩm ở nhà từ xa mà không muốn dựng server → ghi thẳng lên Google Sheets qua Apps Script Web App. Miễn phí, đủ cho vài nghìn bản ghi.

Bước 1 — Tạo Google Sheet + Apps Script

  1. Tạo sheet mới, đặt header dòng 1: thoigian | nhietdo | doam
  2. Extensions → Apps Script, dán:
function doGet(e) {
  const sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  sh.appendRow([new Date(), e.parameter.t, e.parameter.h]);
  return ContentService.createTextOutput("OK");
}
  1. Deploy → New deployment → type Web app → Execute as: Me → Who has access: Anyone → Deploy → copy URL /exec.

Bước 2 — Code ESP32

#include <WiFi.h>
#include <HTTPClient.h>
#include <DHT.h>
DHT dht(4, DHT22);
const char* URL = "https://script.google.com/macros/s/XXXX/exec";

void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    float t = dht.readTemperature(), h = dht.readHumidity();
    if (!isnan(t)) {
      HTTPClient http;
      http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
      http.begin(URL + "?t=" + String(t) + "&h=" + String(h));
      http.GET();
      http.end();
    }
  }
  delay(300000);   // 5 phut/lan - free tier du
}

Lưu ý

  • Apps Script redirect nên bắt buộc setFollowRedirects.
  • Free quota ~20.000 request/ngày — gửi 5–10 phút/lần là an toàn.
  • Xem chart trực tiếp trong Google Sheets: Insert → Chart trên cột dữ liệu.
  • Muốn nhanh hơn realtime thì chuyển sang MQTT/Blynk; Sheets hợp log dài hạn.

0 câu trả lời

Đăng nhập để trả lời câu hỏi này.