emelianov / XY-MD02

XY-MD02 Modbus tools for ESP32
MIT License
1 stars 0 forks source link

XY-MD02 Modbus tools for ESP32

As ModbusRTU data exchange is slow process (especially in case if device not responding) main idea is to use didicated background task that periodically executes data read requsts from XY-MD02 devices. Main task have ability quickly get last values and time when they was received.

http://sahel.rs/media/sah/techdocs/xy-md02-manual.pdf

Prerequirements

https://github.com/emelianov/modbus-esp8266

API

bool xy_modbus(HardwareSerial s, int16_t pin = -1);

Initialize the library. Should be called prior other library calls.

Returns: true on success

bool xy_read_ms(uint32_t interval = 0);

Set delay between data read sessions.

Returns: true on success

xy_parms xy_get(uint8_t i);

Returns last avaiolable data fot the specific device.

Returns: xy_parms structure of filled by the device data.

int16_t xy_add(uint8_t slave);

Adds the device. slave Slave ID of the device to add

Returns: Device position that should be used for xy_get() or -1 on error.

typedef struct xy_parms {
    uint8_t slave_id = 0;   // Set on creation
    uint32_t lastSuccess = 0;// Set each as current millis() time got data from the device
    uint16_t T = 0;         // Temperature
    uint16_t H = 0;         // Humodity
} xy_parms;

(c)2021 Alexander Emelianov (a.m.emelianov@gmail.com)

https://github.com/emelianov/XY-MD02