ESTACIÓN_DE_NOTICIAS_IoT — Arduino Uno simulation

An interactive Arduino Uno circuit simulation you can run free in your browser on Velxio, by amirandalo.

Components

Sketch code

// ╔══════════════════════════════════════════════════╗
// ║   PROYECTO  INTEGRADOR:  Estación  de  Noticias  IoT   ║
// ║   ESP32  +  WiFi  +  APIs  +  SSE  +  MQTT  +  Dashboard    ║
// ║   Taller  IoT  —  EPIS  UNSA 2026-A  |  Velxio.dev     ║
// ╚══════════════════════════════════════════════════╝
#include <WiFi.h>
#include <HTTPClient.h>
#include <WebServer.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>

// --- CONFIGURACIÓN DE RED ---
// Si usas Velxio.dev, deja "Wokwi-GUEST". Si usas hardware real, pon tus datos:
const char* SSID    = "Wokwi-GUEST"; 
const char* PASS    = "";
const char* BROKER  = "broker.hivemq.com";

#define T_NEWS   "epis/unsa/noticiero/resumen"
#define T_CLIMA  "epis/unsa/noticiero/clima"
#define T_CRYPTO  "epis/unsa/noticiero/crypto"

WebServer     server(80);
WiFiClient    wifiCli;
PubSubClient  mqtt(wifiCli);

// ── Datos globales (actualizados por fetchAll) ────────
struct { float temp; float viento; int wcode; } clima;
struct { String hora; String dia; int semana; } tiempo;
struct { float btc; float eth; float sol; } crypto;
String ultimaActualizacion = "--:--:--";

// ── Fetch clima Arequipa (open-meteo.com) ────────────
bool fetchClima() {
  HTTPClient http;
  http.begin("https://api.open-meteo.com/v1/forecast?latitude=-16.409&longitude=-71.538&current_weather=true");
  if (http.GET() != 200) { http.end(); return false; }
  DynamicJsonDocument doc(512);
  deserializeJson(doc, http.getString());
  http.end();
  clima.temp   = doc["current_weather"]["temperature"];
  clima.viento = doc["current_weather"]["windspeed"];
  clima.wcode  = doc["current_weather"]["weathercode"];
  return true;
}

// ── Fetch hora Lima (worldtimeapi.org) ───────────────
bool fetchHora() {
  HTTPClient http;
  http.begin("http://worldtimeapi.org/api/timezone/America/Lima");
  if (http.GET() != 200) { http.end(); return false; }
  StaticJsonDocument<512> doc;
  deserializeJson(doc, http.getString());
  http.end();
  String dt  = String((const char*)doc["datetime"]);
  tiempo.hora  = dt.substring(11,19);
  tiempo.dia   = dt.substring(0,10);
  tiempo.semana  = doc["week_number"];
  return true;
}

// ── Fetch crypto (CoinGecko) ──────────────────────────
bool fetchCrypto() {
  HTTPClient http;
  http.begin("https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,solana&vs_currencies=usd");
  if (http.GET() != 200) { http.end(); return false; }
  StaticJsonDocument<256> doc;
  deserializeJson(doc, http.getString());
  http.end();
  crypto.btc  = doc["bitcoin"]["usd"];
  crypto.eth  = doc["ethereum"]["usd"];
  crypto.sol  = doc["solana"]["usd"];
  return true;
}

// ── Obtener icono del clima según WMO code ───────────
String climaIcono(int code) {
  if (code==0) return " ☀ Despejado";
  if (code<=3) return " 🌤 Parcialmente nublado";
  if (code<=48) return " ☁ Nublado";
  if (code<=67) return " 🌧 Lluvia";
  if (code<=77) return " 🌨 Nieve";
  if (code<=82) return " ⛈ Tormenta";
  return " 🌪 Temporal";
}

// ── Publicar resumen

More projects by amirandalo