Page 4 of 5

Re: Using GPIO to measure energy

Posted: Friday 20 March 2015 17:07
by roblom
Nobody an idea on what can be the problem of the isrcounter not stating?

Re: Using GPIO to measure energy

Posted: Saturday 21 March 2015 8:29
by hansrune
You can debug into more detail by using 'sudo bash -x /etc/init.d/isrcounter status'

Does the daemon executable exist ? Check that what is in NAME=isr.... in the init script exists in your PATH. Mine is NAME=isrcounter1 and exists in /usr/local/bin/isrcounter1

Re: Using GPIO to measure energy

Posted: Sunday 29 March 2015 22:55
by roblom
hansrune wrote:You can debug into more detail by using 'sudo bash -x /etc/init.d/isrcounter status'

Does the daemon executable exist ? Check that what is in NAME=isr.... in the init script exists in your PATH. Mine is NAME=isrcounter1 and exists in /usr/local/bin/isrcounter1
"NAME=isrcounter" and exists in "/usr/local/bin/isrcounter" and "/usr/local/bin" does exists in PATH.
'sudo bash -x /etc/init.d/isrcounter status' gives.

Code: Select all

+ PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
+ DESC='ISR pulse counter and uploader'
+ NAME=isrcounter
+ NAME_SAVEFILE=watermeterstand
+ USERNAME=pi
+ DEVIDX=6
+ LOGFILE=/var/run/shm/isrcounter
+ SAVEFILE=/home/pi/domoticz/scripts/watermeterstand
+ DAEMON=/usr/local/bin/isrcounter
+ DAEMON_ARGS=/var/run/shm/isrcounter
+ SCRIPTNAME=/etc/init.d/isrcounter
+ '[' -x /usr/local/bin/isrcounter ']'
+ . /lib/init/vars.sh
++ TMPTIME=0
++ SULOGIN=no
++ DELAYLOGIN=no
++ UTC=yes
++ VERBOSE=no
++ FSCKFIX=no
++ '[' -f /etc/default/rcS ']'
++ . /etc/default/rcS
+++ FSCKFIX=yes
++ unset EDITMOTD
++ unset RAMRUN
++ unset RAMLOCK
++ '[' -r /proc/cmdline ']'
+++ cat /proc/cmdline
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ for ARG in '$(cat /proc/cmdline)'
++ case $ARG in
++ '[' '' ']'
+ . /lib/lsb/init-functions
+++ run-parts --lsbsysinit --list /lib/lsb/init-functions.d
++ for hook in '$(run-parts --lsbsysinit --list /lib/lsb/init-functions.d 2>/dev/null)'
++ '[' -r /lib/lsb/init-functions.d/20-left-info-blocks ']'
++ . /lib/lsb/init-functions.d/20-left-info-blocks
++ FANCYTTY=
++ '[' -e /etc/lsb-base-logging.sh ']'
++ true
+ case "$1" in
+ status_of_proc /usr/local/bin/isrcounter isrcounter
+ local pidfile daemon name status OPTIND
+ pidfile=
+ OPTIND=1
+ getopts p: opt
+ shift 0
+ '[' -n '' ']'
+ daemon=/usr/local/bin/isrcounter
+ name=isrcounter
+ status=0
+ pidofproc /usr/local/bin/isrcounter
+ local pidfile base status specified pid OPTIND
+ pidfile=
+ specified=
+ OPTIND=1
+ getopts p: opt
+ shift 0
+ base=isrcounter
+ '[' '!' '' ']'
+ pidfile=/var/run/isrcounter.pid
+ '[' -n /var/run/isrcounter.pid ']'
+ '[' -e /var/run/isrcounter.pid ']'
+ '[' -x /bin/pidof ']'
+ '[' '!' '' ']'
+ status=0
+ /bin/pidof -o %PPID -x /usr/local/bin/isrcounter
+ status=1
+ '[' 1 = 1 ']'
+ return 3
+ status=3
+ '[' 3 = 0 ']'
+ '[' 3 = 4 ']'
+ log_failure_msg 'isrcounter is not running'
+ '[' -n 'isrcounter is not running' ']'
+ log_begin_msg isrcounter is not running ...
+ log_begin_msg_pre isrcounter is not running ...
+ log_daemon_msg_pre isrcounter is not running ...
+ log_use_fancy_output
+ TPUT=/usr/bin/tput
+ EXPR=/usr/bin/expr
+ '[' -t 1 ']'
+ '[' xxterm '!=' x ']'
+ '[' xxterm '!=' xdumb ']'
+ '[' -x /usr/bin/tput ']'
+ '[' -x /usr/bin/expr ']'
+ /usr/bin/tput hpa 60
+ /usr/bin/tput setaf 1
+ '[' -z ']'
+ FANCYTTY=1
+ case "$FANCYTTY" in
+ true
+ /bin/echo -n '[....] '
[....] + '[' -z isrcounter ']'
+ /bin/echo -n isrcounter is not running ...
isrcounter is not running ...+ log_begin_msg_post isrcounter is not running ...
+ :
+ log_end_msg 1
+ '[' -z 1 ']'
+ local retval
+ retval=1
+ log_end_msg_pre 1
+ log_use_fancy_output
+ TPUT=/usr/bin/tput
+ EXPR=/usr/bin/expr
+ '[' -t 1 ']'
+ '[' xxterm '!=' x ']'
+ '[' xxterm '!=' xdumb ']'
+ '[' -x /usr/bin/tput ']'
+ '[' -x /usr/bin/expr ']'
+ /usr/bin/tput hpa 60
+ /usr/bin/tput setaf 1
+ '[' -z 1 ']'
+ true
+ case "$FANCYTTY" in
+ true
++ /usr/bin/tput setaf 1
+ RED=''
++ /usr/bin/tput setaf 2
+ GREEN=''
++ /usr/bin/tput setaf 3
+ YELLOW=''
++ /usr/bin/tput op
+ NORMAL=''
+ /usr/bin/tput civis
+ /usr/bin/tput sc
+ /usr/bin/tput hpa 0
+ '[' 1 -eq 0 ']'
+ '[' 1 -eq 255 ']'
+ /bin/echo -ne '[FAIL'
[FAIL+ /usr/bin/tput rc
+ /usr/bin/tput cnorm
+ log_use_fancy_output
+ TPUT=/usr/bin/tput
+ EXPR=/usr/bin/expr
+ '[' -t 1 ']'
+ '[' xxterm '!=' x ']'
+ '[' xxterm '!=' xdumb ']'
+ '[' -x /usr/bin/tput ']'
+ '[' -x /usr/bin/expr ']'
+ /usr/bin/tput hpa 60
+ /usr/bin/tput setaf 1
+ '[' -z 1 ']'
+ true
+ case "$FANCYTTY" in
+ true
++ /usr/bin/tput setaf 1
+ RED=''
++ /usr/bin/tput setaf 3
+ YELLOW=''
++ /usr/bin/tput op
+ NORMAL=''
+ '[' 1 -eq 0 ']'
+ '[' 1 -eq 255 ']'
+ /bin/echo -e ' failed!'
 failed!
+ log_end_msg_post 1
+ :
+ return 1
+ true
+ return 3
+ exit 3

Re: Using GPIO to measure energy

Posted: Friday 25 September 2015 0:06
by Panda
Sorry to kick this old threat but I got the same error as roblom, can start the compiled script fine, but won't be able to use the start/stop script.

Re: Using GPIO to measure energy

Posted: Friday 25 September 2015 6:27
by sincze
Panda wrote:Sorry to kick this old threat but I got the same error as roblom, can start the compiled script fine, but won't be able to use the start/stop script.
Ok will setup demo on separate raspberry to see what is wrong. Currently II don't have access to my hardware. Really interested what is going wrong here.

Re: Using GPIO to measure energy

Posted: Saturday 03 October 2015 14:36
by sincze
sincze wrote:
Panda wrote:Sorry to kick this old threat but I got the same error as roblom, can start the compiled script fine, but won't be able to use the start/stop script.
Ok will setup demo on separate raspberry to see what is wrong. Currently II don't have access to my hardware. Really interested what is going wrong here.
I started from scratch today.
Can you guys confirm you modified the script as described in this thread http://www.domoticz.com/forum/viewtopic ... =40#p30924?

From:

Code: Select all

USERNAME=pi
Gives me:

Code: Select all

pi@raspberrypi ~/domoticz/watermeter $ sudo /etc/init.d/isrcounter start
pi@raspberrypi ~/domoticz/watermeter $ sudo /etc/init.d/isrcounter status
[FAIL] isrcounter1 is not running ... failed!
and change that line to

Code: Select all

USERNAME=root
Now gives me the desired result:

Code: Select all

pi@raspberrypi ~/domoticz/watermeter $ sudo /etc/init.d/isrcounter start
pi@raspberrypi ~/domoticz/watermeter $ sudo /etc/init.d/isrcounter status
[ ok ] isrcounter1 is running.
pi@raspberrypi ~/domoticz/watermeter $ sudo /etc/init.d/isrcounter stop
pi@raspberrypi ~/domoticz/watermeter $ sudo /etc/init.d/isrcounter status
[FAIL] isrcounter1 is not running ... failed!

Re: Using GPIO to measure energy

Posted: Friday 13 November 2015 12:04
by gdrak0
Hello All
I implement the solution that is mentioned in this topic to record the pulses from one meter Landis + Gyr E650.
Everything works well and the measurements are very good.
The only problem I have is when the raspberry does restart, which will record a very large number of units and bringing the number of Kwhs be far from reality.
If the raspberry works continuously without any interruption everything is correct.
The same happens if I run the following command...and as you will see the second entry has a huge number of pulses ..

root@raspberrypi:~# sudo /usr/local/bin/isrcounter /var/run/shm/isrcounter
Waiting ... Done. counter: 16709236: 0
Waiting ... Done. counter: 16709335: 16709236
Waiting ... Done. counter: 16709418: 99
Waiting ... Done. counter: 16709511: 83
Waiting ... Done. counter: 16709591: 93
Waiting ... Done. counter: 16709684: 80
Waiting ... Done. counter: 16709771: 93
Waiting ... Done. counter: 16709861: 87
Waiting ... Done. counter: 16709950: 90
Waiting ... Done. counter: 16710045: 89
Waiting ... Done. counter: 16710129: 95

Is there a solution to deal with this problem .. ??
Thanks in advance
George

Re: Using GPIO to measure energy

Posted: Saturday 14 November 2015 10:10
by sincze
Hi George

You mention the isrcounter script just as an example right? Not using this script for landis meter right?

I assume domoticz takes care of your energy values via a /dev/ttyUSBx?

Re: Using GPIO to measure energy

Posted: Monday 16 November 2015 10:36
by gdrak0
Hi sincze

I use the script for real measurements and not for an example..
From the meter Landis + Gyr get pulses and count through the GPIO 23 with isrcounter.
Everything works fine except if you close the power abruptly from the raspberry or if I give the command..
isrcounter status
Waiting ... Done. counter: 32365: 0
Waiting ... Done. counter: 32371: 32367
Waiting ... Done. counter: 32457: 9

As you see on my second line adds a very large number of units..
Thank you
George

Re: Using GPIO to measure energy

Posted: Monday 02 January 2017 22:32
by Lieuwke
Hi all,

i have my TCRT5000 hooked up to my Raspberry GPIO and with GPIO readall i can see when the disc from my watermeter passes by (showing 1 or 0)
I have made a contact in Domoticz that show the status also. But now i'm stuck. Where do i go from there.
How do i get the watermeter to count in my utility view? What steps do i have to go over?

Re: Using GPIO to measure energy

Posted: Monday 02 January 2017 23:13
by sincze
Lieuwke wrote:Hi all,

i have my TCRT5000 hooked up to my Raspberry GPIO and with GPIO readall i can see when the disc from my watermeter passes by (showing 1 or 0)
I have made a contact in Domoticz that show the status also. But now i'm stuck. Where do i go from there.
How do i get the watermeter to count in my utility view? What steps do i have to go over?
Did you find this link?? Isrcounter?
viewtopic.php?t=5021

Re: Using GPIO to measure energy

Posted: Monday 02 January 2017 23:24
by Lieuwke
LoL in a topic i started myself a loooooong time ago, :)

