diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-11-04 20:28:52 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-11-04 20:28:52 -0300 |
| commit | 48ffb49e0913dc7a94c3bdfb0c0cf69e4b8f0235 (patch) | |
| tree | 2475eff80375727bb10ccc62ca8b0f391927bd18 /esp | |
| parent | e3b41c5c24488a48b552fb7aeffe250574b9c8a8 (diff) | |
enviando mensagens
Diffstat (limited to 'esp')
| -rw-r--r-- | esp/NEW/NEW.ino (renamed from esp/estacao_principal/NEW.ino) | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/esp/estacao_principal/NEW.ino b/esp/NEW/NEW.ino index 86aafcc..c695e84 100644 --- a/esp/estacao_principal/NEW.ino +++ b/esp/NEW/NEW.ino @@ -9,13 +9,13 @@ #include <time.h> // Para o timestamp NTP
//wifi
-const char* ssid = "NOME_DA_SUA_REDE_WIFI";
-const char* password = "SENHA_DA_SUA_REDE_WIFI";
+const char* ssid = "demiurgoodeusarquitetodamentira";
+const char* password = "12345678";
//MQTT
-const char* mqtt_server = "IP_OU_DOMINIO_DO_SEU_BROKER_MQTT"; // Ex: "192.168.1.100" ou "broker.hivemq.com"
+const char* mqtt_server = "10.233.10.131"; // Ex: "192.168.1.100" ou "broker.hivemq.com"
const int mqtt_port = 1883;
-const char* station_id = "estacao_principal_01"; // <stationid> do seu tópico
+const char* station_id = "1"; // <stationid> do seu tópico
//NTP (Timestamp)
const char* ntpServer = "pool.ntp.org";
@@ -30,11 +30,11 @@ PubSubClient client(espClient); // LM393
#define LM393_INTERVAL 1000
#define LM393_PIN 35
-volatile unsigned long contagem_lm393 = 0; [cite_start]// [cite: 1]
-volatile bool prevLm393State = LOW; [cite_start]// [cite: 2]
+volatile unsigned long contagem_lm393 = 0; // [cite: 1]
+volatile bool prevLm393State = LOW; // [cite: 2]
void isr_lm393() {
bool state = digitalRead(LM393_PIN);
- [cite_start]if (prevLm393State != state) { // [cite: 3]
+ if (prevLm393State != state) { // [cite: 3]
contagem_lm393++;
}
prevLm393State = state;
@@ -50,7 +50,7 @@ unsigned long lastTime_bh1750 = 0; #define DHT_PIN 32
#define DHTTYPE DHT11
DHT dht(DHT_PIN, DHTTYPE);
-[cite_start]#define DHT11_HUM_INTERVAL 4000 // [cite: 5]
+#define DHT11_HUM_INTERVAL 4000 // [cite: 5]
unsigned long lastTime_dht11_hum = 0;
// BMP280
@@ -58,7 +58,7 @@ Adafruit_BMP280 bmp; #define BMP280_PRESSURE_INTERVAL 5000
#define BMP280_TEMPERATURE_INTERVAL 3000
unsigned long lastTime_bmp280_press = 0;
-unsigned long lastTime_bmp280_temp = 0; [cite_start]// [cite: 6]
+unsigned long lastTime_bmp280_temp = 0; // [cite: 6]
// Função para obter o timestamp Unix (segundos desde 1970)
unsigned long getTimestamp() {
@@ -73,7 +73,7 @@ unsigned long getTimestamp() { }
// Função para publicar a mensagem no formato solicitado
-void publishMqttMessage(String sensor_id, String unit_id, float reading_value) {
+void publishMqttMessage(int sensor_id, int unit_id, float reading_value) {
if (!client.connected()) {
Serial.println("Cliente MQTT desconectado. Ignorando publicação.");
return;
@@ -86,7 +86,7 @@ void publishMqttMessage(String sensor_id, String unit_id, float reading_value) { }
// Monta o tópico: /weather/<stationid>
- String topic = "/weather/" + String(station_id);
+ String topic = "weather/" + String(station_id);
// Monta o Payload JSON
StaticJsonDocument<256> doc;
@@ -194,7 +194,7 @@ void setup() { attachInterrupt(digitalPinToInterrupt(LM393_PIN), isr_lm393, CHANGE);
// BH1750
- lightMeter.begin(); [cite_start]// [cite: 7]
+ lightMeter.begin(); // [cite: 7]
// DHT11
dht.begin();
@@ -202,7 +202,7 @@ void setup() { // BMP280
bmp.begin(0x76);
- Serial.println("Estacao iniciada"); [cite_start]// [cite: 8]
+ Serial.println("Estacao iniciada"); // [cite: 8]
}
//LOOP
@@ -218,7 +218,7 @@ void loop() { // LM393
if (now - lastTime_lm393 >= LM393_INTERVAL) {
int pulsos;
- const float FATOR_KHM = 2.4; [cite_start]// [cite: 9]
+ const float FATOR_KHM = 2.4; // [cite: 9]
noInterrupts();
pulsos = contagem_lm393;
@@ -226,72 +226,72 @@ void loop() { interrupts();
int giros = pulsos / 10;
- float rps = ((float)pulsos/10.0f) / (LM393_INTERVAL / 1000.0f); [cite_start]// [cite: 10]
+ float rps = ((float)pulsos/10.0f) / (LM393_INTERVAL / 1000.0f); // [cite: 10]
float velocidade = rps * FATOR_KHM;
Serial.print("Velocidade do vento: "); // (Corrigi de "tempo")
Serial.print(velocidade);
- Serial.println(" km/h"); [cite_start]// [cite: 11]
+ Serial.println(" km/h"); // [cite: 11]
//PUBLICA MQTT
// (sensor_id, unit_id, valor)
- publishMqttMessage("LM393_Vento", "km/h", velocidade);
+ publishMqttMessage(2, 2, velocidade);
lastTime_lm393 = now;
}
// BH1750
if (now - lastTime_bh1750 >= BH1750_INTERVAL) {
- float luz = lightMeter.readLightLevel(); [cite_start]// [cite: 12]
+ float luz = lightMeter.readLightLevel(); // [cite: 12]
Serial.print("Luz: ");
Serial.print(luz);
Serial.println(" lux");
//PUBLICA MQTT
- publishMqttMessage("BH1750", "lux", luz);
+ publishMqttMessage(3, 1, luz);
lastTime_bh1750 = now;
}
// DHT11 - Umidade
if (now - lastTime_dht11_hum >= DHT11_HUM_INTERVAL) {
- float umidade = dht.readHumidity(); [cite_start]// [cite: 13]
+ float umidade = dht.readHumidity(); // [cite: 13]
Serial.print("Umidade: ");
Serial.print(umidade);
Serial.println(" %");
// --- PUBLICA MQTT ---
- publishMqttMessage("DHT11", "percent", umidade);
+ publishMqttMessage(1, 4, umidade);
lastTime_dht11_hum = now;
}
// BMP280 - AIR PRESSURE
if (now - lastTime_bmp280_press >= BMP280_PRESSURE_INTERVAL) {
- float pressao = bmp.readPressure() / 100.0f; [cite_start]// [cite: 14]
+ float pressao = bmp.readPressure() / 100.0f; // [cite: 14]
Serial.print("Pressao: ");
Serial.print(pressao);
Serial.println(" hPa");
//PUBLICA MQTT
- publishMqttMessage("BMP280_Pressao", "hPa", pressao);
+ publishMqttMessage(4, 3, pressao);
lastTime_bmp280_press = now;
}
// BMP280 - TEMPERATURE
if (now - lastTime_bmp280_temp >= BMP280_TEMPERATURE_INTERVAL) {
- float temperatura = bmp.readTemperature(); [cite_start]// [cite: 15]
+ float temperatura = bmp.readTemperature(); // [cite: 15]
Serial.print("Temperatura: ");
Serial.print(temperatura);
Serial.println(" C");
//PUBLICA MQTT
- publishMqttMessage("BMP280_Temp", "celsius", temperatura);
+ publishMqttMessage(4, 5, temperatura);
lastTime_bmp280_temp = now;
}
|
