speed matrix
This commit is contained in:
@@ -19,8 +19,9 @@ lib_deps =
|
|||||||
arduino-libraries/NTPClient@^3.1.0
|
arduino-libraries/NTPClient@^3.1.0
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
upload_speed = 256000
|
upload_speed = 256000
|
||||||
|
monitor_flags = --raw
|
||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
upload_port = 192.168.1.108
|
upload_port = 192.168.1.106
|
||||||
upload_flags =
|
upload_flags =
|
||||||
--port=8266
|
--port=8266
|
||||||
--auth=un260874
|
--auth=un260874
|
||||||
@@ -3,22 +3,27 @@
|
|||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <NTPClient.h>
|
#include <NTPClient.h>
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
|
#define DEBUG 0
|
||||||
|
#if DEBUG==1
|
||||||
|
#define debug(x) Serial.println(x)
|
||||||
|
#else
|
||||||
|
#define debug(x)
|
||||||
|
#endif
|
||||||
WiFiUDP ntpUDP;
|
WiFiUDP ntpUDP;
|
||||||
NTPClient timeClient(ntpUDP, "0.south-america.pool.ntp.org", -18000, 6000);
|
NTPClient timeClient(ntpUDP, "0.south-america.pool.ntp.org", -18000, 6000);
|
||||||
|
const char *ssid = "mdchaparror";
|
||||||
|
const char *password = "un260874";
|
||||||
|
long timeAnterior;
|
||||||
|
long matrix_time;
|
||||||
|
int matrix_speed = 150;
|
||||||
|
|
||||||
#include "matrix.hpp"
|
#include "matrix.hpp"
|
||||||
#include "mqtt.hpp"
|
#include "mqtt.hpp"
|
||||||
#include "ota.hpp"
|
#include "ota.hpp"
|
||||||
|
|
||||||
const char *ssid = "mdchaparror";
|
|
||||||
const char *password = "un260874";
|
|
||||||
long timeAnterior;
|
|
||||||
long matrix_time;
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(921600);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
while (WiFi.waitForConnectResult() != WL_CONNECTED)
|
while (WiFi.waitForConnectResult() != WL_CONNECTED)
|
||||||
@@ -26,9 +31,8 @@ void setup()
|
|||||||
delay(5000);
|
delay(5000);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
//Serial.println(WiFi.localIP());
|
|
||||||
mensaje += WiFi.localIP().toString();
|
|
||||||
|
|
||||||
|
debug(WiFi.localIP());
|
||||||
ota_init();
|
ota_init();
|
||||||
mqtt_init();
|
mqtt_init();
|
||||||
|
|
||||||
@@ -39,26 +43,32 @@ void setup()
|
|||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
yield();
|
|
||||||
if ((millis() - matrix_time) > 150)
|
if ((millis() - matrix_time) > (long unsigned int)matrix_speed)
|
||||||
{
|
{
|
||||||
matrix_time = millis();
|
matrix_time = millis();
|
||||||
show_matrix();
|
show_matrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((millis() - timeAnterior) > 1000)
|
if ((millis() - timeAnterior) > 2500)
|
||||||
{
|
{
|
||||||
timeAnterior = millis();
|
timeAnterior = millis();
|
||||||
if (!client.connected())
|
yield();
|
||||||
{ yield();
|
|
||||||
reconnect();
|
|
||||||
}
|
|
||||||
timeClient.update(); //sincronizamos con el server NTP
|
timeClient.update(); //sincronizamos con el server NTP
|
||||||
|
yield();
|
||||||
hora = timeClient.getFormattedTime();
|
hora = timeClient.getFormattedTime();
|
||||||
texto = mensaje + " " + hora;
|
texto = mensaje + " " + hora;
|
||||||
longitud = texto.length() * 5 + 64;
|
longitud = texto.length() * 5 + 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!client.connected())
|
||||||
|
{
|
||||||
|
reconnect();
|
||||||
|
}
|
||||||
client.loop();
|
client.loop();
|
||||||
|
yield();
|
||||||
|
debug("\n\n Free RAM -> ");
|
||||||
|
debug(ESP.getFreeHeap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
#include <Adafruit_NeoMatrix.h>
|
#include <Adafruit_NeoMatrix.h>
|
||||||
#include <Adafruit_NeoPixel.h>
|
#include <Adafruit_NeoPixel.h>
|
||||||
#define PIN D7 //DIN MATRIZ
|
#define PIN D7 //DIN MATRIZ
|
||||||
String texto = "Puerto Ota: ";
|
String texto = "UNELECTRONICA";
|
||||||
String mensaje = "Puerto Ota: ";
|
String mensaje = "UNELECTRONICA";
|
||||||
String hora = "00:00:00";
|
String hora = "00:00:00";
|
||||||
int R = 255;
|
int R = 255;
|
||||||
int G = 0;
|
int G = 0;
|
||||||
|
|||||||
@@ -26,17 +26,16 @@ void callback(char *p_topic, byte *p_payload, unsigned int p_length)
|
|||||||
{
|
{
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
DeserializationError err = deserializeJson(doc, String(payload));
|
deserializeJson(doc, String(payload));
|
||||||
yield();
|
yield();
|
||||||
// if (err)
|
|
||||||
// {
|
|
||||||
// Serial.print(F("deserializeJson() failed with code "));
|
|
||||||
// Serial.println(err.c_str());
|
|
||||||
// }
|
|
||||||
mensaje = doc["msg"].as<String>();
|
mensaje = doc["msg"].as<String>();
|
||||||
R = doc["R"];
|
R = doc["R"];
|
||||||
G = doc["G"];
|
G = doc["G"];
|
||||||
B = doc["B"];
|
B = doc["B"];
|
||||||
|
matrix_speed = doc["speed"].as<int>();
|
||||||
|
if(matrix_speed<50)
|
||||||
|
matrix_speed=50;
|
||||||
|
|
||||||
texto = mensaje + " " + hora;
|
texto = mensaje + " " + hora;
|
||||||
x = matrix.width();
|
x = matrix.width();
|
||||||
longitud = texto.length() * 5 + 64;
|
longitud = texto.length() * 5 + 64;
|
||||||
@@ -50,21 +49,24 @@ void reconnect()
|
|||||||
String clientId = "matrix_client-" + String(random(0xffff), HEX);
|
String clientId = "matrix_client-" + String(random(0xffff), HEX);
|
||||||
if (client.connect(clientId.c_str(), MQTT_USER, MQTT_PASSWORD))
|
if (client.connect(clientId.c_str(), MQTT_USER, MQTT_PASSWORD))
|
||||||
{
|
{
|
||||||
//Serial.println("INFO: connected");
|
|
||||||
client.subscribe(MQTT_TOPIC_FULL);
|
client.subscribe(MQTT_TOPIC_FULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Serial.print("ERROR: failed, rc=");
|
mensaje = "ERROR AL CONECTAR SERVIDOR MQTT";
|
||||||
//Serial.print(client.state());
|
texto = mensaje + " " + hora;
|
||||||
//Serial.println("DEBUG: try again in 5 seconds");
|
x = matrix.width();
|
||||||
|
longitud = texto.length() * 5 + 64;
|
||||||
|
debug("Error conexion MQTT");
|
||||||
|
|
||||||
|
yield();
|
||||||
|
delay(5000);
|
||||||
yield();
|
yield();
|
||||||
delay(1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mqtt_init()
|
void mqtt_init()
|
||||||
{
|
{
|
||||||
client.setServer(MQTT_SERVER_IP, MQTT_SERVER_PORT);
|
client.setServer(MQTT_SERVER_IP, MQTT_SERVER_PORT);
|
||||||
|
|||||||
Reference in New Issue
Block a user