diff --git a/src/espmega_iot_core.cpp b/src/espmega_iot_core.cpp index e895f15..f61b243 100644 --- a/src/espmega_iot_core.cpp +++ b/src/espmega_iot_core.cpp @@ -91,6 +91,11 @@ char AC_ROOM_TEMPERATURE_TOPIC[75]; char AC_HUMIDITY_TOPIC[75]; #endif +#ifdef ENABLE_IR_MODULE +uint16_t ir_buffer[IR_RAW_BUFFER_LENGTH]; +uint16_t ir_buffer_length = 0; +#endif + #ifdef ENABLE_ANALOG_MODULE #define DAC_COUNT 4 #define ADC_COUNT 8 @@ -677,6 +682,18 @@ void mqtt_callback(char *topic, byte *payload, unsigned int length) { dac_set_value_callback(topic_trim, topic_length, payload_nt, length); } +#endif +#ifdef ENABLE_IR_MODULE + else if (!strcmp(topic_trim, "/ir/send")) + { + const char* delimiter = ","; + char* token = strtok(const_cast(payload_nt), delimiter); + while (token != nullptr && ir_buffer_length < IR_RAW_BUFFER_LENGTH) { + ir_buffer[ir_buffer_length++] = atoi(token); + token = strtok(nullptr, delimiter); + } + IrSender.sendRaw(ir_buffer,ir_buffer_length ,NEC_KHZ); + } #endif else if (!strcmp(topic, STATE_REQUEST_TOPIC)) { diff --git a/src/user_code.hpp b/src/user_code.hpp index 9de5311..31f026c 100644 --- a/src/user_code.hpp +++ b/src/user_code.hpp @@ -23,7 +23,7 @@ #define IR_RECIEVE_PIN 35 #define IR_SEND_PIN 17 #define MARK_EXCESS_MICROS 20 -#define RAW_BUFFER_LENGTH 750 +#define IR_RAW_BUFFER_LENGTH 750 #define AC_MAX_TEMPERATURE 30 #define AC_MIN_TEMPERATURE 15 #define DHT22_PIN 32