require(dirname(__FILE__).'/src/mysensors.class.php'); // define your default here ------------------------------------------------ $defaults['node'] ="0"; $defaults['child'] ="0"; $defaults['type'] ="0"; $defaults['ack'] ="0"; $defaults['sub'] ="0"; $defaults['payload'] =""; $defaults['message'] =""; $defaults['wait'] =""; // set the gateway type "eth" or "serial" ------------------------------------- $gateway = "eth"; // gateway type to use $defaults['ip'] ="10.1.7.40"; // default IP address $defaults['port'] ="5003"; // default TCP Port //or //$gateway = "serial"; // gateway type to use //$defaults['s_port'] ="COM1"; // default Serial Port // ############################################################################################ // process form inputs -------------------------------------------- foreach($defaults as $d => $v){ $form[$d] = isset($_REQUEST[$d]) ? $_REQUEST[$d] : $v; } // make javascript types objects ----------------------------------- $mys= new MySensors(); $mess_types=$mys->getMessageTypes(); $sub_types=$mys->getSubTypes(); $js_types .="var types ={};\n"; $js_types .="var mess_types=[];\n"; foreach($mess_types as $t_name => $t){ $js_types .="mess_types[$t]= '$t_name';\n"; $js_types .="types.$t_name= [];\n"; $ts=''; if($t==$form['type']){$ts=" selected='selected'";} $html_options_mess .=" \n"; foreach($sub_types[$t] as $code => $n){ $js_types.="types.{$t_name}[{$n}] = '$code';\n"; } } // process the form ------------------------------------------------- if($_REQUEST['do']){ if($gateway=='serial'){ $mys=new MySensorSendSerial($form['s_port']); } else{ $mys=new MySensorSendEthernet($form['ip'],$form['port']); } $result=$mys->sendMessage($form['node'],$form['child'],$form['type'],$form['ack'],$form['sub'],$form['payload'],$form['wait']); if($result){ $class='success'; if($form['wait']){ $err_mess="Received : $result"; } else{ $err_mess="Successfull!"; } } else{ $class='danger'; if($form['wait']){ $err_mess="Did not receive an answer!"; } else{ $err_mess="Something went wrong. Check GW is receiving on {$form['ip']}:{$form['port']} ! "; } } $last_mess = "