Pecos includes basic data acquisition methods to transfer data from sensors to an SQL database. These methods require the Python packages sqlalchemy (https://www.sqlalchemy.org/) and minimalmodbus (https://minimalmodbus.readthedocs.io).
Device to client¶
device_to_client method collects data from a modbus device and stores it in a local
The method requires several configuration options, which are stored as a nested dictionary.
pyyaml can be used to store configuration options in a file.
The options are stored in a Client block and a Devices block.
The Devices block can define multiple devices and each device can have multiple data streams.
The configuration options are described below.
Client: A dictionary that contains information about the client. The dictionary has the following keys:
IP: IP address (string)
Database: name of database (string)
Table: name of table (string)
Username: name of user (string)
Password: password for user (string)
Interval: data collection frequency in seconds (integer)
Retries: number of retries for each channel (integer)
Devices: A list of dictionaries that contain information about each device (one dictionary per device). Each dictionary has the following keys:
Name: modbus device name (string)
USB: serial connection (string) e.g. /dev/ttyUSB0 for linux
Address: modbus slave address (string)
Baud: data transfer rate in bits per second (integer)
Parity: parity of transmitted data for error checking (string). Possible values: N, E, O
Bytes: number of data bits (integer)
Stopbits: number of stop bits (integer)
Timeout: read timeout value in seconds (integer)
Data: A list of dictionaries that contain information about each data stream (one dictionary per data stream). Each dictionary has the following keys:
Name: data name (string)
Type: data type (string)
Scale: scaling factor (integer)
Conversion: conversion factor (float)
Channel: register number (integer)
Signed: define data as unsigned or signed (bool)
Fcode: modbus function code (integer). Possible values: 3,4
Example configuration options are shown below.
Client: IP: 127.0.0.1 Database: db_name Table: table_name Username: username Password: password Interval: 1 Retries: 2 Devices: - Name: Device1 USB: /dev/ttyUSB0 Address: 21 Baud: 9600 Parity: N Bytes: 8 Stopbits: 1 Timeout: 0.05 Data: - Name: AmbientTemp Type: Temp Scale: 1 Conversion: 1.0 Channel: 0 Signed: True Fcode: 4 - Name: DC Power Type: Power Scale: 1 Conversion: 1.0 Channel: 1 Signed: True Fcode: 4