User Tools

Site Tools


tecnologia:iot:panel_baterias

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tecnologia:iot:panel_baterias [2022/04/28 18:57] – admintecnologia:iot:panel_baterias [2022/04/30 13:55] (current) – jose
Line 19: Line 19:
 Yo he instalado MD_Parola que te deja hacer efectos. Te dirá que tiene dependencias y le decimos que instale todas. Yo he instalado MD_Parola que te deja hacer efectos. Te dirá que tiene dependencias y le decimos que instale todas.
  
-Código de prueba:+====== Mensaje sencillo ====== 
 <code> <code>
 #include <MD_Parola.h> #include <MD_Parola.h>
Line 204: Line 205:
 </code> </code>
  
-Mensaje de **conectando a wifi** mientras conecta+===== Mensaje de **conectando a wifi** mientras conecta ===== 
 <code> <code>
 #include <MD_Parola.h> #include <MD_Parola.h>
Line 278: Line 280:
 } }
  
 +</code>
 +
 +===== Muestra la IP una vez conectado =====
 +
 +
 +<code>
 +#include <MD_Parola.h>
 +#include <MD_MAX72xx.h>
 +#include <WiFi.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     = "mi_red_wifi";
 +const char* password = "mi_contraseña_wifi";
 +
 +IPAddress ip(192,168,1,69);     
 +IPAddress gateway(192,168,1,1);   
 +IPAddress subnet(255,255,255,0); 
 +IPAddress dns(8,8,8,8);
 +
 +AsyncWebServer server(80);
 +
 +MD_Parola Display = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
 +String my_ip;
 +
 +void setup() {
 +  Display.begin();
 +  Display.setIntensity(0);
 +  Display.displayClear();
 +  Display.displayScroll("CONECTANDO WIFI", PA_CENTER, PA_SCROLL_LEFT, 25);
 +
 +  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) {
 +    if (Display.displayAnimate()) {
 +    Display.displayReset();
 +  } 
 +  }
 +
 +  Serial.println('\n');
 +  Serial.println("Connection established!");  
 +  Serial.print("IP address:\t");
 +  Serial.println(WiFi.localIP());
 +
 +  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
 +    request->send(200, "text/plain", "V1.0 Prueba Panel Led");
 +  });
 +  
 +  
 +  AsyncElegantOTA.begin(&server);
 +  server.begin();
 +  Serial.println("HTTP server started");
 +  delay(1000);
 +
 +  my_ip = WiFi.localIP().toString();
 +  Serial.println(my_ip);
 +
 +  Display.displayClear();
 +  Display.displayScroll(my_ip.c_str(), PA_CENTER, PA_SCROLL_LEFT, 25);
 +  
 +  while(true){
 +    if (Display.displayAnimate()) {
 +      Display.displayReset();
 +      break;
 +    }
 +  }
 +}
 +
 +
 +void loop() {
 +
 +    Display.setTextAlignment(PA_LEFT);
 +    Display.print("Hola");
 +    delay(10000);
 +
 +}
 +
 +
 +</code>
 +
 +Si cambiamos la parte del while por esto, lo muestra 2 veces
 +<code>
 +  for (int muestra_ip = 1; muestra_ip <= 2; muestra_ip++) {
 +    while (true) {  
 +      if (Display.displayAnimate()) {
 +        Display.displayReset();
 +      break;
 +      }  
 +    }
 +  }
 +</code>
 +
 +===== Muestra mensaje leido de internet =====
 +Lee el texto que le indicamos en la web que tengamos en:
 +  serverPath = "http://bateriaseko.lobo99.com/prueba_led";
 +
 +Al leer la cadena le pone un símbolo raro al final solo en la pantalla led, en el serial monitor no.
 +
 +Le quitamos el último carácter con:
 +  payload.substring(0,strlen(payload.c_str())-1)
 +
 +<code>
 +#include <MD_Parola.h>
 +#include <MD_MAX72xx.h>
 +#include <SPI.h>
 +#include <WiFi.h>        // Include the Wi-Fi library
 +#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     = "mi_red_wifi";
 +const char* password = "mi_contraseña_wifi";
 +
 +IPAddress ip(192,168,1,69);     
 +IPAddress gateway(192,168,1,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/prueba_led";
 +
 +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());
 +  
 +  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
 +    request->send(200, "text/plain", "V1.0 lee el valor de http://bateriaseko.lobo99.com/prueba_led");
 +  });
 +  
 +  
 +  AsyncElegantOTA.begin(&server);
 +  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(String(payload.toInt()));
 +        
 +        Serial.println(strlen(payload.c_str()));
 +
 +        Display.setTextAlignment(PA_CENTER);
 +        Display.print(payload.substring(0,strlen(payload.c_str())-1));
 +        delay(1000);  
 +      }
 +      else {
 +        Serial.print("Error code: ");
 +        Serial.println(httpResponseCode);
 +      }
 +      // Free resources
 +      http.end();
 +    }
 +    else {
 +      Serial.println("WiFi Disconnected");
 +    }
 +
 +}
 +</code>
 +
 +===== Muestra mensaje leido de internet con scroll =====
 +<code>
 +#include <MD_Parola.h>
 +#include <MD_MAX72xx.h>
 +#include <SPI.h>
 +#include <WiFi.h>        // Include the Wi-Fi library
 +#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     = "mi_red_wifi";
 +const char* password = "mi_contraseña_wifi";
 +
 +IPAddress ip(192,168,1,91);     
 +IPAddress gateway(192,168,1,1);   
 +IPAddress subnet(255,255,255,0); 
 +IPAddress dns(8,8,8,8);
 +
 +AsyncWebServer server(80);
 +
 +String mensaje="";
 +
 +String serverPath = "http://mensaje.lobo99.com/mensaje.txt";
 +
 +
 +MD_Parola Display = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
 +
 +void setup() {
 + 
 +  Display.begin();
 +  Display.setIntensity(0);
 +  Display.displayClear();
 +  String mensaje = "Conectando WIFI: " + String(ssid);
 +  Display.displayScroll(mensaje.c_str(), PA_CENTER, PA_SCROLL_LEFT, 25);
 +    
 +  Serial.begin(115200);         // Start the Serial communication to send messages to the computer
 +  delay(10);
 +  Serial.println('\n');
 +  
 +  WiFi.begin(ssid, password);             // Connect to the network
 +  WiFi.config(ip, gateway, subnet, dns);
 +  Serial.print("Connecting to ");
 +  Serial.print(ssid);
 +
 +  while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
 +    if (Display.displayAnimate()) {
 +      Display.displayReset();
 +    } 
 +  }
 +
 +  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 http://mensaje.lobo99.com/mensaje.txt");
 +  });
 +  
 +  
 +  AsyncElegantOTA.begin(&server);    // Start AsyncElegantOTA
 +  server.begin();
 +  Serial.println("HTTP server started");
 +  Display.print("V 1.0");
 +  delay(1000);
 +
 +        //Display.displayScroll(payload.c_str(), PA_CENTER, PA_SCROLL_LEFT, 25);
 +Display.setTextAlignment(PA_CENTER);
 +Display.displayScroll("hola", PA_CENTER, PA_SCROLL_LEFT, 25);
 +}
 +
 +void loop() {
 +  AsyncElegantOTA.loop();
 +      
 +  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);
 +        const char* mensaje=payload.c_str();
 +        Serial.println(mensaje);
 +        Display.displayClear();
 +        Display.displayScroll(mensaje, PA_CENTER, PA_SCROLL_LEFT, 25);
 +        
 +        while(!Display.displayAnimate())
 +        {
 +          Serial.println("while");     
 +        }
 +      }
 +      else {
 +        Serial.print("Error code: ");
 +        Serial.println(httpResponseCode);
 +      }
 +      // Free resources
 +      http.end();
 +  }
 +  else {
 +    Serial.println("WiFi Disconnected");
 +  }
 +}
 </code> </code>
tecnologia/iot/panel_baterias.1651172278.txt.gz · Last modified: by admin