Permalink
Browse files

added device id creation in util, added more events to simulator

  • Loading branch information...
1 parent 7f62c82 commit 076456ca4c017e4d73b762eefde5967143459bf1 @Bhavya committed Mar 20, 2012
Showing with 91 additions and 49 deletions.
  1. +26 −1 shared/util.php
  2. +44 −44 simulator/HomosDeviceSimulator.Designer.cs
  3. +10 −0 simulator/HomosDeviceSimulator.cs
  4. +10 −3 site/ajax.php
  5. +1 −1 site/device_info.php
View
@@ -1,4 +1,8 @@
<?php
+ include '../shared/lights.php';
+ include '../shared/house.php';
+ include '../shared/floodlights.php';
+ include '../shared/temperature.php';
function db_connect() {
$link = mysql_connect('localhost', 'karmabub_homos', 'homos');
@@ -174,7 +178,7 @@ function s_dec($s)
}
function renderDoorData($house_id){
-
+
}
function renderMotionData($house_id){
@@ -187,12 +191,33 @@ function renderCameraData($house_id){
}
function renderLightsData($house_id){
+ $lights = new LightsRecord();
+ $allLights = $lights->load($house_id);
+ foreach ($allLights as $singleLight) {
+ echo $singleLight->getDevice();
+ }
+ }
+ function insertLightsData($house_id, $state, $deviceId){
+ $lights = new LightsRecord();
+ $allLights = $lights->setState($state, $deviceId, $house_id);
}
+
function renderTemperatureData($house_id){
}
function renderPowerData($house_id){
}
+
+ function fetchDeviceId($house_id, $place, $type) {
+ $result = mysql_query("SELECT * FROM device_info WHERE house_id='$house_id' AND room='$place'") or die(mysql_error());
+ $row = mysql_fetch_array( $result );
+ $device_id = $row['device_id'];
+ if(!$result) {
+ $device_id = rand();
+ mysql_query("INSERT INTO device_info (device_id, device_type, house_id, room) VALUES ('$device_id', '$type', $house_id', '$place')") or die(mysql_error());
+ }
+ return $device_id;
+ }
?>

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -33,11 +33,13 @@ private void btnLightsKitchen_Click(object sender, EventArgs e)
{
btnLightsKitchen.BackColor = System.Drawing.Color.Yellow;
btnLightsKitchen.Text = "Lights (on)";
+ enableWebRequest("update=lights&place=Kitchen&state=1&id=" + houseID.Text);
}
else
{
btnLightsKitchen.BackColor = SystemColors.Control;
btnLightsKitchen.Text = "Lights";
+ enableWebRequest("update=lights&place=Kitchen&state=0&id=" + houseID.Text);
}
lightsKitchen = !lightsKitchen;
}
@@ -48,11 +50,13 @@ private void btnLightsLivingroom_Click(object sender, EventArgs e)
{
btnLightsLivingroom.BackColor = System.Drawing.Color.Yellow;
btnLightsLivingroom.Text = "Lights (on)";
+ enableWebRequest("update=lights&place=Livingroom&state=1&id=" + houseID.Text);
}
else
{
btnLightsLivingroom.BackColor = SystemColors.Control;
btnLightsLivingroom.Text = "Lights";
+ enableWebRequest("update=lights&place=Livingroom&state=0&id=" + houseID.Text);
}
lightsLivingroom = !lightsLivingroom;
}
@@ -63,11 +67,13 @@ private void btnLightsStudy_Click(object sender, EventArgs e)
{
btnLightsStudy.BackColor = System.Drawing.Color.Yellow;
btnLightsStudy.Text = "Lights (on)";
+ enableWebRequest("update=lights&place=Study&state=1&id=" + houseID.Text);
}
else
{
btnLightsStudy.BackColor = SystemColors.Control;
btnLightsStudy.Text = "Lights";
+ enableWebRequest("update=lights&place=Study&state=0&id=" + houseID.Text);
}
lightsStudy = !lightsStudy;
}
@@ -94,11 +100,13 @@ private void btnBedroom_Click(object sender, EventArgs e)
{
btnBedroom.BackColor = System.Drawing.Color.Yellow;
btnBedroom.Text = "Lights (on)";
+ enableWebRequest("update=lights&place=Bedroom&state=1&id=" + houseID.Text);
}
else
{
btnBedroom.BackColor = SystemColors.Control;
btnBedroom.Text = "Lights";
+ enableWebRequest("update=lights&place=Bedroom&state=0&id=" + houseID.Text);
}
lightsBedroom = !lightsBedroom;
}
@@ -109,11 +117,13 @@ private void btnGuestroom_Click(object sender, EventArgs e)
{
btnGuestroom.BackColor = System.Drawing.Color.Yellow;
btnGuestroom.Text = "Lights (on)";
+ enableWebRequest("update=lights&place=Guestroom&state=1&id=" + houseID.Text);
}
else
{
btnGuestroom.BackColor = SystemColors.Control;
btnGuestroom.Text = "Lights";
+ enableWebRequest("update=lights&place=Guestroom&state=0&id=" + houseID.Text);
}
lightsGuestroom = !lightsGuestroom;
}
View
@@ -69,18 +69,25 @@
switch($sensor) {
case "door":
renderDoorData($house_id);
+ $place = $_GET['place'];
+ registerLoggedEvent($house_id, date("F j, Y, g:i a"), "$place Door unlocked.");
break;
case "motion":
- renderMotionData($house_id);
+ registerLoggedEvent($house_id, date("F j, Y, g:i a"), "Motion detected outside house. Security alerted.");
break;
case "floodlight":
registerLoggedEvent($house_id, date("F j, Y, g:i a"), 'Floodlight engaged.');
break;
case "camera":
- renderCameraData($house_id);
+ $place = $_GET['place'];
+ registerLoggedEvent($house_id, date("F j, Y, g:i a"), "$place Camera enabled.");
break;
case "lights":
- renderLightsData($house_id);
+ $place = $_GET['place'];
+ $state = "off";
+ if($_GET['state']==1) $state ="on";
+ insertLightsData($house_id, $state, fetchDeviceId($house_id, $place, $sensor));
+ registerLoggedEvent($house_id, date("F j, Y, g:i a"), "$place Light $state.");
break;
case "temperature":
renderTemperatureData($house_id);
View
@@ -24,7 +24,7 @@
$.ajaxSetup ({
cache: false
});
- var ajax_load = "<CENTER>Please wait while your feed is being generated.<br /><img src='img/load.gif' alt='loading...' /></CENTER>";
+ var ajax_load = "<CENTER>Please wait while your data is being fetched.<br /><img src='img/load.gif' alt='loading...' /></CENTER>";
<?php
$query = "SELECT * FROM update_spam WHERE house_id='$house_id'";
$query = s_enc($query);

0 comments on commit 076456c

Please sign in to comment.