0% encontró este documento útil (0 votos)
77 vistas4 páginas

Práctica No.28 Insertar Datos A Firebase Mediante PHP y CURL

El documento describe un script en PHP que usa la librería CURL para insertar datos de un formulario HTML en la base de datos Firebase. El formulario HTML recopila la temperatura y un mensaje. El script PHP muestra los datos ingresados, los convierte a formato JSON y los envía a la URL de Firebase usando CURL. Si se envían correctamente, muestra un mensaje de éxito.
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
77 vistas4 páginas

Práctica No.28 Insertar Datos A Firebase Mediante PHP y CURL

El documento describe un script en PHP que usa la librería CURL para insertar datos de un formulario HTML en la base de datos Firebase. El formulario HTML recopila la temperatura y un mensaje. El script PHP muestra los datos ingresados, los convierte a formato JSON y los envía a la URL de Firebase usando CURL. Si se envían correctamente, muestra un mensaje de éxito.
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
Está en la página 1/ 4

Práctica no.

28 Insertar datos en firebase Comunicación de datos y Interface Web


por medio de php y librería CURL

Aplicaciones de IoT Quinto cuatrimestre

FORMULARIO EN HTML

FORMULARIO EN HTML “formulario.html”

<html>
<head>
<title>Formulario de entrada del datos</title>
</head>
<body>
<form method="post" action="firebaseinsertar.php">
Ingresa temperatura:
<input type="text" name="temperatura">
<br>
Ingresa mensaje:
<input type="text" name="mensaje">
<br>
<input type="submit" value="confirmar">
</form>
</body>
</html>

SALIDA DEL SCRIPT EN PHP


PROGRAMA EN PHP “firebaseInsertar.php”

<!DOCTYPE html>
<html>
<head>
<title>TEMPERATURA EN FIREBASE</title>
<meta charset="UTF-8">
</head>
<body background="" bgcolor="FFCECB" >
<!-- The core Firebase JS SDK is always required and must be listed first --> <script
src="https://www.gstatic.com/firebasejs/8.8.1/firebase-app.js"></script> <!-- TODO:
Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries --> <script
src="https://www.gstatic.com/firebasejs/8.8.1/firebase-analytics.js"></script> <script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
apiKey: "AIzaSyBW8B9R8UtTM9HnK_PWvUQ7oEc-LkSs-LI",
authDomain: "nenat195.firebaseapp.com",
databaseURL: "https://nenat195-default-rtdb.firebaseio.com",
projectId: "nenat195",
storageBucket: "nenat195.appspot.com",
messagingSenderId: "579544161214",
appId: "1:579544161214:web:ea824748e0ee8c61a937ef",
measurementId: "G-LC5HF62W85"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
<?php
echo "La temperatura ingresada es:";
echo $_REQUEST['temperatura'];
$temp=$_REQUEST['temperatura'];
echo "<br> El mensaje ingresado es:";
echo $_REQUEST['mensaje'];
$mens=$_REQUEST['mensaje'];
echo "<br>";
$datos='{"LM35":'.'"'.$temp.'"'.','.'"Mensaje":'.'"'.$mens.'"'.'}';
$url="https://nenat195-default-rtdb.firebaseio.com/Sensores.json";
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datos);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
$respuesta_datos =curl_exec($ch);
if(curl_errno($ch)){
echo 'Error de:'.curl_errno($ch);
}else{
echo "Los datos se insertaron con éxito";}
?>
</body>
</html>
RESULTADO
Formulario para insertar datos

RETO:

Por medio de un formulario, consultar el dato de una de las colecciones de Sensores empleando
para ello CURL.

También podría gustarte