0){ //if2 $i++; $RetData[$i]=substr($phrase,$phrpos+43,16); //echo $i." ".$RetData[$i]."\r\n"; } // end if2 } // end while1 if ($RetData[1]== $owb_dev[1]) { echo "1-Wire Device ". $owb_dev[3]. "(". $owb_dev[2]. ") present\r\n"; $OwbStat=GetValueInteger("owb_stat"); $OwbStat |= 0x1<<($owb_nr-1); SetValueInteger("owb_stat",$OwbStat); } else { $OwbStat=GetValueInteger("owb_stat"); $OwbStat &= 0xFFFFFFFE<<($owb_nr-1); SetValueInteger("owb_stat",$OwbStat); } fclose($connection); } // end if1 } // end foreach1 /***************************************************** * Example: Communicate with 18B20 * Temperature Sensor *****************************************************/ $owb_nr=1; //select DS18B20 //------------- configure device --------------------- $owb_data="4E00003F"; //switch to 10bit resolution $connection = fsockopen($HA7NetAdr ,80, $errnr, $errstr, $socktimeout); //Script terminates with error message if if($connection){ // if1 fputs($connection, "GET /1Wire/WriteBlock.html?Address=". $owb[$owb_nr][1]."&Data=".$owb_data." HTTP/1.0\r\n\r\n"); $i=0; while(!feof($connection)){ //while1 $phrase = fgets($connection,128); $phrpos = strpos($phrase,"ResultData_",0); if ($phrpos>0){ //if2 $i++; $RetData[$i]=substr($phrase,$phrpos+46,8); echo $i." ".$RetData[$i]."\r\n"; } // end if2 } // end while1 fclose($connection); } // end if1 //------------- configure device --------------------- $owb_data="44"; //start conversion $connection = fsockopen($HA7NetAdr ,80, $errnr, $errstr, $socktimeout); //Script terminates with error message if if($connection){ // if1 fputs($connection, "GET /1Wire/WriteBlock.html?Address=". $owb[$owb_nr][1]."&Data=".$owb_data." HTTP/1.0\r\n\r\n"); $i=0; while(!feof($connection)){ //while1 $phrase = fgets($connection,128); $phrpos = strpos($phrase,"ResultData_",0); if ($phrpos>0){ //if2 $i++; $RetData[$i]=substr($phrase,$phrpos+46,2); echo $i." ".$RetData[$i]."\r\n"; } // end if2 } // end while1 fclose($connection); } // end if1 //-------------- Get Temperature -------------------------- // $starttime=time(); // while (time()<$starttime+1) ; not necessary with 10bit resolution $owb_data="BEFFFF"; //start conversion $connection = fsockopen($HA7NetAdr ,80, $errnr, $errstr, $socktimeout); //Script terminates with error message if if($connection){ // if1 fputs($connection, "GET /1Wire/WriteBlock.html?Address=". $owb[$owb_nr][1]."&Data=".$owb_data." HTTP/1.0\r\n\r\n"); $i=0; while(!feof($connection)){ //while1 $phrase = fgets($connection,128); $phrpos = strpos($phrase,"ResultData_",0); if ($phrpos>0){ //if2 $i++; $RetData[$i]=substr($phrase,$phrpos+48,4); echo $i." ".$RetData[$i]."\r\n"; } // end if2 } // end while1 fclose($connection); } // end if1 // calculate temperature in degree Celsius $temp=hexdec(substr($RetData[1],0,1))+hexdec(substr($RetData[1],2,2))*16; if ($temp>128) $temp=4096-$temp; $temperature = $temp + hexdec(substr($RetData[1],0,1))/16; echo $temperature."\r\n"; SetValueFloat("OWB_Temp_01",round($temperature,1)); ?>