#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <WiFiClientSecure.h>
#include <FastLED.h>

#define LED_PIN 2
#define NUM_LEDS 8

CRGB leds[NUM_LEDS];

const char* ssid = "YOURWIFINAME";
const char* password = "PASSWORD";

const char* endpoint =
"https://script.googleusercontent.com/macros/echo?user_content_key=YOURKEY";

void setup() {
  Serial.begin(115200);

  FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
}

void setColor(String status) {
  if (status == "meeting") {
    leds[0] = CRGB::Red;
  }
  else if (status == "busy") {
    leds[0] = CRGB::Yellow;
  }
  else {
    leds[0] = CRGB::Green;
  }

  FastLED.show();
}

void loop() {

  if (WiFi.status() == WL_CONNECTED) {

    WiFiClientSecure client;
client.setInsecure();

HTTPClient http;

http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);

http.begin(client, endpoint);

int httpCode = http.GET();

    if (httpCode > 0) {

   String payload = http.getString();

Serial.println("PAYLOAD:");
Serial.println(payload);

      DynamicJsonDocument doc(256);

      deserializeJson(doc, payload);

      String status = doc["status"];

      Serial.println(status);

      setColor(status);
    }

    http.end();
  }

  delay(60000); // check every minute
}