Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: help with remote relay project (formerly html button problem) on: April 19, 2013, 04:26:06 pm
Haha, in trying to monitor and debug i actually caused bugs myself  smiley-eek-blue
thanks. it seems to work fine now but i think bounces still register, i guess that's a topic for the hardware forum.

i moved the readGET() function to a point before the transmission starts. thanks.

as to why use interrupts? there are going to be more triggers and i thought it was the way to go, i might be mistaken. i think interrupts are more elegant and give you more flexibility, am i wrong?
2  Using Arduino / Programming Questions / Re: html button only works on second click on: April 19, 2013, 04:06:52 pm
after solving the html button problem i need some assistance with a physical button problem. (i'll continue in this thread so as not to open multiple ones)

I've added an interrupt to toggle the LED at a button press. (I've never used interrupts, so any general advice is welcome)
the button is debounced via a R-C circuit and a schmitt-inverter (74hc14).

the problem is that after a few button presses (sometimes just one) the system seems to stall, not responding to button presses or html requests.
is there a chance that the button bounces still register, even though it doesn't show in the serial monitor? (i added a Serial.println inside the interrupt to see when the button is pressed).
what can cause this behavior?

this is the code:
Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,123,223);
EthernetServer server(12345);  
String HTTP_req;        
volatile boolean LED_status = false;  

void setup()
{
    Ethernet.begin(mac, ip);
    server.begin();        
    Serial.begin(9600);  
    pinMode(2, OUTPUT);
    attachInterrupt(1, Toggle, RISING);
}

void loop()
{
    EthernetClient client = server.available();
    if (client) {
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {
                char c = client.read();
                HTTP_req += c;
                if (c == '\n') {
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");
                    client.println();
                    client.println("<!DOCTYPE html>");
                    client.println("<html>");
                    client.println("<head>");
                    client.println("<title>Arduino Boiler Control</title>");
                    client.println("</head>");
                    client.println("<body>");            
                    client.println("<p>Click to switch Boiler on and off.</p>");
                    readGET(); //identify the request
                    Button(client); //display button according to current status
                    executeLED(); //change pin according to request
                    client.println("</form>");
                    if (LED_status){ //display status message according to current status
                    client.println("<h1>Boiler is ON</h1>");
                    } else client.println("<h1>Boiler is OFF</h1>");
                    client.println("</body>");
                    client.println("</html>");
                    Serial.print(HTTP_req);
                    HTTP_req = "";
                    break;
                }
                if (c == '\n') {
                    currentLineIsBlank = true;
                }else if (c != '\r') {
                    currentLineIsBlank = false;
                      }
            }
        }
        delay(1);
        client.stop();
    }
}

void Toggle(){ //interrupt function - toggles the pin and status indicator
Serial.println("POP"); //for debugging, to see if button bounces
LED_status=!LED_status;
executeLED();
}

void readGET(){
     if (HTTP_req.indexOf("ON?") > -1) {
         LED_status = true;
     }else if (HTTP_req.indexOf("OFF?") > -1){
         LED_status = false;
    }
}

void executeLED(){
  if (LED_status) {
    digitalWrite(2, HIGH);
  }else digitalWrite(2, LOW);
}

