PHPoC board itself is also an embedded web server. We upload web UI on this board. When Web Browser makes an HTTP request to PHPoC Board. It returns this web UI to Web Brower.
When user chooses a cocktail from Web Browser, the cocktail name will be sent to PHPoC board via web-socket. The server side code in PHPoC board receives this cocktail name and control the cocktail machine to make that cocktail.
For detail how to wiring among PHPoC, Step motor controller and Step motor, refer to this manual.
I have another project which uses Alexa to control cocktail machine here.
This code runs in infinite loop to receives command (cocktail name) from web browser via web-socket and control step motors on the cocktail machine to make the cocktail
<?phpinclude_once"/lib/sd_spc.php";include_once"/lib/sn_tcp_ws.php";define("SID_X",13);define("SID_Y",14);define("COCKTAIL_FLOW_TIME",3);// time for cocktail flow into cup in seconddefine("COCKTAIL_WAIT_TIME",3);functionstep_wait($sid){while((int)spc_request_dev($sid,"get state")>1)usleep(1);}functionspc_check_did($sid,$did){$resp=spc_request_csv($sid,0,"get did");if($resp===false){echo"spc_check_did: sid$sid - device not found\r\n";returnfalse;}if($resp[1]!="40002405"){echo"spc_check_did: unknown device ",$resp[2],"\r\n";returnfalse;}returntrue;}functioncooktail_get_id($drink_name){global$names;for($i=0;$i<4;$i++){if($names[$i]==$drink_name)return$i;}return-1;}functioncocktail_get($recipe){global$pos;spc_request_dev(SID_X,"goto -sw1 20000 1000000");step_wait(SID_X);spc_request_dev(SID_X,"reset");for($step_motor=0;$step_motor<4;$step_motor++)// get component one by one{$amount=$recipe[$step_motor];if($amount>0){$ps=$pos[$step_motor];spc_request_dev(SID_X,"goto +$ps 20000 1000000");step_wait(SID_X);for($i=1;$i<=$amount;$i++){if($i!=1)sleep(COCKTAIL_WAIT_TIME);spc_request_dev(SID_Y,"goto -sw0 30000 1000000");step_wait(SID_Y);sleep(COCKTAIL_FLOW_TIME);spc_request_dev(SID_Y,"reset");spc_request_dev(SID_Y,"goto 90000 30000 1000000");step_wait(SID_Y);}spc_request_dev(SID_Y,"goto 140000 30000 1000000");step_wait(SID_Y);}}}functioncocktail_init(){spc_reset();spc_sync_baud(460800);if(!spc_check_did(SID_X,"40002405"))return;if(!spc_check_did(SID_Y,"40002405"))return;spc_request_dev(SID_X,"set vref stop 4");spc_request_dev(SID_X,"set vref drive 15");spc_request_dev(SID_X,"set mode 32");spc_request_dev(SID_X,"set rsnc 120 250");spc_request_dev(SID_Y,"set vref stop 4");spc_request_dev(SID_Y,"set vref drive 15");spc_request_dev(SID_Y,"set mode 32");spc_request_dev(SID_Y,"set rsnc 120 250");spc_request_dev(SID_X,"goto +sw0 20000 1000000");step_wait(SID_X);spc_request_dev(SID_Y,"goto -sw0 30000 1000000");step_wait(SID_Y);spc_request_dev(SID_X,"reset");spc_request_dev(SID_Y,"reset");spc_request_dev(SID_Y,"goto 140000 30000 1000000");step_wait(SID_Y);spc_request_dev(SID_X,"goto +sw0 20000 1000000");step_wait(SID_X);spc_request_dev(SID_X,"reset");spc_request_dev(SID_Y,"reset");}$names=array("SUMMER_RAIN","SCREW_DRIVER","BLACK_RUSSIAN","BLACK_RUSSIAN_2","SWEET_MARTINI","MARTINI");$recipe_list=array(//MALIBU | VODKA | OGRANGE_JUICE | KAHLUA | GIN ||array(2,1,0,0,0),//||SUMMER_RAINarray(0,1,2,0,0),//||SCREW_DRIVERarray(0,1,0,2,0),//||BLACK_RUSSIANarray(0,2,0,1,0),//||BLACK_RUSSIAN_2);// motor pos: //MALIBU | VODKA | OGRANGE_JUICE | KAHLUA | GIN | DRY_VERMOUTH $pos=array(1000,22000,41000,63000,82000,102000);ws_setup(0,"cocktail","text.phpoc");cocktail_init();$rbuf="";while(1){if(ws_state(0)==TCP_CONNECTED){$rlen=ws_read_line(0,$rbuf);if($rlen){$drink_name=rtrim($rbuf,"\r\n");$id=cooktail_get_id($drink_name);if($id>=0){$recipe=$recipe_list[$id];cocktail_get($recipe);}elseecho"cocktail: The drink is not found\r\n";spc_request_dev(SID_X,"goto -sw1 20000 1000000");step_wait(SID_X);spc_request_dev(SID_X,"reset");}}}?>
Comments