Hey everyone,
While I wait for some more funds to be freed up for additional hardware, I have been able to pull in Seneye data into my reef-pi. Due to limitations of the Seneye api, data is only available 2x an hour.
Thought some of you might also like this.
API code:
/home/pi/seneye/seneye.py
Create a run file to make cron easier:
/home/pi/seneye/seneye.sh
Setup a cron job to run twice an hour:
crontab -e
Create file Drivers (Admin -> Drivers). Create one for each of the 5 parameters (NH3, NH4, O2, pH, Temp)
Path should be: /home/pi/ReefData/seneye/<seneye name>_<parameter>_data
ie: /home/pi/ReefData/seneye/92_Corner_temp_data
Create Analog Input Connectors for each parameter (Admin -> Connectors)
Add "pH" montors:
Under pH, add each monitor. Only poll every 1800 seconds due to Seneye only updating data 2x an hour.
While I wait for some more funds to be freed up for additional hardware, I have been able to pull in Seneye data into my reef-pi. Due to limitations of the Seneye api, data is only available 2x an hour.
Thought some of you might also like this.
API code:
/home/pi/seneye/seneye.py
import requests
import os
from pprint import pprint
__BASE_URL__ = "https://api.seneye.com/v1/devices"
username = "user"
password = "pass"
rootDir = "/home/pi"
workDir = "/ReefData/seneye"
seneye_data = {
"nh3": 0.0,
"nh4": 0.0,
"o2": 0.0,
"ph": 0.0,
"temp": 0.0
}
use_fahrenheit = True
def get_devices():
auth = {"user": username, "pwd": password}
device_resp = requests.get(__BASE_URL__, auth)
if device_resp.status_code == 200:
for device_json in device_resp.json():
device = "_".join(device_json["description"].split())
device_id = device_json["id"]
get_experiments(device, device_id, auth)
else:
print("Unable to pull state data. Status: {}".format(status_resp.status_code))
exit(1)
def get_experiments(in_device_name, in_device_id, in_auth):
experiments_url = "{}/{}/exps".format(__BASE_URL__, in_device_id)
experiments_resp = requests.get(experiments_url, in_auth)
if experiments_resp.status_code == 200:
experiments_data = experiments_resp.json()
seneye_data["nh3"] = experiments_data["nh3"]["curr"]
seneye_data["nh4"] = experiments_data["nh4"]["curr"]
seneye_data["o2"] = experiments_data["o2"]["curr"]
seneye_data["ph"] = experiments_data["ph"]["curr"]
seneye_data["temp"] = float(experiments_data["temperature"]["curr"])
if use_fahrenheit:
seneye_data["temp"] = float(seneye_data["temp"]) * 9/5 + 32
write_files(in_device_name)
else:
print("Unable to pull experiment data. Status: {}".format(status_resp.status_code))
exit(1)
def write_files(in_device_name):
path = rootDir + workDir
access_rights = 0o777
if not os.path.isdir(path):
try:
os.makedirs(path, access_rights)
except OSError:
print("Creation of the directory %s failed" % path)
exit(1)
else:
print("Successfully created the directory %s " % path)
for key in seneye_data.keys():
filename = "{}/{}_{}_data".format(path, in_device_name, key)
file = open(filename, "w")
if key == "temp":
data = str(seneye_data[key])
else:
data = seneye_data[key]
file.write(data)
file.close()
os.chmod(filename, access_rights)
get_devices()
exit(0)
Create a run file to make cron easier:
/home/pi/seneye/seneye.sh
#!/bin/bash
/usr/bin/python3 /home/pi/seneye/seneye.py >>/home/pi/seneye/log 2>&1
Setup a cron job to run twice an hour:
crontab -e
10,40 * * * * /home/pi/seneye/seneye.sh
Create file Drivers (Admin -> Drivers). Create one for each of the 5 parameters (NH3, NH4, O2, pH, Temp)
Path should be: /home/pi/ReefData/seneye/<seneye name>_<parameter>_data
ie: /home/pi/ReefData/seneye/92_Corner_temp_data
Create Analog Input Connectors for each parameter (Admin -> Connectors)
Add "pH" montors:
Under pH, add each monitor. Only poll every 1800 seconds due to Seneye only updating data 2x an hour.