Ok, I just got everything (to my knowledge) up server side.
I have run into a problem (no big surprise) and I have realized that I have not thoroughly explained what we are working with.
I am currently running server 2012 r2 on a dell server that is hosting this local php site on IIS8.
Here is the main code for the website:
<html>
<head>
<title>Home Automation Control Panel</title>
<script type="text/JavaScript" src="scripts/jquery.js"></script>
<script type="text/JavaScript" src="scripts/js/jquery-ui-1.8.2.custom.min.js"></script>
<link type="text/css" href="scripts/css/start/jquery-ui-1.8.2.custom.css" rel="stylesheet" />
<script type="text/javascript">
//makes pretty buttons from theme
$(function() {
$("input:submit").button();
});
</script>
<script type="text/JavaScript">
$(document).ready(function(){
//loads status on page ready
$("#led8").load("middle.php", "a=get8");
$("#led3").load("middle.php", "a=get3");
//refreshes the statuses
var refreshId = setInterval(function() {
$("#led8").load("middle.php", "a=get8");
$("#led3").load("middle.php", "a=get3");
}, 2000);
//led8 get and toggle when clicked
$("#led8button").click(function(){
$("#led8").load("middle.php", "a=get8&l=toggle8");
});
//led3 get and toggle when clicked
$("#led3button").click(function(){
$("#led3").load("middle.php", "a=get3&l=toggle3");
});
//end
});
</script>
<script type="text/javascript">
//accordion code set to mouseover and no autoheight
$(function() {
$("#accordion").accordion({
event: "mouseover",
autoHeight: false
});
});
</script>
</head>
<body>
<div id=accordion style="width:250px;">
<h3><a href="#">Lights</a></h3>
<div>
<div style="text-align: center;" class="ui-widget-content">
LED8<div id="led8"><IMG SRC="images/ajax-loader.gif"></div>
<input type=submit id=led8button value=Toggle>
</div>
<div style="text-align: center;" class="ui-widget-content">
LED3<div id="led3"><IMG SRC="images/ajax-loader.gif"></div>
<input type=submit id=led3button value=Toggle>
</div>
</div>
<h3><a href="#">Locks</a></h3>
<div>
<IMG SRC="images/ajax-loader.gif">
</div>
<h3><a href="#">A/C</a></h3>
<div>
<IMG SRC="images/ajax-loader.gif">
</div>
</div>
</body>
</html>
In this code it also references 'middle.php' that I will post here:
<?php
if($_GET[l] == "toggle8")
{
include("http://192.168.1.31/?l=toggle8");
}
if($_GET[l] == "toggle3")
{
include("http://192.168.1.31/?l=toggle3");
}
if($_GET[a] == "get8")
{
include("http://192.168.1.31/?a=get8");
}
if($_GET[a] == "get3")
{
include("http://192.168.1.31/?a=get3");
}
?>
These two pieces of html/php are supposed to send php to the arduino and relays.
Here is the code for the arduino:
#define RELAY1 2
#define RELAY2 3
#define RELAY3 4
#define RELAY4 5
#define RELAY5 6
#define RELAY6 7
#define RELAY7 8
#define RELAY8 9
#include <SPI.h>
#include <WString.h>
#include <Ethernet.h>
byte mac[] = { 0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 31 };
EthernetServer server(80);
String readString = String(30);
void setup()
{
// Initialise the Arduino data pins for OUTPUT
Serial.begin(9600);
Ethernet.begin(mac, ip);
pinMode(RELAY1, OUTPUT); digitalWrite(1,HIGH);
pinMode(RELAY2, OUTPUT); digitalWrite(2,HIGH);
pinMode(RELAY3, OUTPUT); digitalWrite(3,HIGH);
pinMode(RELAY4, OUTPUT); digitalWrite(4,HIGH);
pinMode(RELAY5, OUTPUT); digitalWrite(5,HIGH);
pinMode(RELAY6, OUTPUT); digitalWrite(6,HIGH);
pinMode(RELAY7, OUTPUT); digitalWrite(7,HIGH);
pinMode(RELAY8, OUTPUT); digitalWrite(8,HIGH);
}
void loop(){
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (readString.length() < 100){
readString.concat(c);
}
if (c == '\n') {
if(readString.indexOf("led8")) {
toggle(RELAY8);
} else
if(readString.indexOf("led3")) {
toggle(RELAY3);
}
client.println("<html><center>");
client.println("Light 3
");
if (digitalRead(RELAY3) == LOW){
client.println("<img src='http://http://192.168.1.11/web/homeautomation/images/lightoff'>");
} else if (digitalRead(RELAY3) == HIGH){
client.println("<img src='http://http://192.168.1.11/web/homeautomation/images/lighton.png'>");
}
client.println("<form method='get'><input type=submit name=led3 value=toggle></form>");
client.println("Light 8
");
if (digitalRead(RELAY8) == LOW){
client.println("<img src='http://http://192.168.1.11/web/homeautomation/images/lightoff.png'>");
} else if (digitalRead(RELAY8) == HIGH){
client.println("<img src='http://http://192.168.1.11/web/homeautomation/images/lighton.png'>");
}
client.println("<form method='get'><input type=submit name=led8 value=toggle></form>");
client.println("</center></html>");
readString="";
client.stop();
}
}
}
}
}
int toggle(int pin){
if(digitalRead(pin) == LOW){
digitalWrite(pin, HIGH);
} else {
digitalWrite(pin, LOW);
}
}
// EOF *******************************
As it stands right now I can connect to the arduino through the IP i have assigned it and adjust the lights from there. However, I do not want this. I want to have the server/website send the arduino some php to then turn on and off the relays. an end result may have 5-6 different relays that the website will help stream line with out me having to type 192.168.1.31 for one set of lights but than having to type 192.168.1.33 for another, etc.
sorry for the long rant but now for the problem. I do not know why I am having this connection issue. I have no prior experience with php, so if anyone can potentially take a quick look and see if I am just a total scrub or something? Thank you!