I need help figuring out what I'm doing wrong. I can access all the registers except for the ones related to power generation statistics. Specifically, I'm having trouble getting those registers to work. Can anyone guide me in the right direction?
A or BSeriesControllerProtocolv2.6.pdf (716.1 KB)
#include <ModbusMaster.h>
#define MAX485_DE 26
#define MAX485_RE_NEG 25
ModbusMaster node;
uint16_t energyTodayL;
uint16_t energyTodayH;
uint32_t energyToday;
void preTransmission()
{
digitalWrite(MAX485_RE_NEG, 1);
digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
}
void setup() {
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
Serial2.begin(115200);
Serial.begin(9600);
// ...
node.begin(1, Serial2);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop() {
ArduinoCloud.update();
uint8_t result = node.readInputRegisters(0x3100, 11);
if (result == node.ku8MBSuccess) {
// ePbatterycurrent2 = (node.getResponseBuffer(0x05) / 100.0f);
// ePPVcurrent2 = (node.getResponseBuffer(0x01) / 100.0f) ;
// ePPVvoltage2 = (node.getResponseBuffer(0x00) / 100.0f);
// ePvatteryvoltage2 = (node.getResponseBuffer(0x04) / 100.0f) ;
Serial.print("PV array voltage : ");
Serial.println(node.getResponseBuffer(0x00) / 100.0f);
Serial.print("PV array current : ");
Serial.println(node.getResponseBuffer(0x01) / 100.0f);
Serial.print("PV array power : ");
Serial.println(node.getResponseBuffer(0x02) / 100.0f);
Serial.print("Battery voltage : ");
Serial.println(node.getResponseBuffer(0x04) / 100.0f);
Serial.print("Battery charging current : ");
Serial.println(node.getResponseBuffer(0x05) / 100.0f);
Serial.print("Battery charging power : ");
Serial.println(node.getResponseBuffer(0x06) / 100.0f);
Serial.print("Load voltage : ");
Serial.println(node.getResponseBuffer(0x0C) / 100.0f);
Serial.print("Load current : ");
Serial.println(node.getResponseBuffer(0x0D) / 100.0f);
Serial.print("Load power : ");
Serial.println(node.getResponseBuffer(0x0E) / 100.0f);
Serial.print("Battery SOC : ");
Serial.println(node.getResponseBuffer(0x311A) / 1.0f);
Serial.print("Remote battery temperature : ");
Serial.println(node.getResponseBuffer(0x10) / 100.0f);
Serial.println("==========================");
uint8_t result2 = node.readInputRegisters(0x3300, 7);
energyTodayL = node.getResponseBuffer(0x330C);
energyTodayH = node.getResponseBuffer(0x330D);
energyToday = (energyTodayH << 16) | energyTodayL;
//maxBV = (node.getResponseBuffer(0x02) / 100.0f);
// maxPV = (node.getResponseBuffer(0x00) / 100.0f);
// minBV = (node.getResponseBuffer(0x03) / 100.0f);
// minPV = (node.getResponseBuffer(0x01) / 100.0f);
// genEnergytoday = (node.getResponseBuffer(0x0C) / 100.0f);
Serial.print("Maximum PV voltage today: ");
Serial.println(node.getResponseBuffer(0x00) / 100.0f);
Serial.print("Minimum PV voltage today: ");
Serial.println(node.getResponseBuffer(0x01) / 100.0f);
Serial.print("Maximum battery voltage today: ");
Serial.println(node.getResponseBuffer(0x02) / 100.0f);
Serial.print("Minimum battery voltage today: ");
Serial.println(node.getResponseBuffer(0x03) / 100.0f);
Serial.print("Generated energy today: ");
Serial.println(energyToday / 100.0f);
} else {
Serial.println("Failed to read from Modbus device.");
}
delay(1000);
}