I am trying to post sensor data to google sheet ,but my sensor seems to... not wanna turn on
I appreciate any help in advance.
Sorry it is my first time post
here is code:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "WiFi.h"
#include <HTTPClient.h>
#include "time.h"
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 19800;
const int daylightOffset_sec = 0;
//WiFi credentials//
const char* ssid = "Jiawifi"; // change SSID
const char* password = "11223344"; // change password
// Google script ID and required credentials//
String GOOGLE_SCRIPT_ID = "AKfycbxtVXqjb9L2qIwc4BLZxkSvkVvWdw8pR2S5jinyXG8HWswZcfp_6CZjcSNyMD50vttb"; // change Gscript ID
int count = 0;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
//photoresistor setup//
delay(1000);
Serial.begin(115200);
delay(1000);
pinMode(13, INPUT);//選告GPIO 13作為輸入(光敏電阻)
//Wifi setup//
Serial.begin(115200);
Serial.println();
Serial.print("Connecting to wifi: ");
Serial.println(ssid);
Serial.flush();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Init and get the time
// configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
}
/******************************************************************************/
void loop() {
// wifi connected
if (WiFi.status() == WL_CONNECTED) {
static bool flag = false;
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("Failed to obtain time");
return;
}
// read in photoresistor value
int LightValue;
LightValue = analogRead(13);
Serial.println(LightValue);
// data post to goolge sheet
String urlFinal = "https://script.google.com/macros/s/"+GOOGLE_SCRIPT_ID+"/exec?"+"point=" + LightValue + "&holenumber=" + "1"+"&oneinhole="+"yes";
Serial.print("POST data to spreadsheet:");
Serial.println(urlFinal);
HTTPClient http;
http.begin(urlFinal.c_str());
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
int httpCode = http.GET();
Serial.print("HTTP Status Code: ");
Serial.println(httpCode);
http.end();
}
//count++;
delay(1000);
}