Displaying Seneye in Reef-Pi

TCoach

Active Member
View Badges
Joined
Feb 21, 2021
Messages
279
Reaction score
295
Review score
+0 /0 /-0
Location
SC
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.

seneye.jpg


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
drivers.jpg


Create Analog Input Connectors for each parameter (Admin -> Connectors)
connector.jpg


Add "pH" montors:
Under pH, add each monitor. Only poll every 1800 seconds due to Seneye only updating data 2x an hour.

ph.jpg
 
Top Shelf Aquatics

Do you house a "Reef Safe" Angelfish in your reef tank?

  • YES and it's going good

    Votes: 195 40.8%
  • YES but it's not working out

    Votes: 13 2.7%
  • NO I have tried it in the past and it didn't work out

    Votes: 44 9.2%
  • NO I haven't tried yet

    Votes: 211 44.1%
  • Other (please explain)

    Votes: 15 3.1%
AF
Top