gianfrdp / SDM120C

sdm120c ModBus Mini Smart Meter
GNU General Public License v2.0
73 stars 37 forks source link

sdm stuck /var/lock/LCK #9

Closed jeanmarc77 closed 2 years ago

jeanmarc77 commented 8 years ago

Hello, I use a script that infinitely call sdm120c (1.3.5.3) but it happen after several hours running that the application is stuck and leave the LCK file. Is it possible to have a max time execution that properly shutdown sdm ? thanks

jeanmarc77 commented 8 years ago

hi, I try with a "timeout 5s sdm120c" but it still happen : /

The-Drake commented 8 years ago

Normally sdm120c should clean up automatically stale locks. Have you sdm entries or hw error entries in syslog?

jeanmarc77 commented 8 years ago

When it happens, the sdm120c process is still running. I have to pkill it and manually remove the lock file. I haven't found any error on journalctl sorry. Am i alone that pool like a freak my meter ? ;)

The-Drake commented 8 years ago

No, you are not alone. ;) I tested sdm120c continuously polling my 4 meters + aurora from several parallel processes in a no delay loop on a single 485 bus for weeks without problems before releasing it, but I have an RPI v2 and probably a different adapter.

Let's try to log verbosely: use "-d2" flag and post latest stderr log before hung.

jeanmarc77 commented 8 years ago

Hi, Just got it once again, the process was stop this time but the lock file was in place :

[root@i3 ~]# ps -ef | grep sdm root 6519 1479 0 10:06 pts/1 00:00:00 grep sdm [root@i3 ~]# ls -al /var/lock/LCK..sdm -rw-r--r-- 1 root http 14 May 9 10:06 /var/lock/LCK..sdm

Nothing much informative on log : May 09 10:02:33 i3 sdm120c[20908]: Unable to get lock on serial /dev/sdm for 20908 in 0s: still locked by 20552. May 09 10:02:33 i3 sdm120c[20908]: sdm120c -a1 -d2 -b9600 -W5 -z3 -2 -qpievfg /dev/sdm May 09 10:02:33 i3 sdm120c[20908]: parent: timeout(20904) May 09 10:02:33 i3 sdm120c[20908]: sdm120c v1.3.5.3

If you run several devices on the same bus, maybe your meter have more time to "breath". Now i will pool sdm without daemon, it hang sometimes as well.

jeanmarc77 commented 8 years ago

Hello, I wonder if it's not an issue with my PHP version.. I still looking for details ;)

jeanmarc77 commented 8 years ago

Got stuck once again.. and nothing informative in journalctl with the -d2 :/

[root@i3 ~]# ps -ef | grep sdm root 20811 20810 0 19:39 ? 00:00:00 sdm120c -a1 -d2 -b9600 -2 -z3 -m -p /dev/sdm root 21891 21771 0 19:47 pts/0 00:00:00 grep sdm [root@i3 ~]# date Mon 16 May 19:47:29 CEST 2016 [root@i3 ~]# more /var/lock/LCK..sdm 20811 sdm120c [root@i3 ~]# pkill sdm120c [root@i3 ~]# ps -ef | grep sdm root 22248 21771 0 19:48 pts/0 00:00:00 grep sdm [root@i3 ~]# more /var/lock/LCK..sdm 20811 sdm120c [root@i3 ~]# rm /var/lock/LCK..sdm [root@i3 ~]# more /var/lock/LCK..sdm 22874 sdm120c

I didn't restart my PHP pooling, i just kill the sdm process but the lock file isn't removed though. Is it possible do change that ? Or check the lock file date before starting to remove older one ? Thanks

The-Drake commented 8 years ago

Hi jeanmarc, please try run something like this to capture log for last run:

sdm120c -a1 -d3 -b9600 -2 -z3 -j20 -w5 -m -p /dev/sdm 2> /tmp/lastlog.log

and cat /tmp/lastlog.log when it stops

or try to keep log of latest runs.

Actually if lockfile is "orphaned/stale" sdm should be able to resolve deadlock itself. BUT I think you should enable "wait for lock" with "-w5" even it won't wait at all. Forcing a problem should be simply as running sdm manually on another thread with PHP polling running.

Let me know.

