Hey everyone,
i'm new to this so i will try to get it as detailed as possible.
I have a PV inverter with a smart meter so the inverter can track the needs of energy. Because it's not easy to get the Data directly from the Inverter I thought about sniffing the Data from the Modbus RTU connection and process them. So I did code a program for an Arduino R3 with which I could sniff all the data I wanted. I know the address of the message so I can look up if it's a request or an answer and if I check how long the answer is, I can cut the Data where I want it to.
#include <SPI.h>
#include <MsTimer2.h>
#include <stdlib.h>
#include <Wire.h>
void loop() {
char received;
//get Data
if (Serial.available() > 0) {
received = Serial.read();
RecvBuffer[AnzMsg][recvIndex++] = received;
}
//length of the message
if (recvIndex == 4 & !anfrageData) {
Wert2 = (uint8_t)RecvBuffer[AnzMsg][2];
if (Wert2 <= 1) {
lengthofMsg[AnzMsg] = 8;
} else if (Wert2 > 1) {
lengthofMsg[AnzMsg] = (uint16_t)Wert2 + 5;
}
anfrageData = true;
// reinitialize vars for next detection/dump
dumpData = false;
MsTimer2::stop();
timerStarted = false;
}
//do some stuff
}
But because I wanted to get some relays and other stuff running I thought about switching to the OPTA and had there I didn't get this code runnign so I tried to switch to the code from the example and wanted to change that, but my knowledge with the libareys are too small. I can get the OPTA to request data from the Smart Meter and to read the Data which comes back with something like:
float getT_Float(int dev_address, int base_reg) {
int l;
l = ModbusRTUClient.requestFrom(dev_address, INPUT_REGISTERS, base_reg - 30001, 2);
if (l > 0) {
while (!ModbusRTUClient.available()) {}
uint32_t rawreg = ModbusRTUClient.read() << 16 | ModbusRTUClient.read();
float reg;
memcpy(®, &rawreg, sizeof(float));
return reg;
} else {
return 0;
}
}
But because the inverter is requesting all the time I can't do that. I don't know how I can only read everything that will be sent on the Modbus RTU libary for OPTA.
Greeting
Simon