thank you sincze.
I asume you mean the isrcounter.zip ?

Can you explain to me wich steps i have to take with it? (i'm not very well at these things.)
put it in a file, how do i adjust for my GPIO pin? etc. Whats self explaining for someone who has done these things over and over can be very challenging for the unexperienced. Thank you for your effort and patience.

Best regards,
Martin

Re: Using GPIO to measure energy

Posted: Monday 02 January 2017 23:50
by sincze
You are right the information is all over the forum let met try to find the individual posts and show it to you it works excellent :) seems I have to thank to u for the idea. These are my connections.
raspberry-pi-rev2-gpio-pinout.jpg
Image


And the instructions
viewtopic.php?t=3151&start=20
Sent from my SM-G925F using Tapatalk

Re: Using GPIO to measure energy

Posted: Tuesday 03 January 2017 17:13
by Lieuwke
Hi Sincze,

thank you very much. I was at that same topic, but got stuck on step 3 ( i think i got step 2 ok)
Step 3: The interrupt handler is adapted from the wiringPi samples. Under wiringPi/examples, add the C program isrcounter1.c. I also added an output for a feedback LED in series with a current-limiting resistor. The LED output changes every other pulse received. Adjust pin numbers as needed in the C program, then make isrcounter1. Copy the compiled code to /usr/local/bin/isrcounter1. Source code can be downloaded from http://hansrune.net/domo/isrcounter1.c