jeanmarc77 commented 8 years ago

Hi Drake,

Ok i got it :

[root@i3 ~]# more /tmp/bug.log 20160519-15:57:41.978858: sdm120c(6316) cmdline="sdm120c -a1 -d3 -b9600 -2 -z3 -j20 -w5 -qpievfg /dev/sdm" 20160519-15:57:41.978908: sdm120c(6316) szttyDevice: /dev/sdm 20160519-15:57:41.978921: sdm120c(6316) devLCKfile: </var/lock/LCK..sdm> 20160519-15:57:41.978931: sdm120c(6316) devLCKfileNew: </var/lock/LCK..sdm.6316> 20160519-15:57:41.978941: sdm120c(6316) PID: 6316 20160519-15:57:41.978968: sdm120c(6316) Attempting to get lock on Serial Port /dev/sdm... 20160519-15:57:41.978989: sdm120c(6316) Acquiring shared lock on /var/lock/LCK..sdm... 20160519-15:57:41.979007: sdm120c(6316) Shared lock on /var/lock/LCK..sdm acquired... 20160519-15:57:41.979039: sdm120c(6316) Checking for lock 20160519-15:57:41.979082: sdm120c(6316) errno=0, bRead=2 PID=6316 LckPID=6316 20160519-15:57:41.979093: sdm120c(6316) Checking process 6316 (sdm120c) for lock 20160519-15:57:41.979117: sdm120c(6316) PID: 6316 COMMAND: "sdm120c" LckPID: 6316 LckCOMMAND: "sdm120c" LckPIDcommand "sdm120c" = me 20160519-15:57:41.979130: sdm120c(6316) Appears we got the lock. 20160519-15:57:41.979141: sdm120c(6316) resp_timeout=2000000us 20160519-15:57:41.979159: sdm120c(6316) Libmodbus context open (9600E1) 20160519-15:57:41.979171: sdm120c(6316) Byte timeout disabled. 20160519-15:57:41.979184: sdm120c(6316) New response timeout: 0s, 2000000us 20160519-15:57:41.979714: sdm120c(6316) 1/3. Register Address 30001 [0000] 20160519-15:57:42.012584: sdm120c(6316) Read time: 32842us 20160519-15:57:42.012605: sdm120c(6316) reg[0/1]=17263 (0x436F) 20160519-15:57:42.012612: sdm120c(6316) reg[1/1]=25681 (0x6451) 20160519-15:57:42.012633: sdm120c(6316) 1/3. Register Address 30013 [000C] 20160519-15:57:42.043425: sdm120c(6316) ERROR (112345695) Response not from requested slave, 1/3, Address 30013 [000C] 20160519-15:57:42.043449: sdm120c(6316) Response timeout gave up after 30765us 20160519-15:57:42.043461: sdm120c(6316) 2/3. Register Address 30013 [000C]

tell me if i could help..

On Mon, May 16, 2016 at 11:28 PM, The-Drake notifications@github.com wrote:

Hi jeanmarc, please try run something like this to capture log for last run:

sdm120c -a1 -d3 -b9600 -2 -z3 -j20 -w5 -m -p /dev/sdm 2> /tmp/lastlog.log

and cat /tmp/lastlog.log when it stops

or try to keep log of latest runs.

Actually if lockfile is "orphaned/stale" sdm should be able to resolve deadlock itself. BUT I think you should enable "wait for lock" with "-w5" even it won't wait at all. Forcing a problem should be simply as running sdm manually on another thread with PHP polling running.

Let me know.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/gianfrdp/SDM120C/issues/9#issuecomment-219553839

jeanmarc77 commented 8 years ago

Hello,

Yet another lock since yesterday at 21:41 :

