/**
* Example demonstrating multiple Firebase Realtime Database streams and set operations with ESP32, ESP8266, and Raspberry Pi Pico W.
*/
#include <Arduino.h>
#include <WiFi.h>
#include <HTTPClient.h>
HTTPClient http;
bool isInternetConnected() {
// Ensure WiFi is connected
if (WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi is not connected!");
return false;
}
http.begin("http://clients3.google.com/generate_204"); // A lightweight connectivity check
int httpCode = http.GET();
http.end();
if (httpCode == 204) { // HTTP 204 means success with no content
Serial.println("Internet connection is active.");
return true;
} else {
Serial.printf("Connectivity test failed, HTTP code: %d\n", httpCode);
return false;
}
}
void setup() {
Serial.begin(115200);
WiFi.begin("Wokwi-GUEST", "");
// Connect to WiFi.
}
/**
* Arduino loop function.
*/
void loop() {
// Poll the database to handle internal tasks (required for streaming).
delay(100);
Serial.println(isInternetConnected());
}