tecnologia:proyectos:atril
This is an old revision of the document!
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>
// Uncomment according to your hardware type
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
//#define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW
// Defining size, and output pins
#define MAX_DEVICES 4
#define CS_PIN 5
const char* ssid = "ESLAEKO_P.BAJA";
const char* password = NULL;
IPAddress ip(192,168,100,12);
IPAddress gateway(192,168,100,1);
IPAddress subnet(255,255,255,0);
IPAddress dns(8,8,8,8);
AsyncWebServer server(80);
const int lectura=5;
String power="";
String serverPath = "http://bateriaseko.lobo99.com/frases";
MD_Parola Display = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
void setup() {
Display.begin();
Display.setIntensity(0);
Display.displayClear();
Serial.begin(115200);
delay(10);
Serial.println('\n');
WiFi.begin(ssid, password);
WiFi.config(ip, gateway, subnet, dns);
Serial.print("Connecting to ");
Serial.print(ssid);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print('.');
}
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain", "V1.0 27/04/2022 https://pad.eslaeko.net/p/iot_panelbaterias");
});
AsyncElegantOTA.begin(&server); // Start AsyncElegantOTA
server.begin();
Serial.println("HTTP server started");
Display.print("V 1.0");
delay(1000);
}
void loop() {
AsyncElegantOTA.loop();
Display.setTextAlignment(PA_LEFT);
if(WiFi.status()== WL_CONNECTED){
HTTPClient http;
// Your Domain name with URL path or IP address with path
http.begin(serverPath.c_str());
// Send HTTP GET request
int httpResponseCode = http.GET();
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
Display.setTextAlignment(PA_CENTER);
Display.print((String(payload.toInt()))+"%");
Display.setTextAlignment(PA_LEFT);
delay(1000);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
power = "";
delay(10000);
}
tecnologia/proyectos/atril.1672250219.txt.gz · Last modified: by admin