[root@i3 ~]# ls -al /var/lock/ total 8 drwxr-xr-x 4 root root 120 May 20 07:38 . drwxr-xr-x 20 root root 620 May 20 00:00 .. -rw-r--r-- 1 root http 14 May 19 21:41 LCK..sdm -rw-r--r-- 1 root http 12 May 20 07:38 LCK..solar drwx------ 2 root root 40 May 19 08:00 lvm drwxr-xr-x 2 root root 40 May 19 08:00 subsys [root@i3 ~]# more /var/lock/LCK..sdm 30438 sdm120c [root@i3 ~]# ps -ef | grep sdm root 10750 7872 0 07:39 pts/0 00:00:00 grep sdm http 30437 25380 0 May19 ? 00:00:00 sh -c sdm120c -a1 -d3 -b9600 -2 -z3 -j20 -w5 -qpievfg /dev/sdm 2> /tmp/lastlog.log root 30438 30437 0 May19 ? 00:00:00 sdm120c -a1 -d3 -b9600 -2 -z3 -j 20 -w5 -qpievfg /dev/sdm [root@i3 ~]# more /tmp/lastlog.log 20160519-21:41:31.489841: sdm120c(30438) cmdline="sdm120c -a1 -d3 -b9600 -2 -z3 -j20 -w5 -qpievfg /dev/sdm" 20160519-21:41:31.489882: sdm120c(30438) szttyDevice: /dev/sdm 20160519-21:41:31.489889: sdm120c(30438) devLCKfile: </var/lock/LCK..sdm> 20160519-21:41:31.489895: sdm120c(30438) devLCKfileNew: </var/lock/LCK..sdm.30438> 20160519-21:41:31.489901: sdm120c(30438) PID: 30438 20160519-21:41:31.489914: sdm120c(30438) Attempting to get lock on Serial Port /dev/sdm... 20160519-21:41:31.489928: sdm120c(30438) Acquiring shared lock on /var/lock/LCK..sdm... 20160519-21:41:31.489939: sdm120c(30438) Shared lock on /var/lock/LCK..sdm acquired... 20160519-21:41:31.489961: sdm120c(30438) Checking for lock 20160519-21:41:31.489992: sdm120c(30438) errno=0, bRead=2 PID=30438 LckPID=30438 20160519-21:41:31.489999: sdm120c(30438) Checking process 30438 (sdm120c) for lock 20160519-21:41:31.490012: sdm120c(30438) PID: 30438 COMMAND: "sdm120c" LckPID: 30438 LckCOMMAND: "sdm120c" LckPIDcommand "sdm120c" = me 20160519-21:41:31.490020: sdm120c(30438) Appears we got the lock. 20160519-21:41:31.490025: sdm120c(30438) resp_timeout=2000000us 20160519-21:41:31.490037: sdm120c(30438) Libmodbus context open (9600E1) 20160519-21:41:31.490043: sdm120c(30438) Byte timeout disabled. 20160519-21:41:31.490051: sdm120c(30438) New response timeout: 0s, 2000000us 20160519-21:41:31.490422: sdm120c(30438) 1/3. Register Address 30001 [0000] 20160519-21:41:31.522537: sdm120c(30438) Read time: 32085us 20160519-21:41:31.522558: sdm120c(30438) reg[0/1]=17258 (0x436A) 20160519-21:41:31.522565: sdm120c(30438) reg[1/1]=21374 (0x537E) 20160519-21:41:31.522586: sdm120c(30438) 1/3. Register Address 30013 [000C] 20160519-21:41:31.555991: sdm120c(30438) Read time: 33379us 20160519-21:41:31.556016: sdm120c(30438) reg[0/1]=17315 (0x43A3) 20160519-21:41:31.556025: sdm120c(30438) reg[1/1]=55414 (0xD876) 20160519-21:41:31.556042: sdm120c(30438) 1/3. Register Address 30031 [001E] 20160519-21:41:31.590136: sdm120c(30438) Read time: 34071us 20160519-21:41:31.590163: sdm120c(30438) reg[0/1]=16237 (0x3F6D) 20160519-21:41:31.590173: sdm120c(30438) reg[1/1]=37868 (0x93EC) 20160519-21:41:31.590192: sdm120c(30438) 1/3. Register Address 30071 [0046] 20160519-21:41:31.622117: sdm120c(30438) Read time: 31902us 20160519-21:41:31.622137: sdm120c(30438) reg[0/1]=16968 (0x4248) 20160519-21:41:31.622143: sdm120c(30438) reg[1/1]=8907 (0x22CB) 20160519-21:41:31.622156: sdm120c(30438) 1/3. Register Address 30073 [0048] 20160519-21:41:31.656303: sdm120c(30438) Read time: 34122us 20160519-21:41:31.656329: sdm120c(30438) reg[0/1]=17751 (0x4557) 20160519-21:41:31.656338: sdm120c(30438) reg[1/1]=52163 (0xCBC3) 20160519-21:41:31.656350: sdm120c(30438) 1/3. Register Address 30075 [004A] 20160519-21:41:31.688913: sdm120c(30438) ERROR (112345695) Response not from requested slave, 1/3, Address 30075 [004A] 20160519-21:41:31.688930: sdm120c(30438) Response timeout gave up after 32534us 20160519-21:41:31.688937: sdm120c(30438) 2/3. Register Address 30075 [004A] [root@i3 ~]# ls -al /tmp/metern_log.txt -rw-r--r-- 1 http http 91 May 19 21:41 /tmp/metern_log.txt

