/****************************************************************/ // https://myhomethings.eu // NodeMCU 1.0(ESP-12E Module) // Flash size: 4M (1M SPIFFS) /****************************************************************/ #include #include #include #include const char* ssid = "WIFI-ssid"; //SSID meines WLAN Netzes eintragen const char* password = "WIFI-password"; // mein WLAN Passwort eintragen const char* mqtt_server = "192.168.xx.xx"; // ioBroker ip address int IrLed = D2; WiFiClient espClient; PubSubClient client(espClient); IRsend irsend(IrLed); void setup() { WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); } client.setServer(mqtt_server, 1883); client.setCallback(callback); irsend.begin(); } void loop() { if (!client.connected()) { reconnect(); } client.loop(); } void callback(char* topic, byte* payload, unsigned int length) { payload[length] = '\0'; String strTopic = String(topic); String strPayload = String((char * ) payload); if(strTopic == "Infrared_topic") // Ggf. andere Bezeichnung festlegen * { //fuer spätere unterscheidung if(strPayload == "false") { irsend.sendRC5(0x4C, 12); //Meinen ermittelnden IR-Code eintragen } if (strPayload == "true") { irsend.sendRC5(0x4C, 12); //Weiteren ermittelnder IR-Code eintragen } } } void reconnect() { while (!client.connected()) { String clientId = "ESP8266_IR"; if (client.connect(clientId.c_str())) { client.subscribe("Infrared_topic"); //Ggf. aendern w.o. * } else { delay(6000); } } }