Displaying Seneye in Reef-Pi

TCoach

Well-Known Member
View Badges
Joined
Feb 21, 2021
Messages
589
Reaction score
653
Location
SC
Rating - 0%
0   0   0
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
 
OP
OP
TCoach

TCoach

Well-Known Member
View Badges
Joined
Feb 21, 2021
Messages
589
Reaction score
653
Location
SC
Rating - 0%
0   0   0
Very interesting. Am I right to assume this require to have the web server too?
No, right now I’m using a mini stick computer to run the Seneye. I don’t use their SWS web server.
 

Krheigh

New Member
View Badges
Joined
Apr 17, 2020
Messages
21
Reaction score
16
Rating - 0%
0   0   0
just found this...
first of all the rows i marked red is that pass and username for the pi or my seneye account?
any thing elese i have to change in the code to get it to work?

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)
 
OP
OP
TCoach

TCoach

Well-Known Member
View Badges
Joined
Feb 21, 2021
Messages
589
Reaction score
653
Location
SC
Rating - 0%
0   0   0
just found this...
first of all the rows i marked red is that pass and username for the pi or my seneye account?
any thing elese i have to change in the code to get it to work?

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)
I believe that is correct
 

Krheigh

New Member
View Badges
Joined
Apr 17, 2020
Messages
21
Reaction score
16
Rating - 0%
0   0   0
well if someone get this to work...feel free to enlight me;Nailbiting

been banging my head to the keyboard all day with no results.

my coding skills is not that good
neither is mind reading...:rolleyes:
followed the instructions above but get confused about the file paths... there's
"/home/pi/seneye" and "/home/pi/ReefData/seneye"
 
Last edited:
OP
OP
TCoach

TCoach

Well-Known Member
View Badges
Joined
Feb 21, 2021
Messages
589
Reaction score
653
Location
SC
Rating - 0%
0   0   0
well if someone get this to work...feel free to enlight me;Nailbiting

been banging my head to the keyboard all day with no results.

my coding skills is not that good
neither is mind reading...:rolleyes:
followed the instructions above but get confused about the file paths... there's
"/home/pi/seneye" and "/home/pi/ReefData/seneye"
Create both directories.
/home/pi/seneye is where the code goes
/home/pi/ReefData/seneye is where the data will go for reef-pi to read
 

Krheigh

New Member
View Badges
Joined
Apr 17, 2020
Messages
21
Reaction score
16
Rating - 0%
0   0   0
Sorry, Seneye credentials
could you please post a screenshot of the seneye.py file the code above doesnt work and theres seems to be missing alot of "tab"
blurr your logindata or send me a copy of seneye.py without login data.
 
Last edited:

Caring for your picky eaters: What do you feed your finicky fish?

  • Live foods

    Votes: 9 24.3%
  • Frozen meaty foods

    Votes: 31 83.8%
  • Soft pellets

    Votes: 7 18.9%
  • Masstick (or comparable)

    Votes: 1 2.7%
  • Other

    Votes: 2 5.4%
Back
Top