#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const char* wowkiServer = "http://api.wowki.io/v1/device";
const char* deviceId = "YOUR_DEVICE_ID";
const char* apiKey = "YOUR_API_KEY";
const int ledPin = 9; // PWM pin connected to the LED
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
analogWrite(ledPin, 0); // Ensure the LED is off at startup
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println(" connected");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String url = String(wowkiServer) + "/" + deviceId + "/state?apiKey=" + apiKey;
http.begin(url);
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
Serial.println(payload);
int intensity = payload.toInt();
if (intensity >= 0 && intensity <= 255) {
analogWrite(ledPin, intensity);
}
} else {
Serial.println("Error on HTTP request");
}
http.end();
} else {
Serial.println("WiFi not connected");
}
delay(5000); // Wait for 5 seconds before the next request
}