Selaa lähdekoodia

MQTT Is working also

Thomas Chef 3 vuotta sitten
vanhempi
commit
626b2d5118
5 muutettua tiedostoa jossa 17 lisäystä ja 3 poistoa
  1. 2 2
      main/config.h
  2. 3 0
      main/displayAndSend.c
  3. 1 1
      main/http_client.c
  4. 2 0
      main/main.c
  5. 9 0
      main/mqtt.h

+ 2 - 2
main/config.h

@@ -9,8 +9,8 @@
 // These defines configures which code to generate (to save download time during development)
 #define CCFG_GEN_PULSE      // For testing purposes only (LED-Pulse 14Hz)
 #define CCFG_PCNT           // pcnt-code that counts pulses
-//#define WIFI_ENABLED
-//#define MQTT_ENABLED
+#define WIFI_ENABLED
+#define MQTT_ENABLED
 #define SERIAL_ENABLED
 #define ENABLE_SSD1306
 

+ 3 - 0
main/displayAndSend.c

@@ -1,6 +1,7 @@
 #include "displayAndSend.h"
 #include "ssd1306.h"
 #include "ssd1306_driver.h"
+#include "mqtt.h"
 #include "esp_log.h"
 #include <stdio.h>
 #include <string.h>
@@ -81,6 +82,8 @@ void displayAndSendTask(void *pvParameters) {
                           SSD1306_SetPosition(127-(strlen(txt)*8),33);
                           SSD1306_Puts(txt, &Font_7x10,SSD1306_COLOR_WHITE);
                           SSD1306_UpdateScreen();
+                          sprintf(txt,"%.5f",data.dData);
+                          sendMQTTMessage("sensors/TEST/energy/electricalTotal", txt);
                           break;
                 default:
                           break;

+ 1 - 1
main/http_client.c

@@ -9,7 +9,7 @@
 #include "wifi.h"
 #include "config.h"
 
-#ifdef WIFI_ENABLED
+#ifdef HTTP_ENABLED
 
 #include "nvs_flash.h"
 #include "esp_netif.h"

+ 2 - 0
main/main.c

@@ -6,12 +6,14 @@
 #include "serial.h"
 #include "displayAndSend.h"
 #include "pcnt_functions.h"
+#include "mqtt.h"
 
 
 // Chip info:
 // This is esp32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB external flash
 
 
+
 void app_main(void)
 {
     ESP_LOGI("MAIN", "HomeEnergyMeter ESP32. Core:%d",xPortGetCoreID());

+ 9 - 0
main/mqtt.h

@@ -0,0 +1,9 @@
+#ifndef __MQTT_H__
+#define __MQTT_H__
+
+void mqtt_init(void);
+void sendMQTTMessage(const char * topic, const char * data);
+
+
+
+#endif