main.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "freertos/FreeRTOS.h"
  2. #include "freertos/task.h"
  3. #include "esp_log.h"
  4. #include "config.h"
  5. #include "wifi.h"
  6. #include "mqtt.h"
  7. #include "readTemps.h"
  8. #include "rxTimer.h"
  9. #include "receiver.h"
  10. #include "ir_transmit.h"
  11. #include "toshiba_ir.h"
  12. // Chip info:
  13. // This is esp32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB external flash
  14. /*
  15. I (43709) TOSHIBA: MQTT: F20D03FC0170A300D2
  16. I (43709) TOSHIBA: Data: F2 0D 03 FC 01 70 A3 00 D2
  17. I (43709) TOSHIBA: Mode:1 Temp:24 Fan:4
  18. I (43839) TOSHIBA: MQTT: F20D03FC0170A300D2
  19. I (43839) TOSHIBA: Data: F2 0D 03 FC 01 70 A3 00 D2
  20. I (43839) TOSHIBA: Mode:1 Temp:24 Fan:4
  21. */
  22. void app_main(void)
  23. {
  24. ESP_LOGI("MAIN", "IRTransceiver ESP32. Core:%d",xPortGetCoreID());
  25. // Wait for stable environment
  26. vTaskDelay(1000.0 / portTICK_PERIOD_MS);
  27. #ifdef RX_TIMER
  28. rxTimerInit(); // First we start the Timer (which samples Rx and handles uS-delays)
  29. #endif
  30. #ifdef ENABLE_DS18B20
  31. initTempReadings();
  32. #endif
  33. #ifdef WIFI_ENABLED
  34. initWifi(); // Init WIFI
  35. #endif
  36. #ifdef MQTT_ENABLED
  37. mqtt_init();
  38. #endif
  39. #ifdef IR_RECEIVER
  40. initReceiver(); // Init receiver-task
  41. #endif
  42. vTaskDelay(1000 / portTICK_PERIOD_MS);
  43. initIrTransmit();
  44. TickType_t vLastWakeTime = xTaskGetTickCount();
  45. // Do an initial delay to make the different tasks to work out of sync to each other (not send all data at same time)
  46. vTaskDelayUntil( &vLastWakeTime, 5000 / portTICK_PERIOD_MS );
  47. ESP_LOGI("MAIN","Lets go...");
  48. // ---------------- MAIN WHILE -------------------
  49. while(1) {
  50. vTaskDelayUntil( &vLastWakeTime, 10000 / portTICK_PERIOD_MS );
  51. // Start temp measuring task
  52. xTaskCreatePinnedToCore(readAndSendTemps, "readAndSendTemps", 1024*10, NULL, 2, NULL,1);
  53. /*ESP_LOGI("MAIN","Send a test-IR Tx Data");
  54. const uint8_t data[kToshibaNumberOfBytes] = { 0xF2, 0x0D, 0x03, 0xFC, 0x01, 0x30, 0xA3, 0x00, 0x92 };
  55. // F2 0D 03 FC 01 30 A3 00 92
  56. xQueueSend( toshibaTxQueue, &(data[0]), 0 );*/
  57. }
  58. vTaskDelete(NULL);
  59. }