IoTool v1 Sensor Data

Introduction

The /android/iotool_v1_sensordata flow is designed to process incoming data, typically from IoT devices, and interact with a PostgreSQL database for data storage and retrieval. This flow handles data through a series of steps including data transformation, database interaction, and response management based on the presence or absence of data.

Flow Overview

This documentation outlines the key components and functionalities within the IoTool v1 Sensor Data, focusing on:

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

  2. PostgreSQL user login

  3. Retrieving sensor data from database

  4. Merging data to string and returning HTTP response to sender

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 timestamps. In this example you can modify fields start and stop to set times of measurments in which you want to display data. 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_v1_sensordata",
      "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_v1_sensordata",
          "protocol": "http",
          "host": [
            "test.sandbox.engineering"
          ],
          "port": "1880",
          "path": [
            "android",
            "iotool_v1_sensordata"
          ]
        }
      },
      "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.