reaper7 / SDM_Energy_Meter

reading SDM72 SDM120 SDM220 SDM230 SDM630 modbus energy meters from arduino (esp8266, esp32, avr)
240 stars 97 forks source link

Multi meters sdm120c #10

Closed mariusz84pl closed 7 years ago

mariusz84pl commented 7 years ago

Is sdm120.h library configured to read more then 1 meter? Cant find in library anything about this. I have 4 sdm120c meters and i want to read values from all of them but it reads only from meter with id1.

reaper7 commented 7 years ago

this lib (at this moment) is configured to read only one meter: https://github.com/reaper7/SDM_Energy_Meter/blob/master/SDM.h#L32

I can't test for more slave devices because I have only one :)

...but I commit little mod for test: try to use readVal with two parameters, first -> register to read, and second(addotional) -> node Id for eg.:

readVal(SDM220T_VOLTAGE, 0x01) //read voltage from node 1
readVal(SDM220T_VOLTAGE, 0x02) //read voltage from node 2

remember, all devices must be set with the same parameters like baudrate, parity etc except Id, which must be different for each device.

Please report after Your tests

mariusz84pl commented 7 years ago

Had to make some changes in SDM.h library because this

readVal(SDM220T_VOLTAGE, 0x01) //read voltage from node 1

didnt want to work. Right now i have 4 meters and testing it but im geting few errors with value nan. In 4464 lines i have 15 "nan" values. Any advice what can i do to avoid them and get all reads correct?

In this lib https://github.com/reaper7/SDM_Energy_Meter/blob/master/SDM.h

added/changed: https://github.com/reaper7/SDM_Energy_Meter/blob/master/SDM.h#L163

float readVal(uint16_t reg, uint8_t node){

so i can now in sketch write

sdm.readVal(SDM220T_REACTIVE_APPARENT_POWER, 0x02)

from 0x01 to 0x04

reaper7 commented 7 years ago

please download full SDM.h file because changes are done in 3 places (not only in line 163 but 166 and 221 too). Look at changes: https://github.com/reaper7/SDM_Energy_Meter/commit/95efabf924b7472f671322a83543ad124b345e5f

For test I change my sdm dev id to 002 and it's works for me

mariusz84pl commented 7 years ago

When i use this full SDM.h without any changes im geting this errors while it compile

In file included from C:\Users\Mariusz\AppData\Local\Temp\arduino_modified_sketch_760893\sketch_jun16a.ino:23:0:
C:\Users\Mariusz\Documents\Arduino\libraries\sdm-reaper/SDM2.h: In member function 'float SDM<_speed, _rx_pin, _tx_pin, _dere_pin>::readVal(uint16_t, uint8_t)':
C:\Users\Mariusz\Documents\Arduino\libraries\sdm-reaper/SDM2.h:185:14: error: 'class SoftwareSerial' has no member named 'listen'
       sdmSer.listen();                                                          //enable softserial rx interrupt
              ^
C:\Users\Mariusz\Documents\Arduino\libraries\sdm-reaper/SDM2.h:244:14: error: 'class SoftwareSerial' has no member named 'end'
       sdmSer.end();                                                             //disable softserial rx interrupt
              ^
exit status 1
Błąd kompilacji dla płytki NodeMCU 1.0 (ESP-12E Module).

Should i use some outher SoftwareSerial lib then standard one?

when i comment in SDM.h this:

`#if !defined ( USE_HARDWARESERIAL ) sdmSer.listen(); //enable softserial rx interrupt

endif`

and this:

`#if !defined ( USE_HARDWARESERIAL ) sdmSer.end(); //disable softserial rx interrupt

endif`

then i can compile and upload sketch

And testing now how many "nan" values will i get.

reaper7 commented 7 years ago

I use this one swserial: https://github.com/plerup/espsoftwareserial

mariusz84pl commented 7 years ago

Ok changed this lib and uploaded sketch without errors so will see in 1 houer if there will by any nan values.

reaper7 commented 7 years ago

with swserial probably yes, I use hardwareserial

mariusz84pl commented 7 years ago

For 6768 lines in file with readings have 21 nan values. :/ a litlebit to much Any ideas besides rising delay in SDM.h?

How much errors do you have?

reaper7 commented 7 years ago

My suggestion for You is switch to hardware serial instead softwareserial

I do not have any errors sdm

reaper7 commented 7 years ago

Question about this "Issue" is: this lib now works for You config with multiple meters? If Yes please comment and close this "issue"

mariusz84pl commented 7 years ago

Yes this lib works now ok. Now only have to find out how to get rid of this errors.

mariusz84pl commented 6 years ago

Hi in SDM library what to change to get 3 digits after dot?

2017-06-18 19:19 GMT+02:00 reaper7 notifications@github.com:

Question about this "Issue" is: this lib works for You config with multiple meters? If Yes please comment and close this "issue"

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/reaper7/SDM_Energy_Meter/issues/10#issuecomment-309290559, or mute the thread https://github.com/notifications/unsubscribe-auth/AcH3d-qN58J8dRzZdxs5CdDMmt-REI34ks5sFVwsgaJpZM4N9SAN .

reaper7 commented 6 years ago

if you're talking about an sdm_simple example then simple remove or increase last value (in this case 2 decimal places): Serial.print(sdm.readVal(SDM220T_VOLTAGE), 2);

I do not think that the library itself limit the number of decimal places. SDM meters send reply as IEEE-754 float (32bits = 4bytes) and the library code also returns it without any changes or rounding