I've successfully setup an ESP32S2 Saola board with eModbus (https://emodbus.github.io), so I know for sure that there are no hardware issues and the values shown in the power meter's display match what I'm seeing over the Modbus-RTU twisted pair, see this thread for in-depth details on how I got the hardware up and running w/ Arduino:
https://github.com/eModbus/eModbus/discussions/166
Working with Arduino first:
Code: Select all
// Relevant holding registers and example values:
//
// 0011: 0.193 <--- Amps panel 1
// 0013: 0.258 <--- Amps panel 2
// 0015: 0.210 <--- Amps panel 3
// 0017: 219.600 <--- W total
// 0019: 57.200 <--- var total
// 0039: 105.200 <--- VA total
// 0041: 236.550 <--- Volts panel 1
// 0043: 236.580 <--- Volts panel 2
// 0045: 236.480 <--- Volts panel 3
// 001B: 0.828 <--- PF
// 001D: 49.951 <--- Hz
// 001F: 0.000 <--- uh
// 0021: 0.070 <--- -uh
// 0023: 0.000 <--- uAh
// 0025: 0.030 <--- -uAh
Code: Select all
const mb_parameter_descriptor_t device_parameters[] = {
// { CID, Param Name, Units, Modbus Slave Addr, Modbus Reg Type, Reg Start, Reg Size, Instance Offset, Data Type, Data Size, Parameter Options, Access Mode}
{ CID_HOLD_DATA_0, STR("Amps_phase_1"), STR("A"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0x11, 2,
HOLD_OFFSET(holding_data0), PARAM_TYPE_FLOAT, 4, OPTS( 0, 5000, .001 ), PAR_PERMS_READ },
{ CID_HOLD_DATA_1, STR("Amps_phase_2"), STR("A"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0x13, 2,
HOLD_OFFSET(holding_data1), PARAM_TYPE_FLOAT, 4, OPTS( 0, 5000, .001 ), PAR_PERMS_READ },
{ CID_HOLD_DATA_2, STR("Amps_phase_3"), STR("A"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0x15, 2,
HOLD_OFFSET(holding_data2), PARAM_TYPE_FLOAT, 4, OPTS( 0, 5000, .001 ), PAR_PERMS_READ },
{ CID_HOLD_DATA_3, STR("Watts"), STR("W"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0x17, 2,
HOLD_OFFSET(holding_data3), PARAM_TYPE_FLOAT, 4, OPTS( 0, 5000, .001 ), PAR_PERMS_READ },
{ CID_HOLD_DATA_4, STR("var"), STR("W"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0x19, 2,
HOLD_OFFSET(holding_data4), PARAM_TYPE_FLOAT, 4, OPTS( 0, 5000, .001 ), PAR_PERMS_READ },
{ CID_HOLD_DATA_5, STR("VA"), STR("VA"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0x39, 2,
HOLD_OFFSET(holding_data5), PARAM_TYPE_FLOAT, 4, OPTS( 0, 400, .001 ), PAR_PERMS_READ },
{ CID_HOLD_DATA_6, STR("Volts_phase_1"), STR("V"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0x41, 2,
HOLD_OFFSET(holding_data6), PARAM_TYPE_FLOAT, 4, OPTS( 0, 400, .001 ), PAR_PERMS_READ },
{ CID_HOLD_DATA_7, STR("Volts_phase_2"), STR("V"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0x43, 2,
HOLD_OFFSET(holding_data7), PARAM_TYPE_FLOAT, 4, OPTS( 0, 400, .001 ), PAR_PERMS_READ },
{ CID_HOLD_DATA_8, STR("Volts_phase_3"), STR("V"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0x45, 2,
HOLD_OFFSET(holding_data8), PARAM_TYPE_FLOAT, 4, OPTS( 0, 400, .001 ), PAR_PERMS_READ },
{ CID_HOLD_DATA_9, STR("PF"), STR(""), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0x1B, 2,
HOLD_OFFSET(holding_data9), PARAM_TYPE_FLOAT, 4, OPTS( 0, 1, .001 ), PAR_PERMS_READ },
{ CID_HOLD_DATA_10, STR("Hz"), STR("Hz"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0x1D, 2,
HOLD_OFFSET(holding_data10), PARAM_TYPE_FLOAT, 4, OPTS( 0, 60, .001 ), PAR_PERMS_READ },
{ CID_HOLD_DATA_11, STR("uh"), STR("Wh"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0x1F, 2,
HOLD_OFFSET(holding_data11), PARAM_TYPE_FLOAT, 4, OPTS( 0, 10000, .001 ), PAR_PERMS_READ },
{ CID_HOLD_DATA_12, STR("-uh"), STR("Wh"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0x21, 2,
HOLD_OFFSET(holding_data12), PARAM_TYPE_FLOAT, 4, OPTS( 0, 10000, .001 ), PAR_PERMS_READ },
{ CID_HOLD_DATA_13, STR("uAh"), STR("Wh"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0x23, 2,
HOLD_OFFSET(holding_data13), PARAM_TYPE_FLOAT, 4, OPTS( 0, 10000, .001 ), PAR_PERMS_READ },
{ CID_HOLD_DATA_14, STR("-uAh"), STR("Wh"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0x25, 2,
HOLD_OFFSET(holding_data14), PARAM_TYPE_FLOAT, 4, OPTS( 0, 1000, .001 ), PAR_PERMS_READ },
};
https://github.com/brainstorm/yigedianq ... -rainmaker
Unfortunately I'm getting non stable and completely out of range values out of the code above, see the output logs from the serial dongle:
https://hardbin.com/ipfs/QmX8d9wYPyV51k ... z5ZpH2jUrq
For instance, in TL;DR form:
I (4202) app_modbus: Characteristic #0 Amps_phase_1 (A) value = -0.000000 (0xa2343fb4) read successful.
I (7142) app_modbus: Characteristic #0 Amps_phase_1 (A) value = 9896461401915671303770759400200863744.000000 (0x7cee3fa7) read successful.
I (10082) app_modbus: Characteristic #0 Amps_phase_1 (A) value = 41405882368.000000 (0x511a3fba) read successful.
So I suspect this is a case of not properly initialized variables or registers? Perhaps timing or race condition issues? Incorrect type casting?
Other than reviewing other user's ESP-IDF Modbus repo (solved) issues and this Forum's posts, I've noticed that Alex Lisitsyn (https://github.com/alisitsyn) has been extremely helpful troubleshooting other user's issues. I hope this post gets noticed by him or somebody else so that I get to finish up this project properly