<?php  
$server="localhost"; $user="sdatelem_icuadm"; $pass="Icupu2015"; $db="sdatelem_icu";
$con_project=mysql_connect($server, $user, $pass);
$db_project=mysql_select_db($db,$con_project);

 $sumber = 'https://bwssumatera4:hidrologi2018@prinus.net/api/sensor';
 $konten = file_get_contents($sumber);
 $data = json_decode($konten, true);
 for($a=0; $a < count($data); $a++)
   {
   	 $sensor=$data[$a]['sn'];
	 $sumber2 = 'https://bwssumatera4:hidrologi2018@prinus.net/api/sensor/'.$sensor;
 	 
 	 "<br>==============================================================<br>";
	 $konten2 = file_get_contents($sumber2);
	 $data2 = json_decode($konten2, true);
	 for($b=0; $b < count($data2); $b++)
	   {
		if($sensor=="1908-1"){$tbl="R_nongsa";}
		else if($sensor=="1908-2"){$tbl="R_sekanak2";}
		else if($sensor=="1908-3"){$tbl="R_sribintan";}
		else if($sensor=="1908-4"){$tbl="R_wadukjago";}
		else if($sensor=="1908-9"){$tbl="R_batubi";}
		else if($sensor=="1908-5"){$tbl="WL_sekanak2";}
		else if($sensor=="1908-6"){$tbl="WL_waduk_sei_jago";}
		else if($sensor=="1908-7"){$tbl="WL_sei_jeram";}
		else if($sensor=="1908-8"){$tbl="WL_kolong_enam";}
		
		$tgl=date('Y-m-d',strtotime($data2[$b]['sampling']));
		//$jam=date('H:i:s',strtotime($data2[$b]['sampling']));
		$jam=substr($data2[$b]['sampling'],11,8);
		$rain=$data2[$b]['tick'];
		$pda=number_format($data2[$b]['wl_scale'],0);
		$bat=$data2[$b]['battery'];
	   
   	    echo $insertToSda="insert into ".$tbl."_temp values ('','".$tgl."','".$jam."','".$tgl."','".$jam."','".$rain."','".$pda."','55')";
	    $queryUp=mysql_query($insertToSda);
	  echo "<br>";
	   }
   }
  ?>
