I thought so, thnx for confirming my suspicion. A new one is on its way, just have to wait for a few weekspvangorp wrote:Trigun, looks to me your sensor is defect!
Sent from my iPhone using Tapatalk
Moderators: leecollings, remb0
I thought so, thnx for confirming my suspicion. A new one is on its way, just have to wait for a few weekspvangorp wrote:Trigun, looks to me your sensor is defect!
Code: Select all
sudo raspi-gpio set 21 ip pu
echo "21" > /sys/class/gpio/export
echo "1" | sudo tee -a /sys/class/gpio/gpio21/active_low
echo "both" | sudo tee -a /sys/class/gpio/gpio21/edge
LouiS22 wrote: ↑Sunday 03 September 2017 19:18Code: Select all
sudo raspi-gpio set 21 ip pu echo "21" > /sys/class/gpio/export echo "1" | sudo tee -a /sys/class/gpio/gpio21/active_low echo "both" | sudo tee -a /sys/class/gpio/gpio21/edge
Code: Select all
echo 21 > /sys/class/gpio/unexport
echo 21 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio21/direction
echo 0 > /sys/class/gpio/gpio21/active_low
echo both > /sys/class/gpio/gpio21/edge
raspi-gpio set 21 pd
Code: Select all
sudo raspi-gpio get 21
Thanks for the directions. I've tested, the level changes to 1 when placing a magnet near to the sensor - so it should be ok. However I still get the GPIO INIT ERROR in Domoticz.pvangorp wrote: ↑Sunday 03 September 2017 19:26LouiS22 wrote: ↑Sunday 03 September 2017 19:18Code: Select all
sudo raspi-gpio set 21 ip pu echo "21" > /sys/class/gpio/export echo "1" | sudo tee -a /sys/class/gpio/gpio21/active_low echo "both" | sudo tee -a /sys/class/gpio/gpio21/edge
You can test it using:Code: Select all
echo 21 > /sys/class/gpio/unexport echo 21 > /sys/class/gpio/export echo in > /sys/class/gpio/gpio21/direction echo 0 > /sys/class/gpio/gpio21/active_low echo both > /sys/class/gpio/gpio21/edge raspi-gpio set 21 pd
Level=0 changes in Level=1Code: Select all
sudo raspi-gpio get 21
Hah... Found it another topic: DO NOT USE the manual add for the switch, the found devices are directly created in devices tab, if you try a manual add it will still display "GPIO INIT ERROR".
Code: Select all
2017-09-03 20:01:22.841 Sysfs GPIO: gpio21 new state = on
2017-09-03 20:01:22.846 (Watermeter GPIO) Lighting 2 (GPIO Watermeter)
2017-09-03 20:01:27.405 Sysfs GPIO: gpio21 new state = off
2017-09-03 20:01:27.409 (Watermeter GPIO) Lighting 2 (GPIO Watermeter)
Code: Select all
2017-09-03 20:10:00.929 EventSystem: Started
2017-09-03 20:10:00.929 EventSystem: Queue thread started...
2017-09-03 20:10:00.976 Active notification Subsystems: (0/12)
2017-09-03 20:10:09.776 Sysfs GPIO: gpio21 new state = on
2017-09-03 20:10:09.786 (Watermeter GPIO) Lighting 2 (Watermeter GPIO)
2017-09-03 20:10:09.981 LUA: Water usage is still 0m3
2017-09-03 20:10:09.986 EventSystem: Script event triggered: Watermeter
2017-09-03 20:10:13.458 Sysfs GPIO: gpio21 new state = off
2017-09-03 20:10:13.467 (Watermeter GPIO) Lighting 2 (Watermeter GPIO)
2017-09-03 20:10:13.601 LUA: Water usage is set to 0.001m3
2017-09-03 20:10:13.607 EventSystem: Script event triggered: Watermeter
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import urllib2
import os
#Watermeter stand (wordt alleen initeel gebruikt als er geen bestand meterstand.txt is)
global Counter
Counter = 1154651
#Domoticz URL
domoticz_url = "http://192.168.102.57:8081"
#Domoticz IDX van de water sensor (RFXMeter)
idx = 16
#Open meterstand.txt file en lees meterstand
#Als meterstand.txt niet aanwezig is maakt script bestand aan en vult de meterstand
fn = "/home/pi/domoticz/scripts/meterstand.txt"
if os.path.exists(fn):
f = file(fn, "r+")
f = open(fn)
inhoud = f.readline()
a,b,c = inhoud.split()
Counter = int(c)
else:
f = open(fn, "w")
f.write( 'meterstand = ' + repr(Counter))
f.close()
#Board is pin nr, BMC is GPIO nr
#Read output from water meter op pin 10
GPIO.setmode(GPIO.BOARD)
# Set GPIO 15 (Pin 10) als Input aditioneel als Pulldown-Weerstand aktiveren
GPIO.setup(10, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
#Functie callback
#Dit is de functie die aangeroepen wordt in de interrupt
def Interrupt(channel):
#Teller elke interupt uitlezen en met 1 liter verhogen
f = file(fn, "r+")
f = open(fn)
inhoud = f.readline()
a,b,c = inhoud.split()
Counter = int(c)
Counter = Counter + 1
f.close()
#Schrijf meterstand naar bestand
f = open( fn, 'w')
f.write( 'meterstand = ' + repr(Counter))
f.close()
#Send counter to domoticz JSON
url1 = domoticz_url+'/json.htm?type=command¶m=udevice&idx='+str(idx)+'&svalue='+str(Counter)
req1 = urllib2.Request(url1)
response1 = urllib2.urlopen(req1)
#Voor debug => print voorbeeld van de JSON aanroep en/of de counter
#print "JSON call = "+ str(url1)
#print "Watermeter Counter = " + str(Counter)
#Interrupt-Event toevoegen, bij een NPN off geeft sensor een 0 en en bij detectie een 1
#Bij detectie (LED on) een 1 daarom check dalende interrupt.
GPIO.add_event_detect(10, GPIO.RISING, callback = Interrupt, bouncetime = 800)
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
print "\nBye"
what im doing wrong ???2017-09-05 10:21:12.510 Error: EventSystem: in NPN: [string "commandArray = {} ..."]:8: attempt to perform arithmetic on global 'sWaterUsage' (a nil value)
2017-09-05 10:21:21.808 Error: EventSystem: in NPN: [string "commandArray = {} ..."]:8: attempt to perform arithmetic on global 'sWaterUsage' (a nil value)
commandArray = {}
-- Water usage
-- Retrieve value from water meter device:
sWaterUsage = otherdevices_svalues['Water'']
-- To have a better readable format, divide number by 1000:
sWaterUsagePrint = tonumber(sWaterUsage / 1000);
-- calculation is done with the unmodified water value
sWaterUsage = tonumber(sWaterUsage);
-- For Debuging
-- print("Water usage until now is " .. sWaterUsagePrint .. "m3 ")
-- print('GPIO Watermeter = '..otherdevices['GPIO15'])
function timedifference(s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
if (devicechanged['GPIO15'] == 'Off')
then
sWaterUsageTot = (sWaterUsage + 1)
print("Water usage is set to " .. sWaterUsageTot / 1000 .. "m3 ");
commandArray['UpdateDevice'] = '16|0|'..sWaterUsageTot..''
else
-- Keep a live device
if (timedifference(otherdevices_lastupdate["Water"]) > 300)
then
print("Water usage is still " .. sWaterUsage / 1000 .. "m3 ");
commandArray['UpdateDevice'] = '16|0|'..sWaterUsage..''
end
end
return commandArray
Users browsing this forum: No registered users and 1 guest