void Button(EthernetClient cl)
{
    if (LED_status) {
        cl.println("<form method=\"get\" action=\"/OFF\">");
        cl.println(" <button type=\"submit\">Turn OFF</button>");
    }else {
       cl.println("<form method=\"get\" action=\"/ON\">");
       cl.println(" <button type=\"submit\">Turn ON</button>");  
  }
}
3  Using Arduino / Programming Questions / Re: html button only works on second click on: April 19, 2013, 04:27:01 am
PeterH,
looking only in the first line of the request works, Thanks. hopefully it won't restrict me when trying some advanced options (if so, i'll try the other method).
4  Using Arduino / Programming Questions / Re: html button only works on second click on: April 18, 2013, 06:22:27 pm
the "toggle" function is called that for lack of a better fitting name at the time. (you can notice a "LED_status" variable even though there's no LED in the project - these are just temporary names)
the "toggle" function wasn't originally there, it was originally a part of the "button" function and moved where as part of trial and error for fixing the discussed problem.

this is what i get when accessing the webpage for the first time :
GET / HTTP/1.1
Host: 192.168.123.223:12345
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

GET /favicon.ico HTTP/1.1
Host: 192.168.123.223:12345
Connection: keep-alive
Accept: */*
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3


first click on the ON button (LED turns ON) :
GET /ON? HTTP/1.1
Host: 192.168.123.223:12345
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Referer: http://192.168.123.223:12345/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

GET /favicon.ico HTTP/1.1
Host: 192.168.123.223:12345
Connection: keep-alive
Accept: */*
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3


second click on the OFF button (LED stays ON) :
GET /OFF? HTTP/1.1
Host: 192.168.123.223:12345
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Referer: http://192.168.123.223:12345/ON?
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

GET /favicon.ico HTTP/1.1
Host: 192.168.123.223:12345
Connection: keep-alive
Accept: */*
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3


third click on the OFF button (LED turns OFF):
GET /OFF? HTTP/1.1
Host: 192.168.123.223:12345
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Referer: http://192.168.123.223:12345/OFF?
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

GET /favicon.ico HTTP/1.1
Host: 192.168.123.223:12345
Connection: keep-alive
Accept: */*
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
5  Using Arduino / Programming Questions / help with remote relay project (formerly html button problem) on: April 18, 2013, 05:39:16 pm
hi guys,
this project is at it's very start, the end result should be a network controlled Boiler (and maybe other devices in the future) with some advanced features.
i'm currently trying to get the basic functions to work before i start adding advanced ones.

the current setup is an arduino MEGA with an Ethernet Shield and a LED on pin 2 for testing.

the problem is turning the LED off. turning it on works fine, but in order to turn it off i need to click the button twice.
i looked at the HTTP requests via serial monitor and it seems that the LED changes only when the referrer is the "OFF" page. so when the LED is ON, one click brings up a page that seems like the "ON" page but has the "OFF" page's URL, only then the (second) button click will turn the LED off.

i suspect it has more to do with the HTML part then the Arduino code because that's the part i'm least familiar with (learning as i go) but i'm not sure.

what do you think?
thanks in advance!

my sketch:
Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,123,223);
EthernetServer server(12345);  
String HTTP_req;        
boolean LED_status = false;  
void setup()
{
    Ethernet.begin(mac, ip);
    server.begin();        
    Serial.begin(9600);  
    pinMode(2, OUTPUT);      
}
void loop()
{
    EthernetClient client = server.available();
    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {
                char c = client.read();
                HTTP_req += c;
                if (c == '\n' && currentLineIsBlank) {
                    Toggle();
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");
                    client.println();
                    client.println("<!DOCTYPE html>");
                    client.println("<html>");
                    client.println("<head>");
                    client.println("<title>Arduino Boiler Control</title>");
                    client.println("</head>");
                    client.println("<body>");            
                    client.println("<p>Click to switch Boiler on and off.</p>");
                    Button(client);
                    client.println("</form>");
                      if (LED_status){
                    client.println("<h1>Boiler is ON</h1>");
                    } else client.println("<h1>Boiler is OFF</h1>");
                    client.println("</body>");
                    client.println("</html>");
                    Serial.print(HTTP_req);
                    HTTP_req = "";
                    break;
                }
                if (c == '\n') {
                    currentLineIsBlank = true;
                }
                else if (c != '\r') {
      
                    currentLineIsBlank = false;
                }
            }
        }
        delay(1);
        client.stop();
    }
}

void Toggle(){
     if (HTTP_req.indexOf("ON?") > -1) {
         LED_status = true;
         digitalWrite(2, HIGH);
     }
    else if (HTTP_req.indexOf("OFF?") > -1){
         LED_status = false;
         digitalWrite(2, LOW);
    }
}

void Button(EthernetClient cl)
{
    if (LED_status) {
        cl.println("<form method=\"get\" action=\"/OFF\">");
        cl.println(" <button type=\"submit\">Turn OFF</button>");
    }
    else {
       cl.println("<form method=\"get\" action=\"/ON\">");
       cl.println(" <button type=\"submit\">Turn ON</button>");  
  }
}
6  Using Arduino / Interfacing w/ Software on the Computer / Re: receiving windows laptop battery level on: December 06, 2012, 06:31:30 pm
ok, I got the general idea.

i'll keep reading and try to make this work.

there's no arduino related problem yet because I haven't started working on this yet, I'm still in the planning phase. moreover, I don't want you to feed me the code.

if I have any more problems and questions, you''l know  smiley-wink

thanks.
7  Using Arduino / Interfacing w/ Software on the Computer / Re: receiving windows laptop battery level on: December 06, 2012, 05:08:37 pm
Hehe.. please, don't insult me.  smiley-roll
I tried looking for answers and hints on the web for a few days now, this is my last resort.

if you tried this and have real answers please share.
8  Using Arduino / Interfacing w/ Software on the Computer / receiving windows laptop battery level on: December 06, 2012, 03:03:41 pm
hi all,

I'm wondering if there's any way to send battery info (more specifically, battery level) from a windows laptop to an arduino. maybe via serial port (actually, any way of getting this info will be great)

I'm not talking about checking the battery voltage directly, like in simple battery indicators, I want to get real DATA from the computer.

Is there a way to access this information? maybe with some third-party software?

thanks in advance.
Pages: [1]