Step 4: Add a system startup / service script to /etc/init.d/isrcounter. You can download my version from http://hansrune.net/domo/isrcounter

Step 5: Wire your input signal, and optionally the feedback output

Step 6: Under domoticz application settings, adjust the number of pulses and costs per unit of consumption
Mayby you can tell me the steps that are involved in step 3?

Re: Using GPIO to measure energy

Posted: Tuesday 03 January 2017 19:20
by sincze
As long as you put my compiled isrcounter in the /usr/local/bin directory and have it attached as in my screenshot that is sufficient for step 3

Sent from my SM-G925F using Tapatalk

Re: Using GPIO to measure energy

Posted: Tuesday 03 January 2017 21:09
by Lieuwke
Hi Sincze,

the compiled isrcounter. Is this the right file: download/file.php?id=3097 ?
In the zip i see a txt file. Do i copy the contents into a file called isrcounter in the /usr/local/bin directory? I'm not quite sure what i have to do with the txt file. (i'm using a windows pc and putty)

As you can see, i'm lacking some basic skills on the software side off things......

Update:
I copied the contents of the txt file into a file called isrcounter.c with nano
then i did: gcc -o isrcounter isrcounter.c -lwiringPi
When i run:
isrcounter1 /var/run/shm/isrcounter1
i get:
Waiting ... Waiting ... Waiting ... Done. counter: 18639: 1
Waiting ... Done. counter: 18707: 1
Waiting ... Done. counter: 18732: 83
Waiting ... Done. counter: 18734: 10
Waiting ... Done. counter: 18761: 2
Waiting ... Done. counter: 18797: 47
Waiting ... Done. counter: 18803: 16
Waiting ... Done. counter: 18805: 6