jeanmarc77 commented 8 years ago

Hello, Here's more bug logs. Meanwhile i write a script that automatically kill sdm120 and clean the lock file.

20160521-08:40:30.710225: sdm120c(10108) cmdline="sdm120c -a1 -d3 -b9600 -2 -z3 -j20 -w5 -qpievfg /dev/sdm" 20160521-08:40:30.710258: sdm120c(10108) szttyDevice: /dev/sdm 20160521-08:40:30.710264: sdm120c(10108) devLCKfile: </var/lock/LCK..sdm> 20160521-08:40:30.710270: sdm120c(10108) devLCKfileNew: </var/lock/LCK..sdm.10108> 20160521-08:40:30.710275: sdm120c(10108) PID: 10108 20160521-08:40:30.710289: sdm120c(10108) Attempting to get lock on Serial Port /dev/sdm... 20160521-08:40:30.710301: sdm120c(10108) Acquiring shared lock on /var/lock/LCK..sdm... 20160521-08:40:30.710312: sdm120c(10108) Shared lock on /var/lock/LCK..sdm acquired... 20160521-08:40:30.710329: sdm120c(10108) Checking for lock 20160521-08:40:30.710359: sdm120c(10108) errno=0, bRead=2 PID=10108 LckPID=10108 20160521-08:40:30.710368: sdm120c(10108) Checking process 10108 (sdm120c) for lock 20160521-08:40:30.710381: sdm120c(10108) PID: 10108 COMMAND: "sdm120c" LckPID: 10108 LckCOMMAND: "sdm120c" LckPIDcommand "sdm120c" = me 20160521-08:40:30.710389: sdm120c(10108) Appears we got the lock. 20160521-08:40:30.710394: sdm120c(10108) resp_timeout=2000000us 20160521-08:40:30.710405: sdm120c(10108) Libmodbus context open (9600E1) 20160521-08:40:30.710411: sdm120c(10108) Byte timeout disabled. 20160521-08:40:30.710418: sdm120c(10108) New response timeout: 0s, 2000000us 20160521-08:40:30.710956: sdm120c(10108) 1/3. Register Address 30001 [0000] 20160521-08:40:30.743212: sdm120c(10108) Read time: 32230us 20160521-08:40:30.743231: sdm120c(10108) reg[0/1]=17257 (0x4369) 20160521-08:40:30.743237: sdm120c(10108) reg[1/1]=9766 (0x2626) 20160521-08:40:30.743257: sdm120c(10108) 1/3. Register Address 30013 [000C] 20160521-08:40:30.774059: sdm120c(10108) ERROR (112345695) Response not from requested slave, 1/3, Address 30013 [000C] 20160521-08:40:30.774078: sdm120c(10108) Response timeout gave up after 30777us 20160521-08:40:30.774086: sdm120c(10108) 2/3. Register Address 30013 [000C] next

