Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Programming Questions / Re: Need Help In this Sketch on: November 05, 2013, 07:08:01 am
Quote
i have tried that but no success
Then, maybe false is not the correct state that you want to start with.
If i changed that state to "TRUE" then the relays are not get auto ON but also not getting on from web page..
Thank you all of specially "PaulS" , "AWOL", and "tasosstr " Finally its working as expected Thanks again.
here is the code that worked perfect.
Code:
/*
 * arduWebRelays.ino
 *
 * Created: 07/09/2013 15:55:00
 *  Author: Guillaume Carriere - guillaume.carriere@gmail.com
 *
 */
#include <EtherCard.h>

static byte mymac[] = { 0x00,0x01,0x01,0x01,0x01,0x01  };
static byte myip[] = { 192,168,0,201 };

#define BUFFER_SIZE   500
byte Ethernet::buffer[BUFFER_SIZE];
BufferFiller bfill;

#define CS_PIN       8

#define RELAIS_1     2
#define RELAIS_2     4
bool relais1Status = true;
bool relais2Status = true;

const char http_OK[] PROGMEM =
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n\r\n";

const char http_Found[] PROGMEM =
"HTTP/1.0 302 Found\r\n"
"Location: /\r\n\r\n";

const char http_Unauthorized[] PROGMEM =
"HTTP/1.0 401 Unauthorized\r\n"
"Content-Type: text/html\r\n\r\n"
"<h1>401 Unauthorized</h1>";

