Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #83

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
24974ad
Fixes
MattHoy Jun 1, 2020
235720f
Fixing moisture arguments
MattHoy Jun 3, 2020
2beeea9
Updating to use DHT11 instead of DHT22
MattHoy Jun 3, 2020
bf04277
Adjusting moisture sensitivity
MattHoy Jun 3, 2020
39e8463
Adding 7 day chart
MattHoy Jun 6, 2020
3e68b1a
Fixing method name
MattHoy Jun 6, 2020
a9318ec
Fixing method name
MattHoy Jun 6, 2020
45550fa
Fixes
MattHoy Jun 6, 2020
0b46411
Using USB camera
MattHoy Jun 6, 2020
00651b0
Using USB camera
MattHoy Jun 6, 2020
e1bd590
Fixing charts
MattHoy Jun 13, 2020
0f1a3b1
Chart fixes
MattHoy Jun 13, 2020
afb871e
Chart fixes
MattHoy Jun 13, 2020
45ce0e8
Chart fixes
MattHoy Jun 13, 2020
4f9a499
Chart fixes
MattHoy Jun 13, 2020
55eeb9b
Chart fixes
MattHoy Jun 13, 2020
6f551cd
Chart fixes
MattHoy Jun 13, 2020
22ae574
Chart fixes
MattHoy Jun 13, 2020
ced5516
Chart fixes
MattHoy Jun 13, 2020
d0526c2
Adding pump control
MattHoy Jun 13, 2020
33cf8d8
Adding pump control
MattHoy Jun 13, 2020
660db67
Adding pump control
MattHoy Jun 13, 2020
d9001d2
Chart fixes
MattHoy Jun 13, 2020
96d27dc
Chart fixes
MattHoy Jun 13, 2020
9bf5aee
Chart fixes
MattHoy Jun 13, 2020
0b9c591
Chart fixes
MattHoy Jun 13, 2020
e16ee18
Chart fixes
MattHoy Jun 13, 2020
b8de768
Chart fixes
MattHoy Jun 13, 2020
c5ba36e
Chart fixes
MattHoy Jun 13, 2020
7016471
Chart fixes
MattHoy Jun 13, 2020
756c61f
Chart fixes
MattHoy Jun 13, 2020
3e25116
Chart fixes
MattHoy Jun 13, 2020
b5c47e6
Revert
MattHoy Jun 13, 2020
e77b7ca
p
MattHoy Jun 13, 2020
69a4c6e
test
MattHoy Jun 13, 2020
6ed245a
test
MattHoy Jun 13, 2020
d17c7f8
test
MattHoy Jun 13, 2020
5ed2983
test
MattHoy Jun 13, 2020
6d78710
test
MattHoy Jun 13, 2020
5845c70
test
MattHoy Jun 13, 2020
b0fd1fc
test
MattHoy Jun 13, 2020
3c97b7e
test
MattHoy Jun 13, 2020
eca94c4
test
MattHoy Jun 13, 2020
06c8d98
test
MattHoy Jun 13, 2020
9e57bcf
test
MattHoy Jun 13, 2020
22f0de5
p
MattHoy Jun 13, 2020
2f7d66e
SQL updates
MattHoy Jun 16, 2020
05986e0
Fixes
MattHoy Jun 16, 2020
331e13a
Fixes
MattHoy Jun 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
299 changes: 121 additions & 178 deletions app/actions/fruxepi.py

Large diffs are not rendered by default.

