#include #include #include #include #include #include #include #include #include const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2). IRsend irsend(kIrLed); // Set the GPIO to be used to sending the message. // IR Receiver connected to PIN D5 (14) const uint16_t kRecvPin = 14; const uint32_t kBaudRate = 115200; const uint16_t kCaptureBufferSize = 1024; #if DECODE_AC // Some A/C units have gaps in their protocols of ~40ms. e.g. Kelvinator // A value this large may swallow repeats of some protocols const uint8_t kTimeout = 50; #else // DECODE_AC // Suits most messages, while not swallowing many repeats. const uint8_t kTimeout = 15; #endif // DECODE_AC const uint16_t kMinUnknownSize = 12; #define LEGACY_TIMING_INFO false IRrecv irrecv(kRecvPin, kCaptureBufferSize, kTimeout, true); decode_results results; // Somewhere to store the results // Update these with values suitable for your network. const char* ssid = "JoeNelsDarlings"; const char* password = "Paris2016"; const char* mqtt_server = "mqtt.ddns.kawomi.com"; const String room_name = "IRBedroom"; //const String room_name = "IRBedroom"; WiFiClient espClient; PubSubClient client(espClient); unsigned long lastMsg = 0; #define MSG_BUFFER_SIZE (50) char msg[MSG_BUFFER_SIZE]; int value = 0; void setup_wifi() { delay(10); // We start by connecting to a WiFi network Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } randomSeed(micros()); Serial.println("X"); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); } void callback(char* topic, byte* payload, unsigned int length) { Serial.print("Message arrived ["); Serial.print(topic); String recBuf=""; Serial.print("] "); for (int i = 0; i < length; i++) { recBuf += (char)payload[i]; } Serial.println(recBuf); int numEle=1; for (int i=0; i 2000) { lastMsg = now; ++value; snprintf (msg, MSG_BUFFER_SIZE, "hello world #%ld", value); Serial.print("Publish message: "); Serial.println(msg); client.publish("IRBedroomReceivedIR", msg); } */ // Check if the IR code has been received. if (irrecv.decode(&results)) { // Display a crude timestamp. uint32_t now = millis(); Serial.printf(D_STR_TIMESTAMP " : %06u.%03u\n", now / 1000, now % 1000); // Check if we got an IR message that was to big for our capture buffer. if (results.overflow) Serial.printf(D_WARN_BUFFERFULL "\n", kCaptureBufferSize); // Display the library version the message was captured with. Serial.println(D_STR_LIBRARY " : v" _IRREMOTEESP8266_VERSION_ "\n"); // Display the basic output of what we found. String theResult,theSrc; theResult=resultToHumanReadableBasic(&results); theSrc=resultToSourceCode(&results); Serial.println(theSrc.c_str()); bool isPub = client.publish(String(room_name + "/ReceivedIR").c_str(), theSrc.c_str()); if (isPub) Serial.println("PUBLISHED"); else Serial.println("PUBLISH FAILED"); } }