[Subject]

This project is an implementation of the Internet switch by connecting a 4-port relay output board (PES-2401) and a 4-port digital input board (PES-2402) to the PHPoC board type product.


[Video - PHPoC Blue]


[Video - PHPoC Black]



[Description - Input Part]

The PHPoC board monitors the swtich input through the 4 port digital input port (PES-2402), and when the switch input state is changed, it passes the state to the opposite PHPoC board via TCP/IP.


[Description - Output Part]

The PHPoC board which receives the status turns on / off the lamp using the connected 4 port relay output board (PES-2401).
At this time, on / off of the lamp is synchronized with the input ports of the opposite PHPoC board.


[Components - Input Part]

1. PHPoC Blue(P4S-342) or PHPoC Black(P4S-341) x 1
Click image for larger version

Name:	p4s341.jpg
Views:	192
Size:	19.4 KB
ID:	178 or Click image for larger version

Name:	p4s342.jpg
Views:	191
Size:	21.4 KB
ID:	179

2. 4 Port Digital Input Board (PES-2402) x 1
Click image for larger version

Name:	pes2402.jpg
Views:	190
Size:	17.5 KB
ID:	180

3. PHPoC Bread Board (PES-020-002) 1
Click image for larger version

Name:	pes020002.jpg
Views:	176
Size:	17.1 KB
ID:	181

4. Push Buttons x 2 and Jumper Wires


[Components - Output Part]

1. PHPoC Blue(P4S-342) or PHPoC Black(P4S-341) x 1

2. 4 Port Relay Output Board (PES-2401) x 1
Click image for larger version

Name:	pes2401.jpg
Views:	174
Size:	19.2 KB
ID:	182

3. A House Model x 2

[Connection - Input Part]
Click image for larger version

Name:	connection_input.jpg
Views:	187
Size:	32.4 KB
ID:	183

[Connection - Output Part]
Click image for larger version

Name:	connection_output.jpg
Views:	186
Size:	34.4 KB
ID:	184

[Souce Code - Input Part]
PHP Code:
<?php

include_once "/lib/sd_spc.php";
include_once 
"/lib/sn_tcp_ac.php";

spc_reset();
spc_sync_baud(115200);

$sid 1;
$pin_id 0;
$last_in = array(0000);
$in = array(0000);
$server_addr "10.6.0.241";
$server_port 5020;

function 
read_in($sid$pin)
{

    
$response spc_request($sid4"get $pin input");

    
$response_code substr($response03);
    if(
$response_code != "200")
        return -
1;

    
$response_data substr($response41);
    if(
$response_data == "1")
        return 
1;
    elseif(
$response_data == "0")
        return 
0;
    else
        return -
1;
}

spc_request($sid4"set 0 delay 100");

echo 
"connecting...";

tcp_client(0$server_addr$server_port);
while(
tcp_state(0) != TCP_CONNECTED)
    ;

echo 
"connected!\r\n";

while(
1)
{
    
$state_in "";
    
$event false;

    for(
$pin_id 0$pin_id 4$pin_id++)
    {
        if((
$in[$pin_id] = read_in($sid$pin_id)) != $last_in[$pin_id])
        {
            
$last_in[$pin_id] = $in[$pin_id];
            
$event true;
        }
        
usleep(5000);
    }

    if(
$event)
    {
        for(
$pin_id 0$pin_id 4$pin_id++)
        {
            
$state_in .= (string)$last_in[$pin_id];
        }
        echo 
$state_in"\r\n";
        
tcp_write(0$state_in);
    }
}

?>

[Souce Code - Output Part]
PHP Code:
<?php

include_once "/lib/sd_spc.php";
include_once 
"/lib/sn_tcp_ac.php";

spc_reset();
spc_sync_baud(115200);

$sid 1;
$pin_id 0;
$new_out = array(0000);
$local_port 5020;

function 
get_out($sid$pin)
{
    
$response spc_request($sid4"get $pin output");

    
$response_code substr($response03);
    if(
$response_code != "200")
        return -
1;

    
$response_data substr($response41);
    if(
$response_data == "1")
        return 
1;
    elseif(
$response_data == "0")
        return 
0;
    else
        return -
1;
}

function 
set_out($sid$pin$sig)
{
    if(
$sig == 1)
        
$level "high";
    elseif(
$sig == 0)
        
$level "low";
    else
        exit(
"undefined state \r\n");
    
spc_request($sid4"set $pin output $level");
}

echo 
"listen...";

tcp_server(0$local_port);
while(
tcp_state(0) != TCP_CONNECTED)
    ;

echo 
"connected!\r\n";

while(
1)
{
    
$state_in "";
    if(
tcp_read(0$state_in) == 4)
    {
        for(
$pin_id 0$pin_id 4$pin_id++)
        {
            
$new_out[$pin_id] = (int)substr($state_in$pin_id1);
            
set_out($sid$pin_id$new_out[$pin_id]);
            
usleep(5000);
        }
        echo 
$state_in"\r\n";
    }
    
usleep(200000);
}

?>