bg

How to Log Weight Scale or Balance to MySQL Database

A complete guide to polling weight scale serial devices and exporting the extracted data directly into a MySQL database.

1. Protocol Configuration: RS232 Weight Scale

Communication Type: Passive Listening (Continuous or Print-on-Demand)

Most industrial scales send ASCII strings terminated by a Carriage Return (CR) and Line Feed (LF). Use the software's 'ASCII Data Parser' module and set the data packet signature to ending characters '#0D#0A'. You can then extract the numeric weight by specifying fixed column positions or using a regular expression. Furthermore, the logger contains pre-defined parsers for the most popular scales.

Apply this base configuration for the serial connection:

{
  "port": "COM1",
  "baud_rate": 9600,
  "data_bits": 8,
  "stop_bits": 1,
  "parity": "none",
  "flow_control": "hardware",
  "packet_end": "#0D#0A"
}
Weight scales and balanced plugin selection to poll a device and parse incoming data.

Weight scales and balanced plugin selection to poll a device and parse incoming data.

Weight scales and balanced plugin configuration: weight scale type and polling interval.

Weight scales and balanced plugin configuration: weight scale type and polling interval.

Ready to connect RS232 Weight Scale to MySQL?

2. Database Setup: MySQL

You will need the MySQL Connector/ODBC installed on the machine running the Data Logger. Create a System DSN pointing to your MySQL server instance.

Use the following SQL script to create your target table. We recommend using the InnoDB engine to handle high-frequency concurrent inserts without table locking.

CREATE TABLE sensor_data (
  id INT AUTO_INCREMENT PRIMARY KEY,
  log_timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
  device_id VARCHAR(50),
  register_value FLOAT
) ENGINE=InnoDB;
MySQL plugin to export data.

MySQL plugin to export data.

MySQL database connection settings.

MySQL database connection settings.

INSERT SQL statements in a queue with custom parameters.

INSERT SQL statements in a queue with custom parameters.

3. Protocol-Specific Troubleshooting

  • Garbage characters appearing on the screen: This almost always indicates a baud rate or parity mismatch. 9600-8-N-1 is standard, but older Mettler Toledo or Ohaus scales frequently use 2400 baud or 7-Even-1 parity. Check the hardware manual.
  • Is it possible to process stable weight only and ignore intermediate values?: Use one of our filter plugins, and for example, ignore all records without the "stable" signature in a data packet.
  • Is it possible to process weight values greater that 100.0 kg?: The Expressions filter plugin allows you to using any math expression For example, the following command: DISCARD_DATA_PACKET_IF(WEIGHT < 100).

4. Database-Specific Troubleshooting

  • MySQL server has gone away: If your serial device is idle overnight, MySQL will drop the connection. Enable the 'Keep connection alive' setting in the Data Logger's ODBC export module.
  • How can I insert or update a data row for my device?: You can use any SQL query in our 'SQL Database Pro' plugin. In MySQL, you can easily execute the following SQL: 'INSERT INTO ....... ON DUBLICATE KEY .... UPDATE ....'.
  • I want to write data from each of my devices to a different table. How can I do it?: In the 'SQL Database Pro' plugin, you can use a placeholder in your SQL. For example, 'INSERT INTO SerialData%DEVICE_ID% (....)'. Before executing SQL, the logger replaces %DEVICE_ID% with the corresponding value from parsed data, and the real destination table will vary (SerialData1, SerialData2, etc.).

Ready to connect RS232 Weight Scale to MySQL?

Product Buy Download Support Contacts Site map
Copyright © 1999 - 2026, AGG Software.
All rights reserved.. Terms of use | Privacy policy