Merge branch 'dessarrollo'

This commit is contained in:
2021-09-19 18:43:51 -05:00
5 changed files with 48 additions and 32 deletions

View File

@@ -17,6 +17,9 @@ void loop()
uint16_t val;
IBus.loop();
for (int i=0; i<10; i++) {
Serial.print("CH: ");
Serial.print(i);
Serial.print(": ");
Serial.print(IBus.readChannel(i));
Serial.print(" ");
}

View File

@@ -19,8 +19,9 @@ lib_deps =
arduino-libraries/NTPClient@^3.1.0
monitor_speed = 115200
upload_speed = 256000
monitor_flags = --raw
upload_protocol = espota
upload_port = 192.168.1.108
upload_port = 192.168.1.106
upload_flags =
--port=8266
--auth=un260874

View File

@@ -3,22 +3,27 @@
#include <ArduinoJson.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#define DEBUG 0
#if DEBUG==1
#define debug(x) Serial.println(x)
#else
#define debug(x)
#endif
WiFiUDP ntpUDP;
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 "mqtt.hpp"
#include "ota.hpp"
const char *ssid = "mdchaparror";
const char *password = "un260874";
long timeAnterior;
long matrix_time;
void setup()
{
Serial.begin(115200);
Serial.begin(921600);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED)
@@ -26,9 +31,8 @@ void setup()
delay(5000);
ESP.restart();
}
//Serial.println(WiFi.localIP());
mensaje += WiFi.localIP().toString();
debug(WiFi.localIP());
ota_init();
mqtt_init();
@@ -39,26 +43,32 @@ void setup()
void loop()
{
ArduinoOTA.handle();
yield();
if ((millis() - matrix_time) > 150)
if ((millis() - matrix_time) > (long unsigned int)matrix_speed)
{
matrix_time = millis();
show_matrix();
}
if ((millis() - timeAnterior) > 1000)
if ((millis() - timeAnterior) > 2500)
{
timeAnterior = millis();
if (!client.connected())
{ yield();
reconnect();
}
yield();
timeClient.update(); //sincronizamos con el server NTP
yield();
hora = timeClient.getFormattedTime();
texto = mensaje + " " + hora;
longitud = texto.length() * 5 + 64;
}
if (!client.connected())
{
reconnect();
}
client.loop();
yield();
debug("\n\n Free RAM -> ");
debug(ESP.getFreeHeap());
}

View File

@@ -3,8 +3,8 @@
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#define PIN D7 //DIN MATRIZ
String texto = "Puerto Ota: ";
String mensaje = "Puerto Ota: ";
String texto = "UNELECTRONICA";
String mensaje = "UNELECTRONICA";
String hora = "00:00:00";
int R = 255;
int G = 0;

View File

@@ -26,17 +26,16 @@ void callback(char *p_topic, byte *p_payload, unsigned int p_length)
{
yield();
DeserializationError err = deserializeJson(doc, String(payload));
deserializeJson(doc, String(payload));
yield();
// if (err)
// {
// Serial.print(F("deserializeJson() failed with code "));
// Serial.println(err.c_str());
// }
mensaje = doc["msg"].as<String>();
R = doc["R"];
G = doc["G"];
B = doc["B"];
matrix_speed = doc["speed"].as<int>();
if(matrix_speed<50)
matrix_speed=50;
texto = mensaje + " " + hora;
x = matrix.width();
longitud = texto.length() * 5 + 64;
@@ -50,21 +49,24 @@ void reconnect()
String clientId = "matrix_client-" + String(random(0xffff), HEX);
if (client.connect(clientId.c_str(), MQTT_USER, MQTT_PASSWORD))
{
//Serial.println("INFO: connected");
client.subscribe(MQTT_TOPIC_FULL);
}
else
{
//Serial.print("ERROR: failed, rc=");
//Serial.print(client.state());
//Serial.println("DEBUG: try again in 5 seconds");
mensaje = "ERROR AL CONECTAR SERVIDOR MQTT";
texto = mensaje + " " + hora;
x = matrix.width();
longitud = texto.length() * 5 + 64;
debug("Error conexion MQTT");
yield();
delay(5000);
yield();
delay(1000);
}
}
}
void mqtt_init()
{
client.setServer(MQTT_SERVER_IP, MQTT_SERVER_PORT);