Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
IR over IP project.
//
// Includes
//
#include <IRremote.h>
#include <SPI.h>
#include <Ethernet.h>
//
// Globals
//
int RECV_PIN = 3;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // Adapter MAC
//
// Inits
//
IRrecv irrecv(RECV_PIN);
decode_results results;
// Network settings for the Eth shield...
byte gateway[] = { 192,168,0,1 };
byte ip[] = { 192,168,0,223 };
// IP of the Raspi and the connection context
IPAddress server(192,168,0,234); // Raspi DVR-IR Transmitter Server IP
EthernetClient client;
/**
* Bit shitty, but get a String (char*) for a remote code.
* lirc only likes textual names for commands, not codes -.-
*/
String get_rcode_name(long rcode)
{
switch(rcode)
{
case 0x20DF30CF:
return "STAND_BY";
case 0x20DF50AF:
return "LOGIN_LOCK";
case 0x20DF807F:
return "NUM_1";
case 0x20DF40BF:
return "NUM_2";
case 0x20DFC03F:
return "NUM_3";
case 0x20DF20DF:
return "NUM_4";
case 0x20DFA05F:
return "NUM_5";
case 0x20DF609F:
return "NUM_6";
case 0x20DFE01F:
return "NUM_7";
case 0x20DF10EF:
return "NUM_8";
case 0x20DF906F:
return "NUM_9";
case 0x20DF18E7:
return "NUM_0";
case 0x20DF28D7:
return "GRID";
case 0x20DF08F7:
return "MENU";
case 0x20DF6897:
return "PTZ";
case 0x20DF7887:
return "EXIT";
case 0x20DF48B7:
return "DIR_UP";
case 0x20DFA857:
return "DIR_RIGHT";
case 0x20DFB847:
return "DIR_DOWN";
case 0x20DFF00F:
return "DIR_LEFT";
case 0x20DF00FF:
return "OK";
case 0x20DF9867:
return "PLUS";
case 0x20DF38C7:
return "MINUS";
case 0x20DF708F:
return "REC";
case 0x20DFB04F:
return "STOP";
case 0x20DFF807:
return "EXTRA";
case 0x20DFE817:
return "RW";
case 0x20DF8877:
return "PLAY";
case 0x20DF2AD5:
return "FF";
case 0x20DFD02F:
return "END";
case 0x20DFC837:
return "PLAY_STOP";
case 0x20DF58A7:
return "AUDIO";
case 0x20DFD827:
return "MUTE";
}
return "NOP";
}
void setup()
{
// Open serial for debugging
Serial.begin(9600);
// Start the receiver
irrecv.enableIRIn();
// Start ethernet
Ethernet.begin(mac, ip, gateway);
}
/**
* Transmit a code over the network.
*/
void tx_code(decode_results *results)
{
if (results->decode_type == NEC && results->bits == 32)
{
// Diagnostics - serial
Serial.print(results->value, HEX);
Serial.print(" (");
Serial.print(results->bits, DEC);
Serial.println(" bits)");
// Make request
if (client.connect(server, 80))
{
client.print("GET /?code=");
client.print(get_rcode_name(results->value));
client.println(" HTTP/1.1");
client.println("Host: 198.211.121.22");
client.println();
client.println();
client.stop();
}
}
}
/**
* Decode any received IR codes.
*/
void loop()
{
if (irrecv.decode(&results))
{
tx_code(&results);
irrecv.resume(); // Receive the next value
}
}
<?php
/**
* Convert HTTP requests into CIR transmissions.
*/
// Get the code
$code = isset($_GET['code']) ? $_GET['code'] : '';
// Valid?
if(!$code)
{
// Didn't get a code.
exit();
}
// Request to send the code
// This will be running on my home network, and is a quick hack.
// note that this line would pose a severe security risk outside.
system('irsend SEND_ONCE DVR ' . $code);
// Log it
$f = fopen('codes.log', 'a');
fwrite($f, $code . PHP_EOL);
fclose($f);
begin remote
name DVR
bits 32
flags SPACE_ENC
eps 20
aeps 200
header 8800 4400
one 550 1650
zero 550 550
ptrail 550
repeat 8800 2200
gap 38500
toggle_bit 0
frequency 38000
begin codes
STAND_BY 0x20DF30CF
LOGIN_LOCK 0x20DF50AF
NUM_1 0x20DF807F
NUM_2 0x20DF40BF
NUM_3 0x20DFC03F
NUM_4 0x20DF20DF
NUM_5 0x20DFA05F
NUM_6 0x20DF609F
NUM_7 0x20DFE01F
NUM_8 0x20DF10EF
NUM_9 0x20DF906F
NUM_0 0x20DF18E7
GRID 0x20DF28D7
MENU 0x20DF08F7
PTZ 0x20DF6897
EXIT 0x20DF6897
DIR_UP 0x20DF48B7
DIR_RIGHT 0x20DFA857
DIR_DOWN 0x20DFB847
DIR_LEFT 0x20DFF00F
OK 0x20DF00FF
PLUS 0x20DF9867
MINUS 0x20DF38C7
REC 0x20DF708F
STOP 0x20DFB04F
EXTRA 0x20DFF807
RW 0x20DFE817
PLAY 0x20DF8877
FF 0x20DF2AD5
END 0x20DFD02F
PLAY_STOP 0x20DFC837
AUDIO 0x20DF58A7
MUTE 0x20DFD827
end codes
end remote
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.