20160521-08:51:13.987809: sdm120c(23177) cmdline="sdm120c -a1 -d3 -b9600 -2 -z3 -j20 -w5 -qpievfg /dev/sdm" 20160521-08:51:13.987860: sdm120c(23177) szttyDevice: /dev/sdm 20160521-08:51:13.987871: sdm120c(23177) devLCKfile: </var/lock/LCK..sdm> 20160521-08:51:13.987882: sdm120c(23177) devLCKfileNew: </var/lock/LCK..sdm.23177> 20160521-08:51:13.987892: sdm120c(23177) PID: 23177 20160521-08:51:13.987914: sdm120c(23177) Attempting to get lock on Serial Port /dev/sdm... 20160521-08:51:13.987935: sdm120c(23177) Acquiring shared lock on /var/lock/LCK..sdm... 20160521-08:51:13.987952: sdm120c(23177) Shared lock on /var/lock/LCK..sdm acquired... 20160521-08:51:13.987980: sdm120c(23177) Checking for lock 20160521-08:51:13.988018: sdm120c(23177) errno=0, bRead=2 PID=23177 LckPID=23177 20160521-08:51:13.988029: sdm120c(23177) Checking process 23177 (sdm120c) for lock 20160521-08:51:13.988050: sdm120c(23177) PID: 23177 COMMAND: "sdm120c" LckPID: 23177 LckCOMMAND: "sdm120c" LckPIDcommand "sdm120c" = me 20160521-08:51:13.988064: sdm120c(23177) Appears we got the lock. 20160521-08:51:13.988074: sdm120c(23177) resp_timeout=2000000us 20160521-08:51:13.988091: sdm120c(23177) Libmodbus context open (9600E1) 20160521-08:51:13.988102: sdm120c(23177) Byte timeout disabled. 20160521-08:51:13.988114: sdm120c(23177) New response timeout: 0s, 2000000us 20160521-08:51:13.988460: sdm120c(23177) 1/3. Register Address 30001 [0000] 20160521-08:51:14.020136: sdm120c(23177) ERROR (112345695) Response not from requested slave, 1/3, Address 30001 [0000] 20160521-08:51:14.020162: sdm120c(23177) Response timeout gave up after 31637us 20160521-08:51:14.020174: sdm120c(23177) 2/3. Register Address 30001 [0000] next

20160521-11:26:19.676140: sdm120c(31955) cmdline="sdm120c -a1 -d3 -b9600 -2 -z3 -j20 -w5 -qpievfg /dev/sdm" 20160521-11:26:19.676181: sdm120c(31955) szttyDevice: /dev/sdm 20160521-11:26:19.676188: sdm120c(31955) devLCKfile: </var/lock/LCK..sdm> 20160521-11:26:19.676194: sdm120c(31955) devLCKfileNew: </var/lock/LCK..sdm.31955> 20160521-11:26:19.676200: sdm120c(31955) PID: 31955 20160521-11:26:19.676213: sdm120c(31955) Attempting to get lock on Serial Port /dev/sdm... 20160521-11:26:19.676227: sdm120c(31955) Acquiring shared lock on /var/lock/LCK..sdm... 20160521-11:26:19.676238: sdm120c(31955) Shared lock on /var/lock/LCK..sdm acquired... 20160521-11:26:19.676257: sdm120c(31955) Checking for lock 20160521-11:26:19.676287: sdm120c(31955) errno=0, bRead=2 PID=31955 LckPID=31955 20160521-11:26:19.676293: sdm120c(31955) Checking process 31955 (sdm120c) for lock 20160521-11:26:19.676306: sdm120c(31955) PID: 31955 COMMAND: "sdm120c" LckPID: 31955 LckCOMMAND: "sdm120c" LckPIDcommand "sdm120c" = me 20160521-11:26:19.676313: sdm120c(31955) Appears we got the lock. 20160521-11:26:19.676319: sdm120c(31955) resp_timeout=2000000us 20160521-11:26:19.676330: sdm120c(31955) Libmodbus context open (9600E1) 20160521-11:26:19.676336: sdm120c(31955) Byte timeout disabled. 20160521-11:26:19.676343: sdm120c(31955) New response timeout: 0s, 2000000us 20160521-11:26:19.676689: sdm120c(31955) 1/3. Register Address 30001 [0000] 20160521-11:26:19.709690: sdm120c(31955) Read time: 32973us 20160521-11:26:19.709711: sdm120c(31955) reg[0/1]=17261 (0x436D) 20160521-11:26:19.709718: sdm120c(31955) reg[1/1]=49953 (0xC321) 20160521-11:26:19.709738: sdm120c(31955) 1/3. Register Address 30013 [000C] 20160521-11:26:19.741660: sdm120c(31955) Read time: 31902us 20160521-11:26:19.741678: sdm120c(31955) reg[0/1]=50435 (0xC503) 20160521-11:26:19.741685: sdm120c(31955) reg[1/1]=40859 (0x9F9B) 20160521-11:26:19.741699: sdm120c(31955) 1/3. Register Address 30031 [001E] 20160521-11:26:19.774778: sdm120c(31955) Read time: 33059us 20160521-11:26:19.774795: sdm120c(31955) reg[0/1]=49021 (0xBF7D) 20160521-11:26:19.774802: sdm120c(31955) reg[1/1]=1602 (0x642) 20160521-11:26:19.774814: sdm120c(31955) 1/3. Register Address 30071 [0046] 20160521-11:26:19.807234: sdm120c(31955) Read time: 32401us 20160521-11:26:19.807253: sdm120c(31955) reg[0/1]=16968 (0x4248) 20160521-11:26:19.807260: sdm120c(31955) reg[1/1]=4195 (0x1063) 20160521-11:26:19.807272: sdm120c(31955) 1/3. Register Address 30073 [0048] 20160521-11:26:19.841260: sdm120c(31955) Read time: 33968us 20160521-11:26:19.841279: sdm120c(31955) reg[0/1]=17752 (0x4558) 20160521-11:26:19.841286: sdm120c(31955) reg[1/1]=17969 (0x4631) 20160521-11:26:19.841293: sdm120c(31955) 1/3. Register Address 30075 [004A] 20160521-11:26:19.873982: sdm120c(31955) ERROR (112345695) Response not from requested slave, 1/3, Address 30075 [004A] 20160521-11:26:19.874000: sdm120c(31955) Response timeout gave up after 32664us 20160521-11:26:19.874007: sdm120c(31955) 2/3. Register Address 30075 [004A] next

