Skip to content

Instantly share code, notes, and snippets.

@milankragujevic
Created February 18, 2018 09:45
Show Gist options
  • Save milankragujevic/f7700cdbcde78113eef4d9aaa1bd7da9 to your computer and use it in GitHub Desktop.
Save milankragujevic/f7700cdbcde78113eef4d9aaa1bd7da9 to your computer and use it in GitHub Desktop.
Bear DTV-202 Quad IR remote ESP8266/NodeMCU Arduino sketch
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <WiFiClient.h>
MDNSResponder mdns;
IRsend irsend1(14);
IRsend irsend2(12);
IRsend irsend3(13);
IRsend irsend4(15);
ESP8266WebServer server(80);
const char* ssid = "[WIFI NAME]";
const char* password = "[WIFI PASS]";
const char* mDNSName = "esp8266";
const uint32_t btnPwr = 0x15629B25;
const uint32_t btnMute = 0x57E346E1;
const uint32_t btnInfo = 0xBBB54321;
const uint32_t btnRecall = 0x6BFD8B01;
const uint32_t btnPause = 0x986FB325;
const uint32_t btnMenu = 0xCEBE4CC1;
const uint32_t btnExit = 0xA6B913BD;
const uint32_t btnUp = 0xD0529225;
const uint32_t btnDown = 0x85E09D61;
const uint32_t btnLeft = 0xC806D53D;
const uint32_t btnRight = 0xD035B645;
const uint32_t btnOk = 0x90C35B01;
const uint32_t btnEpg = 0x73A3CEBD;
const uint32_t btnFav = 0x25802501;
const uint32_t btnPageUp = 0xE7ABE421;
const uint32_t btnPageDown = 0xD51CCE5D;
const uint32_t btn1 = 0xCFB32D61;
const uint32_t btn2 = 0xD32B70FD;
const uint32_t btn3 = 0xDEE522C1;
const uint32_t btn4 = 0x9D3D4D25;
const uint32_t btn5 = 0xE32F7CC1;
const uint32_t btn6 = 0xCBD2CCFD;
const uint32_t btn7 = 0x74514645;
const uint32_t btn8 = 0xBA4375E1;
const uint32_t btn9 = 0xB1EFBA9D;
const uint32_t btn0 = 0x6539FA7D;
const uint32_t btnAudio = 0x168E56C1;
const uint32_t btnLang = 0xA3CC4A5;
const uint32_t btnTvRadio = 0x1E90961;
const uint32_t btnTtx = 0xAAFCAC1;
const uint32_t btnRed = 0x2F1EC521;
const uint32_t btnGreen = 0x7510F4BD;
const uint32_t btnYellow = 0x1644C1C1;
const uint32_t btnBlue = 0xC98F01A1;
void handleRequest() {
String message = "";
if(server.arg("code") == "") {
message = "MISSING_PARAM_CODE";
} else {
if(server.arg("tx") == "") {
message = "MISSING_PARAM_TX";
} else {
if(server.arg("code") == "btnPwr") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnPwr, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnPwr, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnPwr, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnPwr, 32);
}
message = "OK";
}
if(server.arg("code") == "btnMute") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnMute, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnMute, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnMute, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnMute, 32);
}
message = "OK";
}
if(server.arg("code") == "btnInfo") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnInfo, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnInfo, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnInfo, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnInfo, 32);
}
message = "OK";
}
if(server.arg("code") == "btnRecall") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnRecall, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnRecall, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnRecall, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnRecall, 32);
}
message = "OK";
}
if(server.arg("code") == "btnPause") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnPause, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnPause, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnPause, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnPause, 32);
}
message = "OK";
}
if(server.arg("code") == "btnMenu") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnMenu, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnMenu, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnMenu, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnMenu, 32);
}
message = "OK";
}
if(server.arg("code") == "btnExit") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnExit, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnExit, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnExit, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnExit, 32);
}
message = "OK";
}
if(server.arg("code") == "btnUp") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnUp, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnUp, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnUp, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnUp, 32);
}
message = "OK";
}
if(server.arg("code") == "btnDown (Down)") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnDown, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnDown, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnDown, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnDown, 32);
}
message = "OK";
}
if(server.arg("code") == "btnLeft") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnLeft, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnLeft, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnLeft, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnLeft, 32);
}
message = "OK";
}
if(server.arg("code") == "btnRight") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnRight, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnRight, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnRight, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnRight, 32);
}
message = "OK";
}
if(server.arg("code") == "btnOk") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnOk, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnOk, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnOk, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnOk, 32);
}
message = "OK";
}
if(server.arg("code") == "btnEpg") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnEpg, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnEpg, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnEpg, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnEpg, 32);
}
message = "OK";
}
if(server.arg("code") == "btnFav") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnFav, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnFav, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnFav, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnFav, 32);
}
message = "OK";
}
if(server.arg("code") == "btnPageUp") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnPageUp, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnPageUp, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnPageUp, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnPageUp, 32);
}
message = "OK";
}
if(server.arg("code") == "btnPageDown") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnPageDown, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnPageDown, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnPageDown, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnPageDown, 32);
}
message = "OK";
}
if(server.arg("code") == "btn1") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btn1, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btn1, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btn1, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btn1, 32);
}
message = "OK";
}
if(server.arg("code") == "btn2") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btn2, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btn2, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btn2, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btn2, 32);
}
message = "OK";
}
if(server.arg("code") == "btn3") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btn3, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btn3, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btn3, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btn3, 32);
}
message = "OK";
}
if(server.arg("code") == "btn4") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btn4, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btn4, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btn4, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btn4, 32);
}
message = "OK";
}
if(server.arg("code") == "btn5") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btn5, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btn5, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btn5, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btn5, 32);
}
message = "OK";
}
if(server.arg("code") == "btn6") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btn6, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btn6, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btn6, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btn6, 32);
}
message = "OK";
}
if(server.arg("code") == "btn7") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btn7, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btn7, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btn7, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btn7, 32);
}
message = "OK";
}
if(server.arg("code") == "btn8") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btn8, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btn8, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btn8, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btn8, 32);
}
message = "OK";
}
if(server.arg("code") == "btn9") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btn9, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btn9, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btn9, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btn9, 32);
}
message = "OK";
}
if(server.arg("code") == "btn0") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btn0, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btn0, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btn0, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btn0, 32);
}
message = "OK";
}
if(server.arg("code") == "btnAudio") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnAudio, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnAudio, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnAudio, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnAudio, 32);
}
message = "OK";
}
if(server.arg("code") == "btnLang") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnLang, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnLang, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnLang, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnLang, 32);
}
message = "OK";
}
if(server.arg("code") == "btnTvRadio") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnTvRadio, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnTvRadio, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnTvRadio, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnTvRadio, 32);
}
message = "OK";
}
if(server.arg("code") == "btnTtx") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnTtx, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnTtx, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnTtx, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnTtx, 32);
}
message = "OK";
}
if(server.arg("code") == "btnRed") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnRed, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnRed, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnRed, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnRed, 32);
}
message = "OK";
}
if(server.arg("code") == "btnGreen") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnGreen, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnGreen, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnGreen, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnGreen, 32);
}
message = "OK";
}
if(server.arg("code") == "btnYellow") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnYellow, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnYellow, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnYellow, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnYellow, 32);
}
message = "OK";
}
if(server.arg("code") == "btnBlue") {
if(server.arg("tx") == "1") {
irsend1.sendNEC(btnBlue, 32);
}
if(server.arg("tx") == "2") {
irsend2.sendNEC(btnBlue, 32);
}
if(server.arg("tx") == "3") {
irsend3.sendNEC(btnBlue, 32);
}
if(server.arg("tx") == "4") {
irsend4.sendNEC(btnBlue, 32);
}
message = "OK";
}
}
}
server.sendHeader("Access-Control-Allow-Origin", "*");
server.send(200, "text/plain", message);
}
void setup() {
Serial.begin(115200);
delay(10);
irsend1.begin();
irsend2.begin();
irsend3.begin();
irsend4.begin();
Serial.println();
Serial.println("DTV-202 Quad IR Bridge");
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(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("");
if(mdns.begin(mDNSName)) {
Serial.println("MDNS responder started");
String identifyMessage = "Identified as ";
identifyMessage += mDNSName;
Serial.println(identifyMessage);
} else {
Serial.println("Couldn't start MDNS responder!");
}
server.on("/", handleRequest);
server.onNotFound([](){
server.sendHeader("Access-Control-Allow-Origin", "*");
server.send(404, "text/plain", "PAGE_NOT_FOUND");
});
server.begin();
Serial.println("Server started on port 80");
}
void loop() {
server.handleClient();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment