IoT project that allows its users to send IR signals from any computer within a network. For that purpose, an ESP8266-enabled development board is connected to an IR sender module, and the finished device hosts a website that allows users to send out codes. The device can be useful, for example, to remote-control several devices from within a network without having to replace the existing electronic equipment with connected items. project made by R.V.S Aditya
for more follow me on instagram and github
//code of Universal Internet Connected Remote Control// idea form maker.io//made by RVS Aditya From HackAtech Industries#include<IRremoteESP8266.h>#include<IRsend.h>#include<ESP8266WiFi.h>#define LED_PIN 5#define STORAGE_SIZE 5constchar* ssid = "YOUR_NETWORK_NAME";
constchar* pass = "NETWORK_PASSWORD";
WiFiServer server(80);
IRsend sender(LED_PIN);
long codes[STORAGE_SIZE] = {0x00123,0x02,0xAB,0x0F,0x0};
bool stored[STORAGE_SIZE] = {true,false,false,false,false};
int protocols[STORAGE_SIZE] = {0,1,1,0,1};
// Function PrototypesintcontainsValidIndex(String);
String findParameterValue(String, String);
voidsetup(){
Serial.begin(9600);
while(!Serial)
delay(50);
sender.begin();
Serial.println("");
Serial.print("Connecting to ");
Serial.print(ssid);
WiFi.begin(ssid, pass);
while(WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.println("Done!");
Serial.println("Starting server...");
server.begin();
Serial.print("Server started with address ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
voidloop(){
// Check for incoming connections
WiFiClient c = server.available();
if(c)
{
while(!c.available())
delay(10);
// Read the first line of the HTTP request// It contains something similar to the following line:// METHOD /requested_url HTTP_VERSION// for example:// GET /send?value=0x0085&protocol=NEC HTTP/1.1// However, for the sake of simplicity this device only accepts// GET requests as they can be sent with any web browser.// Updating values this way is not the 'correct' way according to// the HTTP standard but it makes using the device easier.
String request = c.readStringUntil('\r');
c.flush();
int error = 0;
int value = request.indexOf("value=");
int protocol = request.indexOf("protocol=");
int index = request.indexOf("index=");
int snd = request.indexOf("/send");
int str = request.indexOf("/store");
int del = request.indexOf("/delete");
Serial.println(request);
// The following few if/else-statements parse the incoming request// and then execute the action that the user requested.// The user requested the send page and did not include /store or /delete in their requestif (snd != -1 && str == -1 && del == -1)
{
// The user requested the send page and included a value for the indexif(index != -1)
{
// Check if the supplied index is valid (i.e. at least zero and less than STORAGE_SIZE)// And check if the values array contains an entry at the requested position// First, get the value of the parameter as a string
String index_string = findParameterValue(request, "index");
// Next, convert it to an integer and check whether the value is validint i = containsValidIndex(index_string);
if(i > -1 && stored[i])
{
// The parameter was valid. Repeat the stored value!// Make sure to verify the bit length for your remotes!// I used 32 and 14 in this program, but yours might varyif(protocols[i] == 0)
sender.sendNEC(codes[i], 32);
else
sender.sendRC5(codes[i], 14);
Serial.print("Repeat the value stored at position ");
Serial.println(i);
}
}
// The user supplied the wrong parameters for this request.else
{
error = 1;
Serial.print("Unknown request: ");
Serial.println(request);
}
}
// The user requested the /store page and the request didn't include// the /send or /delete pageelseif(str != -1 && snd == -1 && del == -1)
{
// The user supplied the wrong parameters for this request.// (Either of the three parameters is missing)if(index == -1 || protocol == -1 || value == -1)
{
error = 1;
Serial.print("BAD REQUEST. Missing field: ");
Serial.println(request);
}
else
{
String p = findParameterValue(request, "protocol");
String v = findParameterValue(request, "value");
int i = containsValidIndex(findParameterValue(request, "index"));
// Check if the supplied index is validif(i > -1)
...