I am new to programming micro-controllers but I feel this project is close to being successfull. The gist of it is that I can use my Arduino Uno (Rev 3) and Wifi Shield to monitor a door alarm. With the Arduino connected to my wireless network I should be able to use the board's IP address with a web browser (I have mainly used Chrome but tried Firefox, too) and see whether the door is opened or closed. The main issue is that I have only successfully done this once in numerous attempts (I seen the message "Alert! The door has been opened" for a brief second or two using Chrome web browser).

I believe that the main issue is that I am connecting and then disconnecting almost immediately from the server. But why? The one time I had that momentary success I had followed advice on a website that suggested that I go to Programs -> Java -> Temporary Internet Files -> Settings -> Restore Defaults -> Delete Files. That hasn't yielded the same positive results since.

I am using Windows 7 Professional with Arduino IDE 1.0.2 (I have read in numerous threads that this version works best with the Wifi Shield and I've already gone the other route with updating the IDE and Wifi firmware with overall less connection success despite a successful updating of the firmware).

Ok, I see where you are setting the status of the door. The only place where this occurs is in your interrupt handler. Now, we need to verify that the interrupt routine is being triggered. To do that, for a moment we have to look at the hardware.

Please post a schematic of everything connected to pin 2. You may think this is an irrelevant request, but please humor me.

Yes, in the project steps the author has this exact step which I completed successfully before moving on:

"Finally, let’s test the push button. We want to detect the state of the button, so we will use the function digitalRead(). Here is the sketch to test the button:"

Code (Text):

// Push button pin

int pushButton = 2;

// Setup

void setup() {

Serial.begin(9600);

}

// Main loop

void loop() {

// read the pin number 2

int buttonState = digitalRead(pushButton);

// print out the state of the button

Serial.println(buttonState);

delay(1);

}

"Now upload the sketch, and open the serial monitor. You should see a lot of zeros, which is logical because the pin number 2 is connected to the ground. Then, just push the button, and if you see ones like on the following screenshot, it is all good."

Are you using the Arduino IDE? If so in the bottom window, where I expect you are getting that error message, should indicate the line with the "stray" error. There is a button in the IDE that will copy all errors to the clipboard. Then you can paste them into an editor to get a better look. I'll be honest, never saw that "stray" error.

Not sure why it never compiled without error before but this time it did so without error.

Code (Text):

#include <SPI.h>

#include <WiFi.h>

char ssid[] = "yourNetwork"; // your network SSID (name)

char pass[] = "secretPassword"; // your network password

int status = WL_IDLE_STATUS;

boolean door_status = false;

WiFiServer server(80);

void setup() {

// start serial port for debugging purposes

Serial.begin(9600);

pinMode(2, INPUT);

// Attach interrupt to pin 2

attachInterrupt(0, setDoorStatus, RISING);

// attempt to connect to Wifi network:

while ( status != WL_CONNECTED) {

Serial.print("Attempting to connect to SSID: ");

Serial.println(ssid);

status = WiFi.begin(ssid, pass);

// wait 10 seconds for connection:

delay(10000);

}

server.begin();

// you're connected now, so print out the status:

printWifiStatus();

}

void loop() {

// listen for incoming clients

WiFiClient client = server.available();

if (client) {

Serial.println("new client");

// an http request ends with a blank line

boolean currentLineIsBlank = true;

while (client.connected()) {

if (client.available()) {

char c = client.read();

Serial.write(c);

// if you've gotten to the end of the line (received a newline

// character) and the line is blank, the http request has ended,

// so you can send a reply

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("Connnection: close");

client.println();

client.println("<!DOCTYPE HTML>");

client.println("<html>");

client.println("<meta http-equiv=\"refresh\" content=\"5\">");

if (door_status == false){

client.print("Everything is ok");

}

else {

client.print("Alert ! The door has been opened");

}

client.println("<br />");

client.println("</html>");

break;

}

if (c == '\n') {

// you're starting a new line

currentLineIsBlank = true;

}

else if (c != '\r') {

// you've gotten a character on the current line

currentLineIsBlank = false;

}

}

}

// give the web browser time to receive the data

delay(1);

// close the connection:

client.stop();

Serial.println("client disonnected");

}

}

void printWifiStatus() {

// print the SSID of the network you're attached to:

Serial.print("SSID: ");

Serial.println(WiFi.SSID());

// print your WiFi shield's IP address:

IPAddress ip = WiFi.localIP();

Serial.print("IP Address: ");

Serial.println(ip);

// print the received signal strength:

long rssi = WiFi.RSSI();

Serial.print("signal strength (RSSI):");

Serial.print(rssi);

Serial.println(" dBm");

}

void setDoorStatus() {

door_status = true;

}

After uploading the output in the Arduino IDE serial monitor was consistent. Once I tried connecting by entering the Sheild's IP address in Chrome's web browser it did the same as before:
"new client"
"client disconnected"

What is your problem? I see two. One, you cannot connect to your PC. Second, your alarm code does not work. Is this correct?

I have been addressing the latter.

For the former, I will make some general comments. I can't see yet why you are not sending the HTTP response. I had a couple of thought, but couldn't support them. I might insert a serial.print immediately before you send the HTTP response.

Your screen shot indicates that the browser is not receiving the HTTP response. Let's find out why!

Connect with Us

Sign Up

Quote of the day

“Electrical science has disclosed to us the more intimate relation existing between widely different forces and phenomena and has thus led us to a more complete comprehension of Nature and its many manifestations to our senses.”