And my watermeter is finally showing some values. They suck :lol:
But at least i have a feeling i'n going in the right direction.

Few thing to do:
- See if the counting starts automatically
- Change the value of the meter to the actual values
- and I need to figure out where all those pulses are coming from (maybe a need to add a pull up/down resistor on the GPIO? Thought i didn't need one with the TCRT5000 since it's output is digital i/o) because now it's counting way to many.

Thanks for the great work on it and your kind support!

Re: Using GPIO to measure energy

Posted: Tuesday 03 January 2017 23:51
by sincze
Let me check the instructions tomorrow. The initial meter value you have to set in a temp file:) that isrcounter is using the final file is the file domoticz reads. I don't use a resistor so don't worry we will get it running. Mine has been for over 2 years and same installation with 4 neighbours. Hahaha.

Sent from my SM-G925F using Tapatalk

Re: Using GPIO to measure energy

Posted: Wednesday 04 January 2017 17:54
by Lieuwke
Hi sincze,

i don't worry at all, your are very kind and patient, so i'm confident we will get it going right :)
I also want to document the steps i'm making for myself. Now i'm running on a rpi 1b v2 with domoticz 2.2826 that is a bit outdated, but it's working. I've got a Rpi3 lying here i want to use with the new domoticz version and i have to do the steps all over again.