20160521-12:03:40.569400: sdm120c(14981) cmdline="sdm120c -a1 -d3 -b9600 -2 -z3 -j20 -w5 -qpievfg /dev/sdm" 20160521-12:03:40.569439: sdm120c(14981) szttyDevice: /dev/sdm 20160521-12:03:40.569446: sdm120c(14981) devLCKfile: </var/lock/LCK..sdm> 20160521-12:03:40.569452: sdm120c(14981) devLCKfileNew: </var/lock/LCK..sdm.14981> 20160521-12:03:40.569457: sdm120c(14981) PID: 14981 20160521-12:03:40.569471: sdm120c(14981) Attempting to get lock on Serial Port /dev/sdm... 20160521-12:03:40.569484: sdm120c(14981) Acquiring shared lock on /var/lock/LCK..sdm... 20160521-12:03:40.569495: sdm120c(14981) Shared lock on /var/lock/LCK..sdm acquired... 20160521-12:03:40.569513: sdm120c(14981) Checking for lock 20160521-12:03:40.569544: sdm120c(14981) errno=0, bRead=2 PID=14981 LckPID=14981 20160521-12:03:40.569550: sdm120c(14981) Checking process 14981 (sdm120c) for lock 20160521-12:03:40.569563: sdm120c(14981) PID: 14981 COMMAND: "sdm120c" LckPID: 14981 LckCOMMAND: "sdm120c" LckPIDcommand "sdm120c" = me 20160521-12:03:40.569571: sdm120c(14981) Appears we got the lock. 20160521-12:03:40.569577: sdm120c(14981) resp_timeout=2000000us 20160521-12:03:40.569588: sdm120c(14981) Libmodbus context open (9600E1) 20160521-12:03:40.569594: sdm120c(14981) Byte timeout disabled. 20160521-12:03:40.569602: sdm120c(14981) New response timeout: 0s, 2000000us 20160521-12:03:40.569978: sdm120c(14981) 1/3. Register Address 30001 [0000] 20160521-12:03:40.602471: sdm120c(14981) Read time: 32462us 20160521-12:03:40.602491: sdm120c(14981) reg[0/1]=17261 (0x436D) 20160521-12:03:40.602497: sdm120c(14981) reg[1/1]=47382 (0xB916) 20160521-12:03:40.602518: sdm120c(14981) 1/3. Register Address 30013 [000C] 20160521-12:03:40.634995: sdm120c(14981) Read time: 32456us 20160521-12:03:40.635016: sdm120c(14981) reg[0/1]=50449 (0xC511) 20160521-12:03:40.635026: sdm120c(14981) reg[1/1]=27733 (0x6C55) 20160521-12:03:40.635043: sdm120c(14981) 1/3. Register Address 30031 [001E] 20160521-12:03:40.662262: sdm120c(14981) ERROR (112345695) Response not from requested slave, 1/3, Address 30031 [001E] 20160521-12:03:40.662280: sdm120c(14981) Response timeout gave up after 27177us 20160521-12:03:40.662287: sdm120c(14981) 2/3. Register Address 30031 [001E] 20160521-12:03:40.668020: sdm120c(14981) ERROR (112345695) Response not from requested slave, 2/3, Address 30031 [001E] 20160521-12:03:40.668035: sdm120c(14981) Response timeout gave up after 5713us 20160521-12:03:40.668042: sdm120c(14981) 3/3. Register Address 30031 [001E]

