@mfalkvidd
Thank you so much Finnaly it is working as it should do!
#define MY_DEBUG
#define MY_RS485
#define MY_RS485_DE_PIN 2
#define MY_RS485_BAUD_RATE 19200
#define MY_RS485_HWSERIAL Serial
#define MY_NODE_ID 3
#include <AltSoftSerial.h>
#include <SPI.h>
#include <MySensors.h>
AltSoftSerial altSerial;
int msg[1];
const uint64_t pipe = 0xE8E8F0F0E1LL;
const int requestPin = 4;
char input; // incoming serial data (byte)
bool readnextLine = false;
#define BUFSIZE 500
#define CHILD_ID_WATT 0
#define CHILD_ID_KWH_LOW 1
#define CHILD_ID_KWH_HIGH 2
#define CHILD_ID_GAS 3
#define CHILD_ID_CURRENT 4
char buffer[BUFSIZE]; //Buffer for serial data to find \n .
int bufpos = 0;
long mEVLT = 0; //Meter reading Electrics - consumption low tariff
long mEVHT = 0; //Meter reading Electrics - consumption high tariff
long mEAV = 0; //Meter reading Electrics - Actual consumption
long mEAT = 0; //Meter reading Electrics - Actual generated electricity (Solar panels)
long mG = 0; //Meter reading Gas
MyMessage msgWatt(CHILD_ID_WATT, V_WATT);
MyMessage msgKwhLow(CHILD_ID_KWH_LOW, V_KWH); //Was V_KWH
MyMessage msgKwhHigh(CHILD_ID_KWH_HIGH, V_KWH); //Was V_KWH
MyMessage msgGas(CHILD_ID_GAS, V_VOLUME);
void setup() {
// Serial.begin(19200);
// delay(1000);
altSerial.begin(9600);
delay(1000);
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Node", "1.0");
present(CHILD_ID_WATT, S_POWER);
present(CHILD_ID_KWH_LOW, S_POWER);
present(CHILD_ID_KWH_HIGH, S_POWER);
present(CHILD_ID_GAS, S_GAS);
}
void loop() {
long tl = 0;
long tld =0;
if (altSerial.available()) {
char input = altSerial.read();
buffer[bufpos] = input&127;
bufpos++;
if (input == '\n') { // We received a new line (data up to \n)
// 1-0:1.8.2 = Electricity consumption high tariff (DSMR v4.0)
if (sscanf(buffer,"1-0:1.8.2(%ld.%ld" , &tl, &tld) >0 ) {
tl *= 1000;
tl += tld;
mEVHT = tl;
//mEVHT = tl * 1000 + tld;
if (mEVHT > 0) {
//mEVHT = 0;
}
}
if (sscanf(buffer,"1-0:1.8.1(%ld.%ld" ,&tl, &tld)==2){
tl *= 1000;
tl += tld;
mEVLT = tl;
if (mEVLT > 0) {
}
}
// 1-0:1.7.0 = Electricity consumption actual usage (DSMR v4.0)
if (sscanf(buffer,"1-0:1.7.0(%ld.%ld" ,&tl , &tld) == 2)
{
mEAV = (tl*1000)+tld*10;
if (mEAV > 0) {
}
}
//Gastand uitlezen
if (sscanf(buffer,"(%ld.%ld" , &tl, &tld)==2 )
{ mG = (tl*1000.0)+tld;
mG = mG;
}
// Empty buffer again (whole array)
for (int i=0; i<500; i++)
{
buffer[i] = 0;
}
bufpos = 0;
}
if (input == '!') { //uitroepteken geeft einde van telegram aan, dus we gaan data versturen
#ifdef DEBUG
printData();
#endif
send(msgWatt.set(mEAV));
send(msgKwhLow.set(mEVLT / 1000.0, 3));
send(msgKwhHigh.set(mEVHT / 1000.0, 3));
send(msgGas.set(mG / 1000.0, 3));
mEVHT=0;
mEVLT = 0;
mEAV = 0;
mG = 0;
//client.stop();
} //Einde vraagteken detectie
}
}
And here an picture how it is showing up in domoticz: