$arr_data['lamp'],//lamp 's' => $arr_data['servo'] ,//servo 'm' => $arr_data['motor'],//motor ); try{ $jsondata = json_encode($arr_data, JSON_PRETTY_PRINT);//Transform Array to JSON form if(!file_put_contents($myFile, $jsondata)) {echo "Error";}} //Write on the JSON File catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } http_response_code(200); echo json_encode($data);//Return the Json } /**************************************** WEB Page ********************************** */ else{ /////////// Data recording of the web page if($_SERVER['REQUEST_METHOD']=="POST"){ $arr_data['lamp'] = (isset($_POST['lamp']))? 1:0; $arr_data['servo']= (isset($_POST['servo']))? 1:0; $arr_data['motor']= (isset($_POST['motor']))? 1:0; $jsondata = json_encode($arr_data, JSON_PRETTY_PRINT);//Transform Array to JSON form if(!file_put_contents($myFile, $jsondata)) {echo "Error";} //Write on the JSON File } try{ $motion = $arr_data['motion'];//motion $gaz = $arr_data['gaz'];//gaz $temp = $arr_data['temp'];//temp $lamp = $arr_data['lamp'];//lamp $servo = $arr_data['servo'];//servo $motor = $arr_data['motor'];//Dc motor //echo json_encode($arr_data); $jsondata = json_encode($arr_data, JSON_PRETTY_PRINT); if(!file_put_contents($myFile, $jsondata)) {echo 'Fatal Error';} } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } ?>
Smart Kitchen Controller
No movement
' ?>No danger
' ?>