Adventures on Samsung Android IR Remote Control and IVR Integration

This saturday night, I would like to take a challenge, to study how Samsung Android IR (Infra Red) Remote control can control my home’s Air Conditional and TV in living room. And when it worked, I would like to integrate it with IVR, meant I can make a call to control my home appliances when I am outside without Internet Access.

The idea is to, have Samsung Android device put on a table pointed to TV, and at the same time make a socket connection to my remote server to receive IR signal command, once get the command just send forward to the TV. And integrate with IVR Freeswitch which provide IVR menu and then send IR signal to the device.

I built a Freeswitch ESL server using Node.JS and have DID linked to Freeswitch. I built a net socket server in the same Node.JS process but listen to different port. Once there is a call reached ESL server, I will trigger a socket event to write special IR command to the connected clients. The connected clients and then forward the IR command to the controlled appliances.

Code snippets of Node.JS ESL Server.


conn.execute('answer');
///http://wiki.freeswitch.org/wiki/Event_List#CHANNEL_APPLICATION
var step1 = function() {
agentutil.prompt(conn, 'Welcome to the Remote Control Service', mainMenu);
}

var mainMenu = function() {
agentutil.prompt(conn, 'To control Air Cond, press 1. To control T V, press 2. Otherwise, press 9.', function() {
agentutil.collectDtmf(conn, function(dtmf) {
if(dtmf == 1) {
control_Aircond();
return true;
}
else if(dtmf == 2) {
control_TV();
}
else if(dtmf == 9) {
bye();
return true;
}
return false;
});
});
};

...........
...........

var control_Aircond = function() {
agentutil.prompt(conn, 'To turn on the Air Con, press 1. To turn off the Dai Kin Air Conditional, press 2. To go back to main menu, press 9.', function() {
agentutil.collectDtmf(conn, function(dtmf) {
if(dtmf == 1) {
irsend('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');

..............
..............

var net = require('net');
var sockets = [];

// Start a TCP Server
net.createServer(function (socket) {
.........
.........
}).listen(12345);

........
........
var socket_send = function(data) {
if(sockets.length) {
for(var i in sockets) {
var socket = sockets[i];
if(socket.ended) continue;
socket.write(data);
}
}
}
var irsend = function(data) {
socket_send('irsend:' + data + '\n');
}

I implemented Samsung irDA service on Android. It will register to my Node JS server via TCP socket connection. Once received any IR command, it will just send to the controlled appliances via IR chip.


public void irInit() {
irdaService = this.getSystemService("irda");
Class c = irdaService.getClass();
Class p[] = { String.class };
try {
irWrite = c.getMethod("write_irsend", p);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}

public void irSend(String data) {
if (data != null) {
try {
irWrite.invoke(irdaService, data);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}

........
........

Socket socket = new Socket(SERVER_IP, SERVER_PORT);
ObjectOutputStream output = new ObjectOutputStream(socket.getOutputStream());

InputStream inputstream = socket.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(inputstream));
String line;
while((line = br.readLine()) != null) {
if(line.startsWith("irsend:")) {
ma.irSend(line.substring("irsend:".length()));
}
}
output.close();
inputstream.close();
socket.close();

Implementing these interface code is easy, the challenge is to find the IR command that match the brand of Air Cond and TV, different manufacturer had different IR code to send, this takes me few hours of digging.

After that, I finally made it. I am very excited and then I quickly demo to my mum and sister. Calling from a mobile, and home telephone, following IVR menu, and then to control the TV in the living room, by power on/off TV and change TV channel, and it just worked!

The limitation is that I had to point the Samsung device either on the TV or Air Cond at one time, after show to my mum and sister they feedback that. The future works maybe using Zigbee? Rasperry PI? Arduino? But will requires TV and Air Cond support the protocol as well, really too far advanced for me.

Author: fyhao

Jebsen & Jessen Comms Singapore INTI University College Bsc (Hon) of Computer Science, Coventry University

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.