Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 076456ca4c017e4d73b762eefde5967143459bf1 1 parent 7f62c82
@Bhavya authored
View
27 shared/util.php
@@ -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;
+ }
?>
View
88 simulator/HomosDeviceSimulator.Designer.cs
@@ -33,16 +33,16 @@ private void InitializeComponent()
this.houseIDLabel = new System.Windows.Forms.Label();
this.btnSystemEnable = new System.Windows.Forms.Button();
this.outside = new System.Windows.Forms.GroupBox();
- this.button6 = new System.Windows.Forms.Button();
+ this.btnGarageDoor = new System.Windows.Forms.Button();
this.btnFloodlights = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.button1 = new System.Windows.Forms.Button();
+ this.btnKitchenDoor = new System.Windows.Forms.Button();
this.btnLightsKitchen = new System.Windows.Forms.Button();
this.groupBox3 = new System.Windows.Forms.GroupBox();
- this.button3 = new System.Windows.Forms.Button();
+ this.btnFrontDoor = new System.Windows.Forms.Button();
this.btnLightsLivingroom = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.button2 = new System.Windows.Forms.Button();
+ this.btnStudyDoor = new System.Windows.Forms.Button();
this.btnLightsStudy = new System.Windows.Forms.Button();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.button4 = new System.Windows.Forms.Button();
@@ -95,7 +95,7 @@ private void InitializeComponent()
//
// outside
//
- this.outside.Controls.Add(this.button6);
+ this.outside.Controls.Add(this.btnGarageDoor);
this.outside.Controls.Add(this.btnFloodlights);
this.outside.Location = new System.Drawing.Point(15, 49);
this.outside.Name = "outside";
@@ -104,15 +104,15 @@ private void InitializeComponent()
this.outside.TabStop = false;
this.outside.Text = "Outside";
//
- // button6
+ // btnGarageDoor
//
- this.button6.BackColor = System.Drawing.SystemColors.Control;
- this.button6.Location = new System.Drawing.Point(150, 19);
- this.button6.Name = "button6";
- this.button6.Size = new System.Drawing.Size(123, 40);
- this.button6.TabIndex = 10;
- this.button6.Text = "Lights";
- this.button6.UseVisualStyleBackColor = false;
+ this.btnGarageDoor.BackColor = System.Drawing.SystemColors.Control;
+ this.btnGarageDoor.Location = new System.Drawing.Point(150, 19);
+ this.btnGarageDoor.Name = "btnGarageDoor";
+ this.btnGarageDoor.Size = new System.Drawing.Size(123, 40);
+ this.btnGarageDoor.TabIndex = 10;
+ this.btnGarageDoor.Text = "Garage Door";
+ this.btnGarageDoor.UseVisualStyleBackColor = false;
//
// btnFloodlights
//
@@ -127,7 +127,7 @@ private void InitializeComponent()
//
// groupBox2
//
- this.groupBox2.Controls.Add(this.button1);
+ this.groupBox2.Controls.Add(this.btnKitchenDoor);
this.groupBox2.Controls.Add(this.btnLightsKitchen);
this.groupBox2.Location = new System.Drawing.Point(15, 120);
this.groupBox2.Name = "groupBox2";
@@ -136,15 +136,15 @@ private void InitializeComponent()
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Kitchen";
//
- // button1
+ // btnKitchenDoor
//
- this.button1.BackColor = System.Drawing.SystemColors.Control;
- this.button1.Location = new System.Drawing.Point(21, 65);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(123, 40);
- this.button1.TabIndex = 10;
- this.button1.Text = "Lights";
- this.button1.UseVisualStyleBackColor = false;
+ this.btnKitchenDoor.BackColor = System.Drawing.SystemColors.Control;
+ this.btnKitchenDoor.Location = new System.Drawing.Point(21, 65);
+ this.btnKitchenDoor.Name = "btnKitchenDoor";
+ this.btnKitchenDoor.Size = new System.Drawing.Size(123, 40);
+ this.btnKitchenDoor.TabIndex = 10;
+ this.btnKitchenDoor.Text = "Back Door";
+ this.btnKitchenDoor.UseVisualStyleBackColor = false;
//
// btnLightsKitchen
//
@@ -159,7 +159,7 @@ private void InitializeComponent()
//
// groupBox3
//
- this.groupBox3.Controls.Add(this.button3);
+ this.groupBox3.Controls.Add(this.btnFrontDoor);
this.groupBox3.Controls.Add(this.btnLightsLivingroom);
this.groupBox3.Location = new System.Drawing.Point(188, 120);
this.groupBox3.Name = "groupBox3";
@@ -168,15 +168,15 @@ private void InitializeComponent()
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Livingroom";
//
- // button3
+ // btnFrontDoor
//
- this.button3.BackColor = System.Drawing.SystemColors.Control;
- this.button3.Location = new System.Drawing.Point(17, 65);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(123, 40);
- this.button3.TabIndex = 10;
- this.button3.Text = "Lights";
- this.button3.UseVisualStyleBackColor = false;
+ this.btnFrontDoor.BackColor = System.Drawing.SystemColors.Control;
+ this.btnFrontDoor.Location = new System.Drawing.Point(17, 65);
+ this.btnFrontDoor.Name = "btnFrontDoor";
+ this.btnFrontDoor.Size = new System.Drawing.Size(123, 40);
+ this.btnFrontDoor.TabIndex = 10;
+ this.btnFrontDoor.Text = "Front Door";
+ this.btnFrontDoor.UseVisualStyleBackColor = false;
//
// btnLightsLivingroom
//
@@ -191,7 +191,7 @@ private void InitializeComponent()
//
// groupBox1
//
- this.groupBox1.Controls.Add(this.button2);
+ this.groupBox1.Controls.Add(this.btnStudyDoor);
this.groupBox1.Controls.Add(this.btnLightsStudy);
this.groupBox1.Location = new System.Drawing.Point(15, 248);
this.groupBox1.Name = "groupBox1";
@@ -200,15 +200,15 @@ private void InitializeComponent()
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Study";
//
- // button2
+ // btnStudyDoor
//
- this.button2.BackColor = System.Drawing.SystemColors.Control;
- this.button2.Location = new System.Drawing.Point(21, 82);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(123, 40);
- this.button2.TabIndex = 11;
- this.button2.Text = "Lights";
- this.button2.UseVisualStyleBackColor = false;
+ this.btnStudyDoor.BackColor = System.Drawing.SystemColors.Control;
+ this.btnStudyDoor.Location = new System.Drawing.Point(21, 82);
+ this.btnStudyDoor.Name = "btnStudyDoor";
+ this.btnStudyDoor.Size = new System.Drawing.Size(123, 40);
+ this.btnStudyDoor.TabIndex = 11;
+ this.btnStudyDoor.Text = "Door";
+ this.btnStudyDoor.UseVisualStyleBackColor = false;
//
// btnLightsStudy
//
@@ -342,10 +342,10 @@ private void InitializeComponent()
private System.Windows.Forms.Button btnBedroom;
private System.Windows.Forms.Button btnGuestroom;
private System.Windows.Forms.Button btnFloodlights;
- private System.Windows.Forms.Button button6;
- private System.Windows.Forms.Button button1;
- private System.Windows.Forms.Button button3;
- private System.Windows.Forms.Button button2;
+ private System.Windows.Forms.Button btnGarageDoor;
+ private System.Windows.Forms.Button btnKitchenDoor;
+ private System.Windows.Forms.Button btnFrontDoor;
+ private System.Windows.Forms.Button btnStudyDoor;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button test;
View
10 simulator/HomosDeviceSimulator.cs
@@ -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
13 site/ajax.php
@@ -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
2  site/device_info.php
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.