Hello guys.. I recently bought an Arduino Uno and Ethernet shield to make a project for graduation project..
We will control a Smart Home with an arduino using an ip adress (and later with smartphone app)..
I tried many many ways to programm it but every way has it's problems...
Anyway i want to write the page with html/css/php but i can't figure out how to make arduino understand the php....For example my control panel's code is something like :
<!DOCTYPE html>
<!-- PHP Way -->
<html>
<head>
<title>Smart Home</title>
<style>
body {background-color: #000000; color: green;}
h1 {text-align: center; font-style: italic; font-size: 26pt; margin: 50px 0px;}
table {width:620px; height:240px; font-size: 16pt; position:relative; margin:auto;}
table th {font-size: 20pt; text-decoration: underline;}
</style>
</head>
<body>
<?php
$roomStatus = array("RoomOneStatus" => FALSE, "RoomTwoStatus" => FALSE,
"bathroomStatus" => FALSE, "kitchenStatus" => FALSE,
"livingRoomStatus" => FALSE, "hallwayStatus" => FALSE,
"gardenStatus" => FALSE,);
if (!$roomStatus["RoomOneStatus"]) {
$roomOne = "Disabled";
$style1 = "color:red;";
}
else {
$roomOne = "Enabled";
$style1 = "color:green;";
}
if (!$roomStatus["RoomTwoStatus"]) {
$roomTwo = "Disabled";
$style2 = "color:red;";
}
else {
$roomTwo = "Enabled";
$style2 = "color:green;";
}
if (!$roomStatus["bathroomStatus"]) {
$bathroom = "Disabled";
$style3 = "color:red;";
}
else {
$bathroom = "Enabled";
$style3 = "color:green;";
}
if (!$roomStatus["kitchenStatus"]) {
$kitchen = "Disabled";
$style4 = "color:red;";
}
else {
$kitchen = "Enabled";
$style4 = "color:green;";
}
if (!$roomStatus["livingRoomStatus"]) {
$livingRoom = "Disabled";
$style5 = "color:red;";
}
else {
$livingRoom = "Enabled";
$style5 = "color:green;";
}
if (!$roomStatus["hallwayStatus"]) {
$hallway = "Disabled";
$style6 = "color:red;";
}
else {
$hallway = "Enabled";
$style6 = "color:green;";
}
if (!$roomStatus["gardenStatus"]) {
$garden = "Disabled";
$style7 = "color:red;";
}
else {
$garden = "Enabled";
$style7 = "color:green;";
}
?>
<h1> Smart Home Control Panel </h1>
<table border = "7" cellspacing = "10">
<th>Rooms</th>
<th>Device</th>
<th>Status</th>
<tr>
<td>Room One</td>
<td>Lights</td>
<td style = "<?php echo $style1?>"><?php echo $roomOne ?></td>
</tr>
<tr>
<td>Room Two</td>
<td>Lights</td>
<td style = "<?php echo $style2?>"><?php echo $roomTwo ?></td>
</tr>
<tr>
<td>Bathroom</td>
<td>Lights</td>
<td style = "<?php echo $style3?>"><?php echo $bathroom ?></td>
</tr>
<tr>
<td>Kitchen</td>
<td>Lights</td>
<td style = "<?php echo $style4?>"><?php echo $kitchen ?></td>
</tr>
<tr>
<td>Living Room</td>
<td>Lights</td>
<td style = "<?php echo $style5?>"><?php echo $livingRoom ?></td>
</tr>
<tr>
<td>Hallway</td>
<td>Lights</td>
<td style = "<?php echo $style6?>"><?php echo $hallway ?></td>
</tr>
<tr>
<td>Garden</td>
<td>Lights</td>
<td style = "<?php echo $style7?>"><?php echo $garden ?></td>
</tr>
</table>
<button style=\"width:120px;height:60px\"> <font size=\"3\"; color:red ;>Room One ON </font> </button> </a>
<button style=\"width:120px;height:60px\"> <font size=\"3\"; color:red ;>Room One OFF </font> </button> </a>
</body>
</html>
and my arduino sketch is :
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,5);
EthernetServer server(80);
File webFile;
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
Serial.begin(9600);
// initialize SD card
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("ERROR - SD card initialization failed!");
return; // init failed
}
Serial.println("SUCCESS - SD card initialized.");
if (!SD.exists("arduino.php")) {
Serial.println("ERROR - Can't find arduino.php file!");
return;
}
Serial.println("SUCCESS - Found arduino.php file.");
}
void loop()
{
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
// send web page
webFile = SD.open("arduino.php"); // open web page php file
if (webFile) {
while(webFile.available()) {
client.write(webFile.read()); // send web page to client
}
webFile.close();
}
break;
}
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1);
client.stop();
} // end if (client)
}
But as you can imagine doesnt work...When i go to 192.168.1.5 the browser reads php as text...
Is there anyone with some free time and experiance to help me cause as you may realised i am hardly stuck ![]()
Thanks in advance...
EDIT: But the way i am still in designing the html table...After figuring out how arduino can read the php ill move on writing the statements to turn on and off the leds.(Dunno how yet but lets get some things first) ![]()