La salud, al momento, mejor
-
Clonar este repositorio en Google Cloud Platform;
-
Habilitar las APIs requeridas con los siguientes comandos:
gcloud services enable dataflow.googleapis.com
gcloud services enable cloudiot.googleapis.com
gcloud services enable cloudbuild.googleapis.com
- Crear entorno virtual de Python;
virtualenv -p python3 <ENVIRONTMENT_NAME>
source <ENVIRONMENT_NAME>/bin/activate
- Instalar las dependencias necesarias.
pip install -U -r setup_dependencies.txt
- Ir a Cloud Console PubSub;
- Crear un tema y añadir una subscripción por defecto.
- Ir a Cloud Console Cloud Storage;
- Crear un bucket con un nombre único
Para esta demostración, usaremos Cloud Shell como un dispositivo IoT generador de datos;
-
Ir a Cloud Console IoT Core;
-
Crear un registro IoT escogiendo el tema PubSub creado anteriormente;
-
Ir a Cloud Shell y generar una clave "RSA key with-self signed X509 certificate"
-
Registrar un dispositivo y actualizar la clave rsa_cert.pem en la sección de autenticación
Ahora ya hemos vinculado nuestro dispositivo con IoT Core.
-
Ir a Cloud Console Big Query
-
Crear un BigQuery Dataset
- Ir a la carpeta 02_Dataflow para crear una Plantilla;
- Empaquetar el código python en una imagen de Docker y guardarlo en el registro de contenedores, ejecutando este comando;
gcloud builds submit --tag 'gcr.io/<YOUR_PROJECT_ID>/<YOUR_FOLDER_NAME>/<YOUR_IMAGE_NAME>:latest' .
- Crear la Plantilla Dataflow desde la imagen Docker:
gcloud dataflow flex-template build "gs://<YOUR_BUCKET_NAME>/<YOUR_TEMPLATE_NAME>.json" \
--image "gcr.io/<YOUR_PROJECT_ID>/<YOUR_FOLDER_NAME>/<YOUR_IMAGE_NAME>:latest" \
--sdk-language "PYTHON"
- Para terminar, ejecutar el Dataflow job desde la Plantilla:
gcloud dataflow flex-template run "<YOUR_DATAFLOW_JOB_NAME>" \
--template-file-gcs-location "gs://<YOUR_BUCKET_NAME>/<YOUR_TEMPLATE_NAME>.json" \
--region "europe-west1"
- Crear una Google Cloud Function para pasar los datos a Firestore;
- "main.py"
import base64
import json
from google.cloud import firestore
from datetime import datetime
client = firestore.Client(project='lithe-window-342416')
def dataICareFireStore(event, context):
message = ''
if 'data' in event:
message = base64.b64decode(event['data']).decode('utf-8')
ICaredata = json.loads(message)
doc = client.collection('device').document( str(ICaredata["id_usuario"]))
doc.set({
'id_usuario': ICaredata["id_usuario"],
'id_dispositivo': ICaredata["id_dispositivo"],
'bateria_dispositivo': ICaredata["bateria_dispositivo"],
'timeStamp': ICaredata["timeStamp"],
'presion_arterial': ICaredata["presion_arterial"],
'frec_cardiaca': ICaredata["frec_cardiaca"],
'frec_respiratoria': ICaredata["frec_respiratoria"],
'temperatura': ICaredata["temperatura"],
'oxigeno_sangre': ICaredata["oxigeno_sangre"],
'alertas': ICaredata["alertas"],
})
print(f'message: {message}')
- "requirements.txt"
google-cloud-firestore>=2.1.3
google-cloud-iot
- Ir a la carpeta 01_IoTCore y ejecutar el siguiente comando:
python edemDeviceData.py \
--algorithm RS256 \
--cloud_region europe-west1 \
--device_id <YOUR_IOT_DEVICE_NAME> \
--private_key_file rsa_private.pem \
--project_id <YOUR_PROJECT_ID> \
--registry_id <YOUR_IOT_REGISTRY>
- Ir a Big Query;
-
FireStore
-
Vincular ICare Dashboard
Compuesto por: