OPC UA to CSV Data Logger using JavaScript

OPC UA CSV Data Logger

This project logs OPC UA tag data to daily CSV files, organized by year and month folders. It does not use MySQL or SQLite.

Features

  • Connects to an OPC UA server
  • Reads tag definitions from a CSV file
  • Logs data to CSV files only when tag values change
  • Creates daily CSV files in a folder structure: csvFolder/year/month/day.csv
  • Automatically reconnects to OPC UA server if connection/session is lost
  • Handles CSV file write errors (e.g., file open/locked)

Configuration

Edit config.json to set:

  • opcuaEndpoint: OPC UA server endpoint
  • opcuaUsername / opcuaPassword: credentials
  • pollIntervalMs: polling interval in milliseconds
  • tagsCsvFile: path to tag CSV file
  • csvFolder: base folder for CSV logs (default: csv_data)

Usage

  1. Install dependencies:
     npm install
    
  2. Edit config.json as needed
  3. Run:
     node server.js
    

Tag CSV Format

name,nodeId
Tag1,ns=2;s=Tag1
Tag2,ns=2;s=Tag2

CSV Output Structure

CSV files are created in csvFolder with the following structure:

csvFolder/
   2025/
      09/
         04.csv
         05.csv
      10/
         ...

Each CSV file contains:

timestamp,name,value
2025-09-04T10:00:00.000Z,Tag1,123
2025-09-04T10:01:00.000Z,Tag1,124
...

Error Handling

  • If a CSV file is open/locked and cannot be written, an error is logged and the affected data is skipped (not buffered or retried).
  • Only one error message is logged for repeated connection failures; retries happen in the background every 5 seconds with exponential backoff.

34.03$

SKU 95 Categories ,

Your Automation Partner. Streamline workflows, and drive productivity. Explore our innovative solutions.