Hi guys,
Let me make discuss my problem in detail:
Problem:
LED does not turn ON, even though it was clear that we sent a digitalWrite(4, HIGH) clearly.
Scenario:
We developed an arduino client that calls a webservice. The webservice simply replies "ACTIVE" if LED need to be ON
and "INACTIVE" if need to be OFF.
To our surprise, the webservice had clearly responded with "ACTIVE" led, and the arduino code had clearly went to the code section that
says digitalWrite(4,HIGH) but the LED does not lite. we are certain also that the LED works, as we can make it blink using the "blink sample tutorial"
hope you could help guys.
The actual CODE:
#include <SPI.h>
#include <Ethernet.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x6C,0x62,0x6D,0xEE,0x78,0x9D };
////
IPAddress server(XXX,XXX,XXX,XX);
String response = "";
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
int flag = 0;
int led = 4;
void setup() {
Serial.begin(9600);
pinMode(4,OUTPUT);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;![]()
;
}
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 8080)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /linkxxxxxxxxxxx/?xxxxxxx=xxxxx HTTP/1.0");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
char c;
c = client.read();
response += c;
}
if (!client.connected()) {
Serial.print(response);
Serial.println("\ndisconnecting.");
client.stop();
client.connect(server, 8080);
client.println("GET /seatmateapi/resources/constructionSites/isSiteActiveAndOccupied?macAddress=6C-62-6D-EE-78-9D HTTP/1.0");
client.println();
delay(1000);
if(response.indexOf("INACTIVE") > 0) {
if(flag == 1) {
Serial.println("LIGHTS OFF");
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
flag = 0;
}
}
else {
if(flag == 0) {
Serial.println("LIGHTS ON.");
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
flag = 1;
}
}
response = "";
}
}
The server actual RESPONSE
"ACTIVE"