IoTool v3 Save Data

Introduction

The /android/iotool_v3_data flow example is designed for data ingestion and processing. It interacts with PostgreSQL databases to manage sensor data, leveraging HTTP requests, database queries, and custom logic to parse and insert data efficiently.

Flow Overview

This documentation outlines the key components and functionalities within the IoTool v3 Save Data flow, focusing on:

  1. Structuring sensor data and sending it to Node-RED using HTTP POST request,

  2. Managment of sensors through PostgreSQL database

  3. Table creation and manipulation in PostgreSQL

  4. Parsing and inserting sensor data into database tables

Post Request Handling

Purpose

Initiates the flow by receiving data through a POST request to a specified address. This example shows you how to specify endpoint where data is going to be sent and example configuration/structure of data.

Configuration

Following json file only represents example structure of POST request. Json file contains fields for PostgreSQL username and password, along with other parameters such as sensor name and readings. Username and password in example are random and you should change those to actual credentials for you PostgreSQL user.

You should also modify url and host and set them to your device.

Example of Post request to send:

{
  "info": {
    "_postman_id": "56ff6dea-0cd1-40b3-80ef-8a7426935ede",
    "name": "IoTool",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "_exporter_id": "4611963"
  },
  "item": [
    {
      "name": "iotool_v3_savedata",
      "request": {
        "method": "POST",
        "header": [],
        "body": {
          "mode": "urlencoded",
          "urlencoded": [
            {
              "key": "un",
              "value": "username",
              "type": "text"
            },
            {
              "key": "up",
              "value": "password",
              "type": "text"
            },
            {
              "key": "db",
              "value": "localhost",
              "type": "text"
            },
            {
              "key": "sensorcount",
              "value": "1",
              "type": "text"
            },
            {
              "key": "db0",
              "value": "senzor1",
              "type": "text"
            },
            {
              "key": "data0",
              "value": ",1#,2#,3",
              "type": "text"
            }
          ]
        },
        "url": {
          "raw": "http://dev.sandbox.engineering:1880/android/iotool_v3_savedata",
          "protocol": "http",
          "host": [
            "dev.sandbox.engineering"
          ],
          "port": "1880",
          "path": [
            "android",
            "iotool_v3_savedata"
          ]
        }
      },
      "response": []
    }
  ]
}

PostgreSQL user login

Purpose

Section in flow that is used for issuing query to database and logging in user, for this purpose reusable node flow is used, this flow is defined in another file named iotool_v1_funct. Shortly this flow/function sets parameter pgConfig object inside msg object, pgConfig includes information about login credentials and database location.

Try to Get Sensor ID

This subflow implements a straightforward SQL search algorithm to retrieve the sensor ID, which is then passed along in the msg object. This ID is a key component in fetching additional data from the database.

Merging Data and HTTP Response

In this section, incoming data is consolidated using a Function node, which formats the sensor data into a string and tallies the processed entries. Should existing data be present, this segment appends the new information, updates the entry count, and flags the presence of data if any records are found. The amalgamated data is subsequently relayed back to the POST request’s sender via an HTTP response subflow.

Overview

This workflow facilitates the retrieval of data from a PostgreSQL database, contingent upon input parameters. It dynamically generates SQL queries to match the criteria outlined in the POST request, ensuring a tailored data extraction process. An HTTP response is issued to the requester as a confirmation of the operation’s success.