The clean script that must be run as root each 5 min

!/usr/bin/php

<?php if (isset($_SERVER['REMOTE_ADDR'])) { die('Direct access not permitted'); } date_default_timezone_set('Europe/Brussels'); $lockfile = '/var/lock/LCK..sdm'; $mnfile = '/tmp/metern_log.txt';

if (file_exists($lockfile)) { $now = time(); $ft = filemtime($lockfile); if ($now - $ft > 30) { // 30 sec exec("cp /tmp/lastlog.log /tmp/bug$now.log"); exec('pkill -f sdm120c'); sleep(2); if (file_exists($lockfile)) { exec("rm -f $lockfile"); } if (file_exists($mnfile)) { file_put_contents($mnfile, '', FILE_APPEND); chmod($mnfile, 0666); } $output = date('Ymd H:i:s') . "\n"; file_put_contents('/tmp/clearsdm.txt', $output, FILE_APPEND);

}

} ?>

The-Drake commented 8 years ago

I think that there is a little bug in your version that hungs when it finds some exotic errors.

Please try this new version from my fork, I tested it some months and it should work:

https://github.com/The-Drake/SDM120C

sdm120c v1.4 (Beta)

Multiple reading call example:

sdm120c -a1 -a10 -a11 -a12 -b9600 -PN -w12 -z3 -W40 -j20 -m -pvcfg /dev/ttyUSB0

jeanmarc77 commented 8 years ago

Thanks, i'll try this v1.4beta and i'll let you know.

I add few warnings will compiling, i used latest libmodbus-3.1.3. But it work ;)

[root@i3 SDM120Cb]# make clean && make rm -f .o sdm120c gcc -c -o sdm120c.o sdm120c.c -O2 -Wall -g pkg-config --cflags libmodbus gcc -c -o RS485_lock.o RS485_lock.c -O2 -Wall -g pkg-config --cflags libmodbus In file included from RS485_lock.c:25:0: sdm120c.h:34:20: warning: inline function ‘tv_diff’ declared but never defined extern long inline tv_diff(struct timeval const * const t1, struct timeval const * const t2); ^~~ gcc -c -o log.o log.c -O2 -Wall -g pkg-config --cflags libmodbus In file included from log.c:18:0: sdm120c.h:34:20: warning: inline function ‘tv_diff’ declared but never defined extern long inline tv_diff(struct timeval const * const t1, struct timeval const \ const t2); ^~~ gcc -O2 -Wall -g pkg-config --libs libmodbus -o sdm120c sdm120c.o RS485_lock.o log.o chmod 4711 sdm120c

The-Drake commented 8 years ago

If you want to speed-up readings, try -W40 option too. In my setup, it results in less retries.

jeanmarc77 commented 8 years ago

Hello,

I tried the 1.4beta with sucess. I haven't any more lock, thanks ! I believe you can close the ticket.

I will play with the parameters to see how fast i can pool. But right now it is already blazing fast, i probably have to slow down or meterN will squeeze my cpu ;)

The-Drake commented 8 years ago

Thanks for feedback jeanmarc! ;)

I think that Gianfrdp himself will close ticket for main branch when I'll push non beta version to it.

jeanmarc77 commented 2 years ago

was ok since then