37 changes: 22 additions & 15 deletions app/application/controllers/Dashboard.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
ob_start();
/**
* FruxePi (frx-dev-v0.3)
* Dashboard Controller
*/
class Dashboard extends CI_Controller
class Dashboard extends CI_Controller
{

// Constructor
Expand All @@ -29,8 +29,8 @@ public function __construct()

/**
* Dashboard - Index
* The main page of the FruxePi app. From here, all things are possible!
*
* The main page of the FruxePi app. From here, all things are possible!
*
* @url /dashboard
*/
public function index()
Expand All @@ -47,11 +47,13 @@ public function index()
$data['crops'] = $this->Crop_model->getAllCropsInfo();
$data['crop_activity'] = $this->Crop_model->get_cropActivity();

$data['temperature_chart'] = $this->Dashboard_model->get_temperature_chart_data();
$data['temperature_format'] = $this->Climate_model->getTemperatureFormat();
$data['humidity_chart'] = $this->Dashboard_model->get_humidity_chart_data();
$data['chart_legend'] = $this->Dashboard_model->get_chart_legend();


$data['temperature_chart7'] = $this->Dashboard_model->get_temperature_chart7_data();
$data['humidity_chart7'] = $this->Dashboard_model->get_humidity_chart7_data();
$data['moisture_chart7'] = $this->Dashboard_model->get_moisture_chart7_data();
$data['chart_legend7'] = $this->Dashboard_model->get_chart_legend7();

$data['pump_schedule'] = $this->Pump_model->getPumpSchedule();
$data['fan_schedule'] = $this->Fan_model->getFanSchedule();
$data['fan_status'] = $this->Fan_model->getFanStatus();
Expand All @@ -65,9 +67,14 @@ public function index()
$data['cropConditions'] = $this->Dashboard_model->get_cropConditions();
$data['soil_status'] = $this->Moisture_model->readMoistureSensor();

$data['temperature_chart'] = $this->Dashboard_model->get_temperature_chart_data();
$data['temperature_format'] = $this->Climate_model->getTemperatureFormat();
$data['humidity_chart'] = $this->Dashboard_model->get_humidity_chart_data();
$data['moisture_chart'] = $this->Dashboard_model->get_moisture_chart_data();
$data['chart_legend'] = $this->Dashboard_model->get_chart_legend();
// Page View
$this->load->view('dashboard/index', $data);

} else {
// Redirect to login.
redirect('/login');
Expand All @@ -81,11 +88,11 @@ public function editGrowRoomSettings()
{
// Set climate threshold
$this->Climate_model->setClimateThreshold();

// Change lighting schedule in DB
$lightsON = $this->Lights_model->setLightTimerON();
$lightsOFF = $this->Lights_model->setLightTimerOFF();

// Edit lighting CRON
$this->Scheduler_model->editLightsCRON($lightsON, $lightsOFF);

Expand All @@ -94,9 +101,9 @@ public function editGrowRoomSettings()

// Set Pump schedule
$this->Pump_model->setPumpSchedule();

redirect($_SERVER['HTTP_REFERER']);

} else {
// Redirect to login.
redirect('/login');
Expand All @@ -112,7 +119,7 @@ public function latestPhoto()
$filename = $this->Camera_model->takePhoto();

redirect(asset_url() . "tmp/". $filename);

} else {
// Redirect to login.
redirect('/login');
Expand All @@ -124,7 +131,7 @@ public function reset()
{
// Page View
$this->load->view('auth/reset');

}

}
Expand Down
182 changes: 161 additions & 21 deletions app/application/models/Dashboard_model.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ public function get_user_info()
// Get user ID for current user logged in
$user = $this->ion_auth->user()->row();
$id = $user->id;

// Fetch user record from the database
$this->db->select('*');
$this->db->from('users');
$this->db->where(array('users.id' => $id));

// Return the result as array
$query = $this->db->get();
return $query->result();
}

// Get latest grow data
public function get_latest_grow_data()
{
$this->db->select("*");
$this->db->from("grow_data");
$this->db->order_by("id","DESC");
$this->db->order_by("id DESC");
$this->db->limit(1);

$query = $this->db->get();
Expand All @@ -55,6 +55,7 @@ public function get_latest_grow_data()
"moisture_status" => $grow_data["moisture_status"],
"fan_status" => $grow_data["fan_status"],
"pump_status" => $grow_data["pump_status"],
"moisture" => $grow_data["moisture"],
);

return $data;
Expand All @@ -76,15 +77,127 @@ public function get_sensor_activation_state()
return $data;
}


// Get 24-hr temperature chart data
public function get_temperature_chart7_data()
{
$tempFormat = $this->Climate_model->getTemperatureFormat();

$this->db->select("date_time, round(avg(temperature)) as temperature");
$this->db->from("grow_data");
$this->db->group_by("day( date_time )");
$this->db->order_by("date_time");
$this->db->limit(7);
$query = $this->db->get();
$results = $query->result_array();

$output = "";
$count = 1;
foreach($results as $result) {
if ($count == count($results)) {
if ($tempFormat == "F") {
$output .= celsiusToFahrenheit($result["temperature"]);
} else {
$output .= $result["temperature"];
}
} else {
if ($tempFormat == "F") {
$output .= celsiusToFahrenheit($result["temperature"]) . ", ";
} else {
$output .= $result["temperature"] . ", ";
}
}
$count++;
}

return $output;
}

