diff --git a/ESP32/IBUSM/src/main.cpp b/ESP32/IBUSM/src/main.cpp index 07b996e..969a666 100644 --- a/ESP32/IBUSM/src/main.cpp +++ b/ESP32/IBUSM/src/main.cpp @@ -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(" "); } diff --git a/ESP8266/MatrixLedsRGB/platformio.ini b/ESP8266/MatrixLedsRGB/platformio.ini index d8b3fa1..2bec368 100644 --- a/ESP8266/MatrixLedsRGB/platformio.ini +++ b/ESP8266/MatrixLedsRGB/platformio.ini @@ -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 \ No newline at end of file diff --git a/ESP8266/MatrixLedsRGB/src/main.cpp b/ESP8266/MatrixLedsRGB/src/main.cpp index e99f12d..d3b5e35 100644 --- a/ESP8266/MatrixLedsRGB/src/main.cpp +++ b/ESP8266/MatrixLedsRGB/src/main.cpp @@ -3,22 +3,27 @@ #include #include #include - +#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(); @@ -38,27 +42,33 @@ void setup() void loop() { - ArduinoOTA.handle(); - yield(); - if ((millis() - matrix_time) > 150) + ArduinoOTA.handle(); + + 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()); } diff --git a/ESP8266/MatrixLedsRGB/src/matrix.hpp b/ESP8266/MatrixLedsRGB/src/matrix.hpp index 78987ce..281ac5b 100644 --- a/ESP8266/MatrixLedsRGB/src/matrix.hpp +++ b/ESP8266/MatrixLedsRGB/src/matrix.hpp @@ -3,8 +3,8 @@ #include #include #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; diff --git a/ESP8266/MatrixLedsRGB/src/mqtt.hpp b/ESP8266/MatrixLedsRGB/src/mqtt.hpp index 734a71c..4b6252e 100644 --- a/ESP8266/MatrixLedsRGB/src/mqtt.hpp +++ b/ESP8266/MatrixLedsRGB/src/mqtt.hpp @@ -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(); R = doc["R"]; G = doc["G"]; B = doc["B"]; + matrix_speed = doc["speed"].as(); + 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);