void homePage()
{
  bfill.emit_p(PSTR("$F"
    "<title>Arduino Relais Webserver</title>"
    "Relais 1: <a href=\"?relais1=$F\">$F</a><br />"
    "Relais 2: <a href=\"?relais2=$F\">$F</a>"),
  http_OK,
  relais1Status?PSTR("off"):PSTR("on"),
  relais1Status?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"),
  relais2Status?PSTR("off"):PSTR("on"),
  relais2Status?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"));
}
  void setup()
{
  Serial.begin(115200); 

  pinMode(RELAIS_1, OUTPUT);
  pinMode(RELAIS_2, OUTPUT);

digitalWrite(RELAIS_1,HIGH); // I use HIGH because i thing this relay board's it is reverse the signal, if not works with this way //try LOW
digitalWrite(RELAIS_2,HIGH);

  if (ether.begin(BUFFER_SIZE, mymac, CS_PIN) == 0)
    Serial.println("Cannot initialise ethernet.");
  else
    Serial.println("Ethernet initialised.");

  ether.staticSetup(myip);
   
  Serial.println("Setting up DHCP");
  if (!ether.dhcpSetup())
    Serial.println( "DHCP failed");
 
  ether.printIp("My IP: ", ether.myip);
  ether.printIp("Netmask: ", ether.mymask);
  ether.printIp("GW IP: ", ether.gwip);
  ether.printIp("DNS IP: ", ether.dnsip);

}

void loop()
{
  digitalWrite(RELAIS_1, relais1Status);
  digitalWrite(RELAIS_2, relais2Status);

  delay(1);   // necessary for my system
  word len = ether.packetReceive();   // check for ethernet packet
  word pos = ether.packetLoop(len);   // check for tcp packet

  if (pos) {
    bfill = ether.tcpOffset();
    char *data = (char *) Ethernet::buffer + pos;
    if (strncmp("GET /", data, 5) != 0) {
      // Unsupported HTTP request
      // 304 or 501 response would be more appropriate
      bfill.emit_p(http_Unauthorized);
    }
    else {
      Serial.print("----");
      Serial.print(data);
      Serial.println("----");
      data += 5;

      if (data[0] == ' ') {
        // Return home page
        homePage();
      }
      else if (strncmp("?relais1=on ", data, 12) == 0) {
        relais1Status = true;       
        bfill.emit_p(http_Found);
      }
      else if (strncmp("?relais2=on ", data, 12) == 0) {
        relais2Status = true;       
        bfill.emit_p(http_Found);
      }
      else if (strncmp("?relais1=off ", data, 13) == 0) {
        relais1Status = false;       
        bfill.emit_p(http_Found);
      }
      else if (strncmp("?relais2=off ", data, 13) == 0) {
        relais2Status = false;       
        bfill.emit_p(http_Found);
      }
      else {
        // Page not found
        bfill.emit_p(http_Unauthorized);
      }
    }

    ether.httpServerReply(bfill.position());    // send http response
  }
}


2  Using Arduino / Programming Questions / Re: Need Help In this Sketch on: November 05, 2013, 06:59:23 am
Quote
i have tried that but no success
Then, maybe false is not the correct state that you want to start with.
If i changed that state to "TRUE" then the relays are not get auto ON but also not getting on from web page..
3  Using Arduino / Programming Questions / Re: Need Help In this Sketch on: November 05, 2013, 06:52:53 am
You set the pinMode of the relay outputs, but don't write to them.
Is this intentional?
Hello , I have tried what you say but no success .. please help me.
4  Using Arduino / Programming Questions / Re: Need Help In this Sketch on: November 05, 2013, 06:49:36 am
Hi "tasosstr" your changes to code does not changed anything, please look into attached image when it takes a IP address from my router it turn ON relays automatic. and one more thing my Relay board is active-low Thanks for helping me ..
5  Using Arduino / Programming Questions / Re: Need Help In this Sketch on: November 05, 2013, 01:48:49 am
Thank you sir ,
Code:
/*
 * arduWebRelays.ino
 *
 * Created: 07/09/2013 15:55:00
 *  Author: Guillaume Carriere - guillaume.carriere@gmail.com
 *
 */
#include <EtherCard.h>

static byte mymac[] = { 0x00,0x01,0x01,0x01,0x01,0x01  };
static byte myip[] = { 192,168,0,201 };

#define BUFFER_SIZE   500
byte Ethernet::buffer[BUFFER_SIZE];
BufferFiller bfill;

#define CS_PIN       8

#define RELAIS_1     2
#define RELAIS_2     4
bool relais1Status = false;
bool relais2Status = false;

const char http_OK[] PROGMEM =
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n\r\n";

const char http_Found[] PROGMEM =
"HTTP/1.0 302 Found\r\n"
"Location: /\r\n\r\n";

const char http_Unauthorized[] PROGMEM =
"HTTP/1.0 401 Unauthorized\r\n"
"Content-Type: text/html\r\n\r\n"
"<h1>401 Unauthorized</h1>";

void homePage()
{
  bfill.emit_p(PSTR("$F"
    "<title>Arduino Relais Webserver</title>"
    "Relais 1: <a href=\"?relais1=$F\">$F</a><br />"
    "Relais 2: <a href=\"?relais2=$F\">$F</a>"),
  http_OK,
  relais1Status?PSTR("off"):PSTR("on"),
  relais1Status?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"),
  relais2Status?PSTR("off"):PSTR("on"),
  relais2Status?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"));
}

void setup()
{
  Serial.begin(115200); 

  pinMode(RELAIS_1, OUTPUT);
  pinMode(RELAIS_2, OUTPUT);

  if (ether.begin(BUFFER_SIZE, mymac, CS_PIN) == 0)
    Serial.println("Cannot initialise ethernet.");
  else
    Serial.println("Ethernet initialised.");

  ether.staticSetup(myip);
   
  Serial.println("Setting up DHCP");
  if (!ether.dhcpSetup())
    Serial.println( "DHCP failed");
 
  ether.printIp("My IP: ", ether.myip);
  ether.printIp("Netmask: ", ether.mymask);
  ether.printIp("GW IP: ", ether.gwip);
  ether.printIp("DNS IP: ", ether.dnsip);

}

void loop()
{
  digitalWrite(RELAIS_1, relais1Status);
  digitalWrite(RELAIS_2, relais2Status);

  delay(1);   // necessary for my system
  word len = ether.packetReceive();   // check for ethernet packet
  word pos = ether.packetLoop(len);   // check for tcp packet

  if (pos) {
    bfill = ether.tcpOffset();
    char *data = (char *) Ethernet::buffer + pos;
    if (strncmp("GET /", data, 5) != 0) {
      // Unsupported HTTP request
      // 304 or 501 response would be more appropriate
      bfill.emit_p(http_Unauthorized);
    }
    else {
      Serial.print("----");
      Serial.print(data);
      Serial.println("----");
      data += 5;

      if (data[0] == ' ') {
        // Return home page
        homePage();
      }
      else if (strncmp("?relais1=on ", data, 12) == 0) {
        relais1Status = true;       
        bfill.emit_p(http_Found);
      }
      else if (strncmp("?relais2=on ", data, 12) == 0) {
        relais2Status = true;       
        bfill.emit_p(http_Found);
      }
      else if (strncmp("?relais1=off ", data, 13) == 0) {
        relais1Status = false;       
        bfill.emit_p(http_Found);
      }
      else if (strncmp("?relais2=off ", data, 13) == 0) {
        relais2Status = false;       
        bfill.emit_p(http_Found);
      }
      else {
        // Page not found
        bfill.emit_p(http_Unauthorized);
      }
    }

    ether.httpServerReply(bfill.position());    // send http response
  }
}

6  Using Arduino / Programming Questions / Re: Need Help In this Sketch on: November 05, 2013, 01:45:46 am
someone help regarding this
7  Using Arduino / Installation & Troubleshooting / Re: Please help on: November 05, 2013, 01:39:19 am
Arduino uno not detecting in Pc device manager.
Now the problem got solved actually the Crystal is the problem I have replaced it and now working fine.
8  Using Arduino / Programming Questions / Re: Need Help In this Sketch on: November 04, 2013, 06:06:58 am
Quote
i have tried that but no success
Then, maybe false is not the correct state that you want to start with.
if i use true in place of false relays are first get on and after some time goes off.
9  Using Arduino / Programming Questions / Re: Need Help In this Sketch on: November 04, 2013, 06:03:04 am
You could try pull-downs on the relay outputs.
(I can't see your schematic)
I am using a 2 relay module
10  Using Arduino / Programming Questions / Re: Need Help In this Sketch on: November 04, 2013, 05:51:01 am
yes you are right i have tried that but no success . pls help
11  Using Arduino / Programming Questions / Need Help In this Sketch on: November 04, 2013, 05:47:48 am
Hi , I am using following sketch and need help in , after using this 2 relays are getting auto on after reseting arduino uno or at starting the uno please tell how to keep relays off during reset or starting the arduino uno rest working fine.

Code:
/*
 * arduWebRelays.ino
 *
 * Created: 07/09/2013 15:55:00
 *  Author: Guillaume Carriere - guillaume.carriere@gmail.com
 *
 */
#include <EtherCard.h>

static byte mymac[] = { 0x00,0x01,0x01,0x01,0x01,0x01  };
static byte myip[] = { 192,168,0,201 };

#define BUFFER_SIZE   500
byte Ethernet::buffer[BUFFER_SIZE];
BufferFiller bfill;

#define CS_PIN       8

#define RELAIS_1     2
#define RELAIS_2     4
bool relais1Status = false;
bool relais2Status = false;

const char http_OK[] PROGMEM =
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n\r\n";

const char http_Found[] PROGMEM =
"HTTP/1.0 302 Found\r\n"
"Location: /\r\n\r\n";

const char http_Unauthorized[] PROGMEM =
"HTTP/1.0 401 Unauthorized\r\n"
"Content-Type: text/html\r\n\r\n"
"<h1>401 Unauthorized</h1>";

void homePage()
{
  bfill.emit_p(PSTR("$F"
    "<title>Arduino Relais Webserver</title>"
    "Relais 1: <a href=\"?relais1=$F\">$F</a><br />"
    "Relais 2: <a href=\"?relais2=$F\">$F</a>"),
  http_OK,
  relais1Status?PSTR("off"):PSTR("on"),
  relais1Status?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"),
  relais2Status?PSTR("off"):PSTR("on"),
  relais2Status?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"));
}

void setup()
{
  Serial.begin(115200); 

  pinMode(RELAIS_1, OUTPUT);
  pinMode(RELAIS_2, OUTPUT);

  if (ether.begin(BUFFER_SIZE, mymac, CS_PIN) == 0)
    Serial.println("Cannot initialise ethernet.");
  else
    Serial.println("Ethernet initialised.");

  ether.staticSetup(myip);
   
  Serial.println("Setting up DHCP");
  if (!ether.dhcpSetup())
    Serial.println( "DHCP failed");
 
  ether.printIp("My IP: ", ether.myip);
  ether.printIp("Netmask: ", ether.mymask);
  ether.printIp("GW IP: ", ether.gwip);
  ether.printIp("DNS IP: ", ether.dnsip);

}

void loop()
{
  digitalWrite(RELAIS_1, relais1Status);
  digitalWrite(RELAIS_2, relais2Status);

  delay(1);   // necessary for my system
  word len = ether.packetReceive();   // check for ethernet packet
  word pos = ether.packetLoop(len);   // check for tcp packet

  if (pos) {
    bfill = ether.tcpOffset();
    char *data = (char *) Ethernet::buffer + pos;
    if (strncmp("GET /", data, 5) != 0) {
      // Unsupported HTTP request
      // 304 or 501 response would be more appropriate
      bfill.emit_p(http_Unauthorized);
    }
    else {
      Serial.print("----");
      Serial.print(data);
      Serial.println("----");
      data += 5;

      if (data[0] == ' ') {
        // Return home page
        homePage();
      }
      else if (strncmp("?relais1=on ", data, 12) == 0) {
        relais1Status = true;       
        bfill.emit_p(http_Found);
      }
      else if (strncmp("?relais2=on ", data, 12) == 0) {
        relais2Status = true;       
        bfill.emit_p(http_Found);
      }
      else if (strncmp("?relais1=off ", data, 13) == 0) {
        relais1Status = false;       
        bfill.emit_p(http_Found);
      }
      else if (strncmp("?relais2=off ", data, 13) == 0) {
        relais2Status = false;       
        bfill.emit_p(http_Found);
      }
      else {
        // Page not found
        bfill.emit_p(http_Unauthorized);
      }
    }

    ether.httpServerReply(bfill.position());    // send http response
  }
}

12  Using Arduino / Installation & Troubleshooting / Re: How to get into DFU mode? on: August 09, 2013, 10:56:46 am
I think in my case the 16Mhz Crystal having problem .my uno is not detecting in device manager at all.
13  Using Arduino / Installation & Troubleshooting / Re: Strange UNO USB problem on: July 31, 2013, 03:24:07 am
I have tried the solution given here but the solution is for another vision of UNO and i cant take the UNO in DFU mode .. Thanks .
14  Using Arduino / Installation & Troubleshooting / Re: Strange UNO USB problem on: July 31, 2013, 03:21:38 am
Sir can you help me to Troubleshoot my UNO ?
My uno cant get detect in Device manager i think the Firmware of USB IC got problem pls help .
15  Using Arduino / Installation & Troubleshooting / Please help [solved] on: July 28, 2013, 11:38:54 pm
Arduino uno not detecting in Pc device manager.
Pages: [1] 2 3 ... 5