Hi jackzampolin
Thanks for your reply. I prefer to use python eventhough im quite new with python and coding in general.
I have created a code that is "printing the value I want to store in my influxdb.
The code is checking the status (0/1) of GPIO pin 4 every second for one minute, and then printing the value (a number between 0 and 60)
This value I would like to go into my influxdb with at timestamp. And then create a graph in openhab so I can monitor the status from remote.
Heres my code I have in python for printing the “count” value:
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(4,GPIO.IN)
while True:
count = 0
for loop_count in range(0,60):
sensor = GPIO.input(4) # 0, 1
if sensor == 1:
count += 1
time.sleep(1)
print count, “-”, time.strftime("%d-%m-%Y %H:%M:%S")
I tried with the cod below, but its not working.
#!/usr/bin/python
import time
import RPi.GPIO as GPIO
import json
import math
import requests
import sys
IP = “192.168.0.100” # The IP of the machine hosting your influxdb instance
DB = “furnace” # The database to write to, has to exist
USER = “Johansen” # The influxdb user to authenticate with
PASSWORD = “1234” # The password of that user
GPIO.setmode(GPIO.BCM)
GPIO.setup(4,GPIO.IN)
while True:
count = 0
for loop_count in range(0,10):
sensor = GPIO.input(4) # 0, 1
if sensor == 1:
count += 1
time.sleep(1)
print count, “-”, time.strftime("%d-%m-%Y %H:%M:%S")
r = requests.post(“http://%s:8086/write?db=%s” %(IP, DB), auth=(USER, PASSWORD), data=[count])
if r.status_code != 204:
print 'Failed to add point to influxdb (%d) - aborting.' %r.status_code
sys.exit(1)