#include <WiFi.h>;
#include <HTTPClient.h>;
#include <Adafruit_NeoPixel.h>
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
#define api "sal"
#define WIFI_CHANNEL 6
#define LED_PIN 13
#define LED_COUNT 16
Adafruit_NeoPixel ring(LED_COUNT, LED_PIN, NEO_RGBW + NEO_KHZ800);
// we need this library to serialize the data
//come from api in Json format
#include <ArduinoJson.h>;
void setup() {
Serial.begin(115200);
WiFi.disconnect();
WiFi.begin(WIFI_SSID, WIFI_PASSWORD, WIFI_CHANNEL);
Serial.print("Connecting to WiFi ");
Serial.print(WIFI_SSID);
while(WiFi.status() != WL_CONNECTED){
Serial.println("loading.");
Serial.println("loading..");
Serial.println("loading...");
delay(300);
}
Serial.println(".");
Serial.println("Wifi connected!");
Serial.println("IP Address: ");
// print board ip
IPAddress ipadress = WiFi.localIP();
Serial.println(ipadress);
//settinh the dns to use it in link instead of 192 ip
// access point: http://esp32.local
ring.begin();
ring.show();
ring.setBrightness(50);
// here we do fetch the api by begin method
}
void loop() {
while(WiFi.status() == WL_CONNECTED){
HTTPClient client;
client.begin("https://www.google.com/");
// here we define the method wich return status code
int HttpCode = client.GET();
if(HttpCode > 0){
Serial.println(HttpCode);
}
if(HttpCode == 200){
for(int i = 0; i < ring.numPixels(); i++){
ring.setPixelColor(i, random(255), random(255), random(255), 0);
ring.show();
delay(50);
}
for(int i = ring.numPixels()-1; i >= 0; i--){
ring.setPixelColor(i, 0, 0, 0, 0);
ring.show();
delay(50);
}
}
if(HttpCode != 200){Serial.println("error fetching data...!");
client.end();
}
}
delay(10000);
}