Refactor MqttVerticle and GPS implementations: add stop method, update GPS serial handling, and improve WiFi connection logic with LED feedback
This commit is contained in:
@@ -1,7 +1,18 @@
|
||||
package net.miarma.contaminus.server;
|
||||
|
||||
import io.vertx.core.AbstractVerticle;
|
||||
import io.vertx.core.Promise;
|
||||
|
||||
public class MqttVerticle extends AbstractVerticle {
|
||||
|
||||
@Override
|
||||
public void start(Promise<Void> startPromise) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(Promise<Void> startPromise) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
:root {
|
||||
--primary-color: #be0f2e;
|
||||
--secondary-color: #a8223a;
|
||||
--text-shadow: #be0f2e80;
|
||||
--box-shadow: #be0f2e33;
|
||||
--primary-color: #018E55;
|
||||
--secondary-color: #007946;
|
||||
--text-shadow: #00794680;
|
||||
--box-shadow: #00794633;
|
||||
|
||||
--gradient-primary: #1A1A1A;
|
||||
--gradient-secondary: #2A2A2A;
|
||||
|
||||
--card-background: #be0f2e1a;
|
||||
--card-background: #0079461a;
|
||||
--card-gradient-primary: #252525;
|
||||
--card-gradient-secondary: #353535;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
#include "TinyGPSPlus.h"
|
||||
|
||||
#define RX 26
|
||||
#define TX 14
|
||||
|
||||
struct GPSData_t
|
||||
{
|
||||
float lat;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <WiFi.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
#define SSID "iPhone de Álvaro"
|
||||
#define PASSWORD "alvarito123"
|
||||
#define SSID "DIGIFIBRA-D2ys"
|
||||
#define PASSWORD "4EEATsyTcZ"
|
||||
|
||||
int setupWifi();
|
||||
@@ -9,6 +9,8 @@
|
||||
#define GPS_ID 3
|
||||
#define MAX7219_ID 1
|
||||
|
||||
#define DEBUG
|
||||
|
||||
#include "JsonTools.hpp"
|
||||
#include "RestClient.hpp"
|
||||
#include "WifiConnection.hpp"
|
||||
|
||||
@@ -1,33 +1,83 @@
|
||||
#include <WifiConnection.hpp>
|
||||
|
||||
#define PIN_R 12
|
||||
#define PIN_G 13
|
||||
#define PIN_B 14
|
||||
|
||||
WiFiClient wifiClient;
|
||||
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
ledcWrite(0, r);
|
||||
ledcWrite(1, g);
|
||||
ledcWrite(2, b);
|
||||
}
|
||||
|
||||
void setupLED() {
|
||||
ledcAttachPin(PIN_R, 0);
|
||||
ledcAttachPin(PIN_G, 1);
|
||||
ledcAttachPin(PIN_B, 2);
|
||||
|
||||
ledcSetup(0, 5000, 8);
|
||||
ledcSetup(1, 5000, 8);
|
||||
ledcSetup(2, 5000, 8);
|
||||
}
|
||||
|
||||
// hue cycle
|
||||
void hueCycle(uint8_t pos) {
|
||||
uint8_t r = (uint8_t)(sin((pos + 0) * 0.024) * 127 + 128);
|
||||
uint8_t g = (uint8_t)(sin((pos + 85) * 0.024) * 127 + 128);
|
||||
uint8_t b = (uint8_t)(sin((pos + 170) * 0.024) * 127 + 128);
|
||||
setColor(r, g, b);
|
||||
}
|
||||
|
||||
int setupWifi()
|
||||
{
|
||||
Serial.println();
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(SSID);
|
||||
setupLED();
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(SSID, PASSWORD);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
#ifdef DEBUG
|
||||
Serial.print("Conectando a la red WiFi: ");
|
||||
Serial.print(SSID);
|
||||
#endif
|
||||
|
||||
int hue = 0;
|
||||
uint32_t start = millis();
|
||||
const uint32_t timeout = 15000;
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED && millis() - start < timeout)
|
||||
{
|
||||
delay(500);
|
||||
hueCycle(hue++);
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.print(".");
|
||||
#endif
|
||||
|
||||
delay(30);
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
Serial.println("Setup!");
|
||||
|
||||
if(WiFi.status() == WL_CONNECTED)
|
||||
if (WiFi.status() == WL_CONNECTED)
|
||||
{
|
||||
setColor(0, 255, 0);
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.println("Conectado a la red WiFi");
|
||||
Serial.print("Dirección IP: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
setColor(255, 0, 0);
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.println("No se pudo conectar a la red WiFi");
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
#include "GPS.hpp"
|
||||
|
||||
TinyGPSPlus gps;
|
||||
HardwareSerial gpsSerial(1);
|
||||
HardwareSerial SerialGPS(1);
|
||||
|
||||
void GPS_Init()
|
||||
{
|
||||
gpsSerial.begin(9600, SERIAL_8N1, RX, TX);
|
||||
SerialGPS.begin(9600, SERIAL_8N1, 25, 26); // RX, TX
|
||||
}
|
||||
|
||||
GPSData_t GPS_Read()
|
||||
{
|
||||
while (gpsSerial.available() > 0) {
|
||||
gps.encode(gpsSerial.read());
|
||||
while (SerialGPS.available() > 0)
|
||||
{
|
||||
gps.encode(SerialGPS.read());
|
||||
}
|
||||
|
||||
float lat = 0.0f, lon = 0.0f;
|
||||
|
||||
if (gps.location.isValid()) {
|
||||
if (gps.location.isUpdated())
|
||||
{
|
||||
lat = gps.location.lat();
|
||||
lon = gps.location.lng();
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
#include "main.hpp"
|
||||
|
||||
#define DEBUG
|
||||
|
||||
const uint32_t DEVICE_ID = getChipID();
|
||||
const char ALL_VEHICLES[] = "Todo tipo de vehiculos";
|
||||
const char ELECTRIC_VEHICLES[] = "Solo vehiculos electricos/hibridos";
|
||||
const char* currentMessage = nullptr;
|
||||
|
||||
TaskTimer matrixTimer{0, 25};
|
||||
TaskTimer globalTimer{0, 30000};
|
||||
TaskTimer globalTimer{0, 60000};
|
||||
|
||||
extern HTTPClient httpClient;
|
||||
extern MD_Parola display;
|
||||
@@ -23,6 +21,9 @@ void setup()
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Iniciando...");
|
||||
|
||||
setupWifi();
|
||||
|
||||
BME280_Init();
|
||||
Serial.println("Sensor BME280 inicializado");
|
||||
GPS_Init();
|
||||
@@ -51,9 +52,13 @@ void loop()
|
||||
readBME280();
|
||||
readGPS();
|
||||
readMQ7();
|
||||
|
||||
#ifdef DEBUG
|
||||
printAllData();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
globalTimer.lastRun = now;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user