IoTool Data, Sensor Data and Sensor Files

Introduction

This document consolidates the workflows related to data management within the IoTool framework, specifically designed for interactions with a PostgreSQL database. It includes three distinct operations, each tailored to handle incoming data from IoT devices through various stages of processing:

  • IoTool v3 Data: Focuses on processing incoming data and interacting with the PostgreSQL database for storage and retrieval, emphasizing data transformation and response management.

  • IoTool v1 Sensor Data: Similar to the IoTool v3 Data flow, this operation is designed to handle sensor data, including structuring the data for PostgreSQL interaction and managing HTTP POST requests.

  • IoTool v1 Sensor Files: Concentrates on handling sensor file data, with particular attention to database interactions and data structuring for retrieval and storage.

These operations demonstrate the integration of custom Node-RED functions, PostgreSQL database querying, and comprehensive error handling and response mechanisms.

Common Components and Processes

Handling HTTP POST Requests

Each flow initiates by receiving data through a POST request to a specified endpoint. These requests are structured to include necessary information for database operations, such as PostgreSQL username and password, sensor data, and potentially timestamps for data retrieval.

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_data",
      "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"
            },
            {
              "key": "mt0",
              "value": "senzor1",
              "type": "text"
            },
            {
              "key": "start",
              "value": "0",
              "type": "text"
            },
            {
              "key": "stop",
              "value": "10000000000",
              "type": "text"
            }
          ]
        },
        "url": {
          "raw": "http://dev.sandbox.engineering:1880/android/iotool_v3_data",
          "protocol": "http",
          "host": [
            "test.sandbox.engineering"
          ],
          "port": "1880",
          "path": [
            "android",
            "iotool_v3_data"
          ]
        }
      },
      "response": []
    }
  ]
}

PostgreSQL User Authentication

A reusable Node-RED node, often defined in external files like iotool_v1_funct, is utilized across all flows for user authentication against the PostgreSQL database. This setup involves configuring a pgConfig object within the Node-RED message payload to include login credentials and database location.

Data Retrieval from Database

The core functionality of these flows involves constructing dynamic SQL queries to retrieve relevant sensor data or file information from the database, based on the parameters provided in the POST request.

Data Aggregation and HTTP Response Management

Incoming data is processed and aggregated into a coherent format, which is then returned to the request initiator through an HTTP response. This process includes tallying entries, merging new data with existing records if applicable, and ensuring the response accurately reflects the operation’s outcome.

Unique Aspects of Each Flow

  • IoTool v3 Data: Emphasizes the transformation of incoming sensor data and the construction of SQL queries for data retrieval, with a strong focus on response management based on data availability.

  • IoTool v1 Sensor Data: Shares similarities with the IoTool v3 Data flow but may include specific configurations for handling sensor data, particularly in structuring POST requests and managing database interactions.

  • IoTool v1 Sensor Files: Distinguished by its focus on sensor file data, this flow potentially involves additional steps or configurations for handling file-based data, including retrieval and storage processes tailored to file data management.

Main difference between all 3 examples comes from the Function node named Merge data to string. Which merges retreived data from database into string and formats it into HTML code, so it can be sent back as response to incoming request.

Conclusion

This unified documentation provides an overview of the IoTool data management flows, highlighting their shared foundations in handling HTTP POST requests, PostgreSQL database interactions, and dynamic SQL query generation. By understanding the specific functionalities and configurations of these flows, users can effectively utilize the IoTool suite for diverse data management tasks within IoT applications.