npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ya-modbus/driver-xymd1

v0.4.4

Published

XYMD1 Temperature and Humidity Sensor driver for ya-modbus

Downloads

435

Readme

@ya-modbus/driver-xymd1

XYMD1 Temperature and Humidity Sensor driver for ya-modbus.

Device Information

  • Model: XY-MD1
  • Type: Temperature and Humidity Sensor
  • Communication: Modbus RTU
  • Default Settings:
    • Address: 1
    • Baud rate: 9600
    • Parity: Even
    • Stop bits: 1
    • Data bits: 8

Installation

npm install @ya-modbus/driver-xymd1

Usage

import { createDriver } from '@ya-modbus/driver-xymd1'
import { ModbusRTU } from '@ya-modbus/transport-rtu'

// Create transport
const transport = new ModbusRTU({
  path: '/dev/ttyUSB0',
  baudRate: 9600,
  parity: 'even',
})

// Create driver
const driver = await createDriver({
  transport,
  slaveId: 1,
})

// Read temperature and humidity
const values = await driver.readDataPoints(['temperature', 'humidity'])
console.log(values)
// { temperature: 24.5, humidity: 65.2 }

// Read current device configuration
const currentAddress = await driver.readDataPoint('device_address')
const currentBaudRate = await driver.readDataPoint('baud_rate')
console.log(`Current config: address=${currentAddress}, baudRate=${currentBaudRate}`)

// Configure device address (requires device restart to take effect)
await driver.writeDataPoint('device_address', 5)

// Configure baud rate (requires device restart to take effect)
await driver.writeDataPoint('baud_rate', 19200)

// Calibrate sensor (applied immediately)
await driver.writeDataPoint('temperature_correction', -1.5)
await driver.writeDataPoint('humidity_correction', 2.0)

Using Default Configuration

The driver exports a DEFAULT_CONFIG constant with factory-default device settings:

import { createDriver, DEFAULT_CONFIG } from '@ya-modbus/driver-xymd1'
import { ModbusRTU } from '@ya-modbus/transport-rtu'

// Use default configuration for connecting to factory-default device
const transport = new ModbusRTU({
  path: '/dev/ttyUSB0',
  baudRate: DEFAULT_CONFIG.baudRate, // 9600
  parity: DEFAULT_CONFIG.parity, // 'even'
  dataBits: DEFAULT_CONFIG.dataBits, // 8
  stopBits: DEFAULT_CONFIG.stopBits, // 1
})

const driver = await createDriver({
  transport,
  slaveId: DEFAULT_CONFIG.defaultAddress, // 1
})

This ensures your code always uses the correct factory defaults and makes it easier to update if device specifications change.

Data Points

| ID | Name | Type | Unit | Access | Description | | ------------------------ | ---------------------- | ------- | ---- | ---------- | ------------------------------------------------------------------------------------------ | | temperature | Temperature | float | °C | Read-only | Temperature in degrees Celsius | | humidity | Relative Humidity | float | % | Read-only | Relative humidity percentage (0-100%) | | device_address | Device Address | integer | - | Read-write | Modbus device address (1-247). Changes applied after device restart. | | baud_rate | Baud Rate | enum | - | Read-write | Serial communication baud rate (9600, 14400, 19200). Changes applied after device restart. | | temperature_correction | Temperature Correction | float | °C | Read-write | Temperature correction offset (-10.0 to +10.0°C). Applied immediately. | | humidity_correction | Humidity Correction | float | % | Read-write | Humidity correction offset (-10.0 to +10.0%RH). Applied immediately. |

Register Mapping

| Function | Register | Type | Format | Description | | ------------- | -------- | ------- | --------------- | ------------------------------------------ | | Read | 1-2 | Input | 16-bit × 2 | Temperature and humidity (×10) | | Configuration | 0x101 | Holding | 16-bit unsigned | Device address (1-247) | | Configuration | 0x102 | Holding | 16-bit unsigned | Baud rate setting | | Calibration | 0x103 | Holding | 16-bit signed | Temperature correction (×10, -100 to +100) | | Calibration | 0x104 | Holding | 16-bit signed | Humidity correction (×10, -100 to +100) |

Calibration

The XYMD01 supports temperature and humidity correction to calibrate sensor readings against reference measurements.

Using the Driver API

// Example: Calibrate temperature
// 1. Measure actual temperature with reference device: 23.0°C
// 2. Read XYMD01 sensor: 25.5°C
// 3. Calculate correction: 23.0 - 25.5 = -2.5°C

await driver.writeDataPoint('temperature_correction', -2.5)

// Verify corrected reading
const temp = await driver.readDataPoint('temperature')
// temp should now be approximately 23.0°C

// Example: Calibrate humidity
await driver.writeDataPoint('humidity_correction', 1.5)

Using the CLI

# Set temperature correction
ya-modbus write \
  --port /dev/ttyUSB0 \
  --slave-id 1 \
  --data-point temperature_correction \
  --value -2.5 \
  --yes \
  --verify

# Set humidity correction
ya-modbus write \
  --port /dev/ttyUSB0 \
  --slave-id 1 \
  --data-point humidity_correction \
  --value 1.5 \
  --yes \
  --verify

# Read all values including corrections
ya-modbus read \
  --port /dev/ttyUSB0 \
  --slave-id 1 \
  --all

Notes

  • Corrections are applied immediately (no device restart required)
  • Values are stored in device holding registers and persist across power cycles
  • Correction range: -10.0 to +10.0 for both temperature (°C) and humidity (%RH)
  • The corrected values are reflected in the temperature and humidity input registers

License

GPL-3.0-or-later