// Get 24-hr humidity chart data
public function get_humidity_chart7_data()
{
$this->db->select("date_time, round(avg(humidity)) as humidity");
$this->db->from("grow_data");
$this->db->group_by("day( date_time )");
$this->db->order_by("date_time");
$this->db->limit(7);
$query = $this->db->get();
$results = $query->result_array();

$output = "";
$count = 1;
foreach($results as $result) {
if ($count == count($results)) {
$output .= $result["humidity"];
} else {
$output .= $result["humidity"] . ", ";
}
$count++;
}

return $output;
}

// Get 24-hr moisture chart data
public function get_moisture_chart7_data()
{
$this->db->select("date_time, round(avg(moisture)) as moisture");
$this->db->from("grow_data");
$this->db->group_by("day( date_time )");
$this->db->order_by("date_time");
$this->db->limit(7);
$query = $this->db->get();
$results = $query->result_array();

$output = "";
$count = 1;
foreach($results as $result) {
if ($count == count($results)) {
$output .= $result["moisture"];
} else {
$output .= $result["moisture"] . ", ";
}
$count++;
}

return $output;
}

// Get chart legend
public function get_chart_legend7()
{
$this->db->select("date_time");
$this->db->from("grow_data");
$this->db->group_by("day( date_time )");
$this->db->order_by("date_time");
$this->db->limit(7);
$query = $this->db->get();
$results = $query->result_array();

$output = "";
$count = 1;
foreach($results as $result) {
if ($count == count($results)) {
$output .= "\"" . date_format(date_create($result["date_time"]), "M d") . "\"";
} else {
$output .= "\"" . date_format(date_create($result["date_time"]), "M d") . "\"" . ", ";
}
$count++;
}

return $output;
}

// Get 24-hr temperature chart data
public function get_temperature_chart_data()
{
$tempFormat = $this->Climate_model->getTemperatureFormat();

$this->db->select("*");
$this->db->from("climate_history");
$this->db->order_by("id","DESC");
$this->db->limit(24);
$this->db->select("date_time, round(avg(temperature)) as temperature");
$this->db->from("grow_data");
$this->db->group_by("hour( date_time ), day( date_time )");
$this->db->order_by("date_time");
$this->db->limit(48);

$query = $this->db->get();
$results = $query->result_array();
Expand Down Expand Up @@ -114,10 +227,11 @@ public function get_temperature_chart_data()
// Get 24-hr humidity chart data
public function get_humidity_chart_data()
{
$this->db->select("*");
$this->db->from("climate_history");
$this->db->order_by("id","DESC");
$this->db->limit(24);
$this->db->select("date_time, round(avg(humidity)) as humidity");
$this->db->from("grow_data");
$this->db->group_by("hour( date_time ), day( date_time )");
$this->db->order_by("date_time");
$this->db->limit(48);

$query = $this->db->get();
$results = $query->result_array();
Expand All @@ -136,13 +250,39 @@ public function get_humidity_chart_data()
return $output;
}

// Get 24-hr moisture chart data
public function get_moisture_chart_data()
{
$this->db->select("date_time, round(avg(moisture)) as moisture");
$this->db->from("grow_data");
$this->db->group_by("hour( date_time ), day( date_time )");
$this->db->order_by("date_time");
$this->db->limit(48);
$query = $this->db->get();
$results = $query->result_array();

$output = "";
$count = 1;
foreach($results as $result) {
if ($count == count($results)) {
$output .= $result["moisture"];
} else {
$output .= $result["moisture"] . ", ";
}
$count++;
}

return $output;
}

// Get chart legend
public function get_chart_legend()
{
$this->db->select("*");
$this->db->from("climate_history");
$this->db->order_by("id","DESC");
$this->db->limit(24);
$this->db->select("date_time");
$this->db->from("grow_data");
$this->db->group_by("hour( date_time ), day( date_time )");
$this->db->order_by("date_time");
$this->db->limit(48);

$query = $this->db->get();
$results = $query->result_array();
Expand Down Expand Up @@ -256,8 +396,8 @@ public function get_cropThresholds()
// Current Crop Conditions
public function get_cropConditions()
{
$sql = "SELECT * FROM grow_data WHERE DATE(date_time) = CURDATE() ORDER BY date_time DESC";

$sql = "SELECT * FROM grow_data WHERE DATE(date_time) = CURDATE() ORDER BY date_time ASC";
$query = $this->db->query($sql);
$tempData = $query->result_array();

Expand All @@ -271,7 +411,7 @@ public function get_cropConditions()
// Loop through tempData
$total_records = sizeof($tempData);
$positive_records = 0;

foreach ($tempData as $item) {
$temp = $item['temperature'];
$humid = $item['humidity'];
Expand All @@ -289,7 +429,7 @@ public function get_cropConditions()
}

}

}

?>
?>
Loading