30 lines
806 B
Python
30 lines
806 B
Python
import RPi.GPIO as g
|
|
from time import sleep
|
|
import json,socket
|
|
g.setmode(g.BCM)
|
|
g.setup(1, g.IN,pull_up_down=g.PUD_UP)
|
|
global revcount
|
|
revcount = 0
|
|
def increaserev(channel):
|
|
timestamp=int(1000*time.time())
|
|
json_out={"time": timestamp,"device": "rasolar","payload":{"S0":{"timestamp": timestamp,"sensor":"S0","i2c":0,"value":1}}}
|
|
try:
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
except:
|
|
print("{}: could not connect to database".format(time.time()))
|
|
else:
|
|
try:
|
|
s.connect(("banana", 24048))
|
|
except:
|
|
print("{}: could not connect to database".format(time.time()))
|
|
else:
|
|
s.sendall(json.dumps(json_out))
|
|
s.close()
|
|
global revcount
|
|
revcount += 1
|
|
g.add_event_detect(1, g.RISING, callback=increaserev)
|
|
while True:
|
|
sleep(60)
|
|
print "RPM is {0}".format(revcount)
|
|
revcount = 0
|