I changed the code the way I understood u mean it, but still not recieving post data...
I would debug it more myself, but dont actually have the arduino board, im sending this stuff to someone else to check...
This is what I get in the serial monitor...
Ready
Client request: GET /favicon.ico HTTP/1.1
POST data:
Sending response
Returning Information to server...
adjusting lights...
adjust light function starting with val:0
and that "GET /favicon.ico HTTP/1.1" makes me think they are using the wrong script on the server now, but any how, would appreciate a code check for me.
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {0x1c, 0x26, 0x0c, 0x98, 0x22, 0x85 };
byte ip[] = {192, 168, 1 , 20 };
byte gateway[] = {192, 168, 1, 1 };
byte subnet[] = {255, 255, 255, 0 };
EthernetServer server(80);
const int photocellPin = A0;
int photocellReading;
const float Res=10.0;
const int Pin9 = 9;
const int Pin8 = 8;
const int Pin7 = 7;
int lux = 0;
int val;
int lightlux = 0;
int lightvol = 0;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip, gateway, subnet);
pinMode(Pin9, OUTPUT);
pinMode(Pin8, OUTPUT);
pinMode(Pin7, OUTPUT);
pinMode(photocellPin, INPUT);
delay(2000);
server.begin();
Serial.println("Ready");
}
void loop()
{
EthernetClient client = server.available();
if(client) {
boolean currentLineIsBlank = true;
boolean currentLineIsGet = true;
int tCount = 0;
char tBuf[64];
int a,b;
char *pch;
Serial.print("Client request: ");
while (client.connected()) {
while(client.available()) {
char c = client.read();
if(currentLineIsGet && tCount < 63)
{
tBuf[tCount] = c;
tCount++;
tBuf[tCount] = 0;
}
if (c == '\n' && currentLineIsBlank) {
Serial.println(tBuf);
// retrieve the POST data
Serial.print("POST data: ");
while(client.available()) Serial.write(client.read());
Serial.println();
pch = strtok(tBuf,"?");
while(pch != NULL)
{
if(strncmp(pch,"a=",2) == 0)
{
a = atoi(pch+2);
lightlux = a;
lightvol = 51*(lightlux/1333);
Serial.print("Lux a=");
Serial.println(a,DEC);
Serial.print("Lightlux:");
Serial.print(lightvol);
}
if(strncmp(pch,"b=",2) == 0)
{
b = atoi(pch+2);
val = b;
Serial.print("Lights b=");
Serial.println(b,DEC);
}
pch = strtok(NULL,"& ");
}
Serial.println("Sending response");
Serial.print("Returning Information to server...");
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
photocellReading = analogRead(photocellPin);
float Vout=photocellReading*0.0048828125;
lux=500/(Res*((5-Vout)/Vout));
client.print("Lux Value is : ");
client.print(lux);
client.print(" Current Voltage is: ");
client.print(lightvol);
client.print(" END");
client.println("
");
client.stop();
}
else if (c == '\n') {
currentLineIsBlank = true;
currentLineIsGet = false;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
if (val != 0) {
Serial.print("adjusting lights...");
while (lightlux < lux){
lightvol = lightvol + .1;
adjustlight();
}
while (lightlux > lux){
lightvol = lightvol - .1;
adjustlight();
}
}
Serial.println("done");
}
}
void adjustlight() {
Serial.print("adjust light function starting with val: ");
Serial.print(val);
if (val == '000') { analogWrite(Pin9, LOW);analogWrite(Pin8, LOW);analogWrite(Pin7, LOW);}
if (val == '111') { analogWrite(Pin9, lightvol);analogWrite(Pin8, lightvol);analogWrite(Pin7, lightvol);}
if (val == '100') { analogWrite(Pin9, lightvol);analogWrite(Pin8, LOW);analogWrite(Pin7, LOW);}
if (val == '010') { analogWrite(Pin9, LOW);analogWrite(Pin8, lightvol);analogWrite(Pin7, LOW);}
if (val == '001') { analogWrite(Pin9, LOW);analogWrite(Pin8, LOW);analogWrite(Pin7, lightvol);}
if (val == '110') { analogWrite(Pin9, lightvol);analogWrite(Pin8, lightvol);analogWrite(Pin7, LOW);}
if (val == '011') { analogWrite(Pin9, LOW);analogWrite(Pin8, lightvol);analogWrite(Pin7, lightvol);}
photocellReading = analogRead(photocellPin);
float Vout=photocellReading*0.0048828125;
lux=500/(Res*((5-Vout)/Vout));
}