Sfoglia il codice sorgente

Can disable MQTT and WIFI

Thomas Chef 3 anni fa
parent
commit
6e5580283c
4 ha cambiato i file con 18 aggiunte e 7 eliminazioni
  1. 2 1
      main/config.h
  2. 3 5
      main/http_client.c
  3. 8 1
      main/main.c
  4. 5 0
      main/mqtt.c

+ 2 - 1
main/config.h

@@ -4,7 +4,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 WIFI_ENABLED
+//#define MQTT_ENABLED
 
 
 #define PCNT_INPUT_SIG_IO   4  // Pulse Input GPIO

+ 3 - 5
main/http_client.c

@@ -97,14 +97,10 @@ static void http_rest_with_url(void *pvParameters)
     esp_http_client_cleanup(client);
 }
 
-#endif
-
 static void http_send_data_task(void *pvParameters)
 {
 
-#ifdef WIFI_ENABLED
     http_rest_with_url(pvParameters);
-#endif
 
     vTaskDelete(NULL);
 }
@@ -119,4 +115,6 @@ void sendHTTPMessage(const double inData, const uint32_t bigCnt, const int32_t c
     void *const ptr = (void *const)&data;
 
     if( commIsUpAndRunning == 1 ) xTaskCreate(&http_send_data_task, "send_data_task", 8192, ptr, 5, NULL);
-}
+}
+
+#endif

+ 8 - 1
main/main.c

@@ -43,7 +43,9 @@ void app_main(void)
 #ifdef WIFI_ENABLED
     initWifi();             // Init WIFI
 #endif
+#ifdef MQTT_ENABLED
     mqtt_init();
+#endif
 
     char dataStr[100];
     double kWh = 0.0;
@@ -57,9 +59,14 @@ void app_main(void)
 
         sprintf(dataStr,"%.5f",kWh);
 
-        sendMQTTMessage("/sensors/energy/electricalTotal", dataStr);
+        // @TODO This is changed for testing
+#ifdef MQTT_ENABLED
+        sendMQTTMessage("/sensors/TEST/energy/electricalTotal", dataStr);
+#endif
 
+#ifdef WIFI_ENABLED
         sendHTTPMessage(kWh, bigCnt, cnt);
+#endif
 
         ESP_LOGI("MAIN", "%.4f   %u    %d",kWh,bigCnt,cnt);
 

+ 5 - 0
main/mqtt.c

@@ -32,6 +32,8 @@
 
 #include "wifi.h"
 
+#ifdef MQTT_ENABLED
+
 static const char *TAG = "MQTT";
 static esp_mqtt_client_handle_t client;
 static bool connected = false;
@@ -77,8 +79,10 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
 
 void    mqttTask(void *pvParameters) {
 
+#ifdef WIFI_ENABLED
     // Wait for tcpip-comm
     while( commIsUpAndRunning == false ) vTaskDelay(10000 / portTICK_PERIOD_MS);
+#endif
 
     esp_mqtt_client_config_t mqtt_cfg = {
         .uri = "mqtt://192.168.1.110:1883",
@@ -112,3 +116,4 @@ void sendMQTTMessage(const char * topic, const char * data) {
     }
 }
 
+#endif