Show Posts
Pages: [1]
1  Topics / Home Automation and Networked Objects / Re: webserver for 5 relays on: September 29, 2012, 07:24:28 am
Thank you all  !!!

I solved . The problem is low memory on mega328 . I can't use button's , only links . Is working fine now , but i need to save status of the relays on internal eeprom  and not working so far .
I tested the examples from arduino and serial monitor show that eeprom program is working fine ,but i can't connect data from eeprom to relay status .
Code:
// A simple web server to turn 5 LED on or off

#include "etherShield.h"
#include "ETHER_28J60.h"
#include <EEPROM.h>

int outPin0 = 0; // relay1 to pin 4
int outPin1 = 1; // relay2 to pin 3
int outPin2 = 2; // relay3 to pin 2
int outPin3 = 3; // relay4 to pin 1
int outPin4 = 4; // relay5 to pin 0

const int ledPin =  9; // led status pin 9

byte value0;
byte value1;
byte value2;
byte value3;
byte value4;

int ledState = LOW;
long previousMillis = 0;
long interval = 1000;


static uint8_t mac[6] = {
  0x54, 0x55, 0x58, 0x10, 0x00, 0x24};   // this just needs to be unique for your network,

static uint8_t ip[4] = {
  192, 168, 0, 2}; // IP address for the webserver

static uint16_t port = 80; // Use port 80 - the standard for HTTP

ETHER_28J60 e;

void setup()
{
  e.setup(mac, ip, port);
  pinMode(outPin0, OUTPUT);
  pinMode(outPin1, OUTPUT);
  pinMode(outPin2, OUTPUT);
  pinMode(outPin3, OUTPUT);
  pinMode(outPin4, OUTPUT);
  pinMode(ledPin, OUTPUT);
 
 
 
  value0 = EEPROM.read(0x00);
  value1 = EEPROM.read(0x01);
  value2 = EEPROM.read(0x02);
  value3 = EEPROM.read(0x03);
  value4 = EEPROM.read(0x04);
 
  if (byte value0=0)
  {
    digitalWrite(outPin0, LOW);
  }
  else if (byte value0=1)
  {
    digitalWrite(outPin0, HIGH);
  }
 
 
  if (byte value1=0)
  {
    digitalWrite(outPin1, LOW);
  }
  else if (byte value1=1)
  {
    digitalWrite(outPin1, HIGH);
  }
 
 
  if (byte value2=0)
  {
    digitalWrite(outPin2, LOW);
  }
  else if (byte value2=1)
  {
    digitalWrite(outPin2, HIGH);
  }
 
 
  if (byte value3=0)
  {
    digitalWrite(outPin3, LOW);
  }
  else if (byte value3=1)
  {
    digitalWrite(outPin3, HIGH);
  }
 
 
  if (byte value4=0)
  {
    digitalWrite(outPin4, LOW);
  }
  else if (byte value4=1)
  {
    digitalWrite(outPin4, HIGH);
  }
}

void loop()
{
  char* params;
  if (params = e.serviceRequest())
  {
    e.print("<h1>Simielk WRemote<h1>");
    e.print("<h2><a href='/?d1=of'>out1off</a></h2>");
    e.print("<h2><a href='/?d1=on'>out1on</a></h2>");
    e.print("<h2><a href='/?d2=of'>out2off</a></h2>");
    e.print("<h2><a href='/?d2=on'>out2on</a></h2>");
    e.print("<h2><a href='/?d3=of'>out3off</a></h2>");
    e.print("<h2><a href='/?d3=on'>out3on</a></h2>");
    e.print("<h2><a href='/?d4=of'>out4off</a></h2>");
    e.print("<h2><a href='/?d4=on'>out4on</a></h2>");
    e.print("<h2><a href='/?d5=of'>out5off</a></h2>");
    e.print("<h2><a href='/?d5=on'>out5on</a></h2>");
   
    if (strcmp(params, "?d1=on") == 0)
    {
      byte value0=1;
      digitalWrite(outPin0, HIGH);
      e.print("<h1><a href='?d1=of'></a>1 is ON</h1>");
    }
    else if (strcmp(params, "?d1=of") == 0)
    {
      byte value0=0;
      digitalWrite(outPin0, LOW);
      e.print("<h1><a href='?d1=on'></a>1 is OFF</h1>");
    }
       if (strcmp(params, "?d2=on") == 0)
    {
      byte value1=1;
      digitalWrite(outPin1, HIGH);
      e.print("<h1><a href='?d2=of'></a>2 is ON</h1>");
    }
    else if (strcmp(params, "?d2=of") == 0)
    {
      byte value1=0;
      digitalWrite(outPin1, LOW);
      e.print("<h1><a href='?d2=on'></a>2 is OFF</h1>");
    }
        if (strcmp(params, "?d3=on") == 0)
    {
      byte value2=1;
      digitalWrite(outPin2, HIGH);
      e.print("<h1><a href='?d3=of'></a>3 is ON</h1>");
    }
    else if (strcmp(params, "?d3=of") == 0)
    {
      byte value2=0;
      digitalWrite(outPin2, LOW);
      e.print("<h1><a href='?d3=on'></a>3 is OFF</h1>");
    }
        if (strcmp(params, "?d4=on") == 0)
    {
      byte value3=1;
      digitalWrite(outPin3, HIGH);
      e.print("<h1><a href='?d4=of'></a>4 is ON</h1>");
    }
    else if (strcmp(params, "?d4=of") == 0)
    {
      byte value3=0;
      digitalWrite(outPin3, LOW);
      e.print("<h1><a href='?d4=on'></a>4 is OFF</h1>");
    }
        if (strcmp(params, "?d5=on") == 0)
    {
      byte value4=1;
      digitalWrite(outPin4, HIGH);
      e.print("<h1><a href='?d5=of'></a>5 is ON</h1>");
    }
    else if (strcmp(params, "?d5=of") == 0)
    {
      byte value4=0;
      digitalWrite(outPin4, LOW);
      e.print("<h1><a href='?d5=on'></a>5 is OFF</h1>");
    }
   
   
        e.respond();
       
  }
 
  {
        EEPROM.write(0x00, value0);
   EEPROM.write(0x01, value1);
   EEPROM.write(0x02, value2);
   EEPROM.write(0x03, value3);
   EEPROM.write(0x04, value4);
        }
       
 
    // blink the LED.
  {
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);}
  }
}
2  Topics / Home Automation and Networked Objects / Re: webserver for 5 relays on: September 29, 2012, 07:18:12 am
Thank you all  !!!

I solved . The problem is low memory on mega328 . I can't use button's , only links . Is working fine now , but i need to save status of the relays on internal eeprom  and not working so far .
I tested the examples from arduino and serial monitor show that eeprom program is working fine ,but i can't connect data from eeprom to relay status .
3  Topics / Home Automation and Networked Objects / Re: webserver for 5 relays on: September 01, 2012, 03:47:20 pm
this is the program . When i tried to connect the result is : web page not available
4  Topics / Home Automation and Networked Objects / Re: webserver for 5 relays on: September 01, 2012, 02:26:57 pm
Hi GaryP
Thank you for response
 
I do not know how to modify the program to work with 5 relays . I tried unsuccessfully .
5  Topics / Home Automation and Networked Objects / webserver for 5 relays on: September 01, 2012, 10:23:27 am
HI

I am using the arduino uno and enc28j60 . tested and is ok . i want to control 5 relays but am stuck .
i used this example .
Thank you
Pages: [1]