I noticed no increase on my watermeter values since last evening, so i think it's not starting automatically.

Re: Using GPIO to measure energy

Posted: Wednesday 04 January 2017 19:07
by sincze
Lieuwke wrote:Hi sincze,

i don't worry at all, your are very kind and patient, so i'm confident we will get it going right :)
I also want to document the steps i'm making for myself. Now i'm running on a rpi 1b v2 with domoticz 2.2826 that is a bit outdated, but it's working. I've got a Rpi3 lying here i want to use with the new domoticz version and i have to do the steps all over again.

I noticed no increase on my watermeter values since last evening, so i think it's not starting automatically.
A yes. the famous how to get back from a disaster or... I want to upgrade my hardware scenario :D

Add this to your manual as well ;'-)

Step 0: http://www.domoticz.com/forum/viewtopic ... =20#p28371

Step 1: Connect the tcrt5000 device with plain dupont cables to:

Code: Select all

HeaderPin  1:	3,3 volt
HeaderPin  9:	Ground
HeaderPin 12:  	GPIO1
Step 2:

Code: Select all

Install Wiring PI (http://wiringpi.com/download-and-install/)
	-	sudo apt-get install git-core
	-	sudo apt-get update
	-	sudo apt-get upgrade
	-	git clone git://git.drogon.net/wiringPi
	-	cd wiringPi
	-	git pull origin
	-	./build
Step 3: Please use
isrcounter1.rar
(6.26 KiB) Downloaded 265 times
in /usr/local/bin. All ready including false-positive detection. Rename the isrcounter1_binary to isrcounter1

Step 4: Startup script
isrcounter1.rar
(6.26 KiB) Downloaded 265 times
in /etc/init.d/. Rename the isrcounter_startup_service to isrcounter


Step 5a: Set Initial value in temp file /var/run/shm/isrcounter1

Code: Select all

echo 2142454 > /var/run/shm/isrcounter1
Step 5b: Set inital value in domoticz meter (if not okay)

Code: Select all

http://<YOUR_IP_HERE>:8080/json.htm?type=command&param=udevice&idx=<YOUR_IDX_HERE&nvalue=0&svalue=<YOUR_METER_VALUE_HERE>
#Advanced settings.... Have monit monitor your watermeter pid file.

Install Monit

Code: Select all

	sudo apt-get install monit
	sudo monit
Create the Watermeter Config file watermeter.conf in /etc/monit/conf.d directory

Code: Select all

check process Water_Meter matching "/usr/local/bin/isrcounter1"
start program "/etc/init.d/isrcounter start"
stop program "/etc/init.d/isrcounter stop"

Code: Select all

	
	sudo monit status
	sudo monit reload
Maybe I still did forget something but it will keep you rolling. :D

Re: Using GPIO to measure energy

Posted: Wednesday 04 January 2017 19:24
by Lieuwke
Wow sincze,

that looks fabulous! A complete howto!
I will try this asap and let you know. The misses wants some quality time this week, so i don't know if i can get around to it this week already.