I'll show you how to Remote control USB Web Relays
Needed
1 RaspberryPI
1 PC Remote
1 USB relay
1 USB cable
recommend install Raspbian
C code : kbd.c
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/input.h>
#include <string.h>
#include <stdio.h>
static const char *const evval[3] = {
"RELEASED",
"PRESSED ",
"REPEATED"
};
char inData[4] = {0,0,0,0}; //Input Buffer
char *ptr;
int main(void)
{
const char *dev = "/dev/input/event0";
struct input_event ev;
ssize_t n;
int fd;
ptr = &inData[0];
fd = open(dev, O_RDONLY);
if (fd == -1) {
fprintf(stderr, "Cannot open %s: %s.\n", dev, strerror(errno));
return EXIT_FAILURE;
}
while (1) {
n = read(fd, &ev, sizeof ev);
if (n == (ssize_t)-1) {
if (errno == EINTR)
continue;
else
break;
} else
if (n != sizeof ev) {
errno = EIO;
break;
}
if (ev.type == EV_KEY && ev.value >= 0 && ev.value <= 2)
// printf("%s 0x%04x (%d)\n", evval[ev.value], (int)ev.code, (int)ev.code);
if(ev.value == 1){//Pressed
if(ev.code == 163){// >| key
popen("exec /home/pi/pcremote/./on.sh","r");
}
else if(ev.code == 165){// |< key
popen("exec /home/pi/pcremote/./off.sh","r");
}
else{}
}
}
fflush(stdout);
fprintf(stderr, "%s.\n", strerror(errno));
return EXIT_FAILURE;
}
File : on.sh
#!/bin/bash
# sends on signal to the USB relay
echo -e "\xFF\x01\x01" > /dev/ttyUSB0
File: off.sh
#!/bin/bash
# sends on signal to the USB relay
echo -e "\xFF\x01\x00" > /dev/ttyUSB0