Show Posts
Pages: [1] 2 3 ... 41
1  Using Arduino / Networking, Protocols, and Devices / Re: <solved>Modbus Lib example Compile error on: April 22, 2014, 11:05:10 pm
I have made mistaken While write operation . i am using same address buffer to read write so its over writing value. and hanging
2  Using Arduino / Networking, Protocols, and Devices / Reading data from Webserver on: April 22, 2014, 01:15:30 am
Dear all,
Here i am pasting my code. I am new in programming with web server. I wanted to know How could i read data from Web server. In below code i am trying to read data from web server using that date and time get modified.
i wanted to know  below thing:
1) If edit option selected how to disable edit option, user cant change date and time
2) how to read data from client.
3)Is there any application software where i can create own tags and just link to arduino Web server
http://www.w3schools.com/html/html_forms.asp
Code:
#include <SPI.h>
#include <Ethernet.h>
static int local_day;
static int local_month;
static int local_year;
static int local_s;
static int local_h;
static int local_m;
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {
  192, 168,1, 120 };  
EthernetServer server(80);
void setup()
{
  Ethernet.begin(mac, ip);
  server.begin();
}
void loop()
{
  Ethernet_Control();
}
void Ethernet_Control()
{
  EthernetClient client = server.available();
  // detect if current is the first line
  boolean current_line_is_first = true;

  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        // if we've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so we can send a reply
        if (c == '\n' && current_line_is_blank) {
        
          // send a standard http response header
          
        
          client.println(F("HTTP/1.1 200 OK"));
          client.println(F("Content-Type: text/html"));
          client.println();
          client.println("<input type=\"checkbox\" name=\"EDIT\" value=\"2\" \
        onclick=\"submit();\" checked>EDIT");
          client.print(" <font> <color=blue> DD: <input type=text name=01 value=");
          client.println(local_day);
          client.print(" <font> <color=blue> month: <input type=text name=01 value=");
          client.println(local_month);
          client.print(" <font> <color=blue> year: <input type=text name=01 value=");
          client.println(local_year);
          client.print(" <font> <color=blue> hour: <input type=text name=01 value=");
          client.println(local_h);
          client.print(" <font> <color=blue> min: <input type=text name=01 value=");
          client.println(local_m);
          client.print(" <font> <color=blue> sec: <input type=text name=01 value=");
          client.println(local_s);
          client.println("");
           client.println(F("</form><br />"));
           client.println(F("<button name=d value=1 type=submit style=height:30px;width:50px>OK</button>"));
          client.println("<p>NOTE: This page will automatically refresh every 5 seconds.</p></center>");
          
          
          client.println(F("<center><p><h5>Web application  V1.0</h5></p><center><hr><br />"));
          client.print(F("<p><h5>DATE: = <font color=indigo>"));
          client.print(local_day);
          client.print("/");
          client.print(local_month);
          client.print("/");
          client.print(local_year);
          client.println("</font></h5></p>");
          client.print(F("<p><h5>TIME: = <font color=indigo>"));
          client.print(local_h);
          client.print(":");
          client.print(local_m);
          client.print(":");
          client.print(local_s);
          client.println("</font></h5></p>");
        
          

          break;
        }

        if (c == '\n') {
          // we're starting a new line

          current_line_is_blank = true;
        }
        else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
      }
    
    }
  delay(1);
  client.stop();  
 
}
}

3  Using Arduino / Networking, Protocols, and Devices / <SOLVED> Modbus Lib example Compile error on: April 22, 2014, 12:33:08 am
Thanks for support. i finally got it working
4  Using Arduino / Networking, Protocols, and Devices / Re: Modbus Lib example Compile error on: April 21, 2014, 11:00:19 pm
Quote
As soon as the slave gets any write function (such as Write Multiple Coil), the referred buffer is updated in the slave. Of course, you will see that this is already updated on the next pooling cycle, unless there is something that overwrites them.

Imagine that you write the current time on the RTC and afterwards you read it. If your RTC is currently working, you should watch that the time has been increased.


if i use any write coil operatio i seen that i not being update , But continue to read previous value itself
5  Using Arduino / Programming Questions / Re: Altering value on webserver. on: April 21, 2014, 04:45:59 am
Code:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {   192, 168,1, 120 }; 
EthernetServer server(80);
float latitude=13.08;
float longitude=80.20;
void setup()
{
   Serial.begin(9600);
   Ethernet.begin(mac, ip);
   server.begin();
}
void loop()
{
   Ethernet_Control();
}

void Ethernet_Control()
{
 EthernetClient client = server.available();
  // detect if current is the first line
  boolean current_line_is_first = true;

  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
          if (c == '\n' && current_line_is_blank) {
          client.println(F("HTTP/1.1 200 OK"));
          client.println(F("Content-Type: text/html"));
          client.println();
          client.println(F("<META HTTP-EQUIV=REFRESH CONTENT=5 URL=>"));
          client.println(F("<center><p><h5>Web application  V1.0</h5></p><center><hr><br />"));
          client.print(F("<p><h5>DATE: = <font color=indigo>"));
    client.print(" <font> <color=blue> latitude: <input type=text name=01 value=");
        client.println(latitude);
          client.print(" <font> <color=black> Longitude: <input type=text name=01 value=");
          client.println(longitude);
           client.println("</form>");
                    client.println("</body>");
                    client.println("</html>");

            client.println("<p>NOTE: This page will automatically refresh every 5 seconds.</p></center>");

          break;
        }
        if (c == '\n') {
          // we're starting a new line
          current_line_is_first = false;
          current_line_is_blank = true;
        }
        else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
       }
    }
    // give the web browser time to receive the data
    delay(1);
    client.stop();
  }
}

6  Using Arduino / Programming Questions / Re: Altering value on webserver. on: April 21, 2014, 04:05:40 am
This function i am calling from loop. Here i can Dispaly all value but i cant change value.

I have attached output of my code. Here i wanted to change latitude, longitude, Let me know how to impliemet using Web app


Code:

void Ethernet_Control()
{
  EthernetClient client = server.available();
  // detect if current is the first line
  boolean current_line_is_first = true;

  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if we've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so we can send a reply
        if (c == '\n' && current_line_is_blank) {
          // send a standard http response header
          client.println(F("HTTP/1.1 200 OK"));
          client.println(F("Content-Type: text/html"));
          client.println();

          // auto reload webpage every 5 second
          client.println(F("<META HTTP-EQUIV=REFRESH CONTENT=5 URL=>"));

          // webpage title
          client.println(F("<center><p><h5>Web application  V1.0</h5></p><center><hr><br />"));
          client.print(F("<p><h5>DATE: = <font color=indigo>"));
          client.print(local_day);
          client.print("/");
          client.print(local_month);
          client.print("/");
          client.print(local_year);
          client.println("</font></h5></p>");
          client.print(F("<p><h5>TIME: = <font color=indigo>"));
          client.print(local_h);
          client.print(":");
          client.print(local_m);
          client.print(":");
          client.print(local_s);
          client.println("</font></h5></p>");
         // client.print(F("<p><h5>LATITUDE: = <font color=indigo>"));
         // client.print(latitude);
        client.print(" <font> <color=blue> latitude: <input type=text name=01 value=");
        client.println(latitude);
          //client.println("</font></h5></p>");
          //client.print(F("<p><h5>LONGITUDE: = <font color=indigo>"));
            client.print(" <font> <color=black> Longitude: <input type=text name=01 value=");
          client.println(longitude);
          //client.println("</font></h5></p>");
            client.print(" <font> <color=blue> Desired_Angle: <input type=text name=01 value=");
          //client.print(F("<p><h5>DESIRE_ANGLE: = <font color=indigo>"));
          client.println(tracker_des_angle);
         // client.println("</font></h5></p>");
           client.print(" <font> <color=blue> Actual_Angle: <input type=text name=01 value=");
          //client.print(F("<p><h5>ACTUAL ANGLE: = <font color=indigo>"));               
          client.println(tracker_actual_pos);
          //client.println("</font></h5></p>");
            //client.print(" <font> <color=blue> Wind_Speed m/s: <input type=text name=01 value=");
             client.println(F("</form><br />"));
         client.print(F("<p><h5>WIND_SPEED M/S: = <font color=indigo>")); 
          client.print(Wind_Speed);
           client.println(F("</form><br />"));
          // client.println("</font></h5></p>");
          client.print(F("<p><h5>WIND_SPEED KMPH: = <font color=BLACK>"));
           //client.println(F("</form><br />"));
            //client.print(" <font> <color=blue> WIND in KMPH: <input type=text name=01 value=");
           client.print(Wind_Kmph);
             client.println(F("</form><br />"));
         //  client.println("</font></h5></p>");
         
          client.println("<form  method=get name=form>");
          client.println(F("<button name=d value=1 type=submit style=height:50px;width:80px>FORWARD</button>"));
          client.println(F("<button name=d value=2 type=submit style=height:50px;width:80px>REVERSE</button>"));
          client.println(F("<button name=d value=3 type=submit style=height:50px;width:80px>STOP</button>"));
          client.println(F("</form><br />"));
         
           client.println("<form method=\"get\">");
          ProcessCheckbox(client);
                    client.println("</form>");
                    client.println("</body>");
                    client.println("</html>");


                    //Serial.print(HTTP_req);
                    HTTP_req = "";    // finished with request, empty string

          // button functions
        /*  client.println("<form  method=get name=form>");
          client.println("<button name=b value=1 type=submit style=height:50px;width:80px>LED On</button>");
          client.println("<button name=b value=2 type=submit style=height:50px;width:80px>LED Off</button>");
          client.println("</form><br />");
*/
          // webpage footer
       
          client.println("<p>NOTE: This page will automatically refresh every 5 seconds.</p></center>");

          break;
        }
        if (c == '\n') {
          // we're starting a new line
          current_line_is_first = false;
          current_line_is_blank = true;
        }
        else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
        // get the first http request
        if (current_line_is_first && c == '=') {
          for (int i = 0; i < 1; i++) {
            c = client.read();
            command[i] = c;
          }
         
            if (!strcmp(command, "1"))
          {
             client.print("FWD");
             digitalWrite(PWM,1);
            digitalWrite(IN1,1);
            digitalWrite(IN2,0);
           
          }
         
          if (!strcmp(command, "2"))
          {
             client.print("REV");
            digitalWrite(PWM,1);
            digitalWrite(IN1,0);//spdt
            digitalWrite(IN2,1);//dpdt
           
          }
          if (!strcmp(command, "3"))
          {
             client.print("STOP");
            digitalWrite(PWM,0);
            digitalWrite(IN1,0);
            digitalWrite(IN2,0);
           
          }
         
          // LED control
        /*  if (!strcmp(command, "1")) {
            digitalWrite(LED, HIGH);
          }
          else if (!strcmp(command, "2")) {
            digitalWrite(LED, LOW);
          }*/
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    client.stop();
  }
}
7  Using Arduino / Programming Questions / Re: Altering value on webserver. on: April 21, 2014, 02:04:52 am
This code is used to read data from Sensor And Displayed on webserver. These type code i posted already given by many. These code are working fine.

My question here is Suppose assume that ,  
v1=analogRead(A0)*(5.0/1024.0)
output= (voltage* slope)+intercept;
initial, slope 35 , intercept =-75
 with Default value of slope and intercept it display it on webserver.
Suppose i want to change my slope value and intercept value. Every time i need to goto sketch and make change ,then upload into arduino board to get result. Instead of doing this
I wanted to keep 3 tag.
slope
intercept
update

 where you can value of slope and intercept to any value. Once update link clicked you can see changes made output. I am looking for such code.

check below image. I am looking as in image 2
8  Using Arduino / Programming Questions / Re: Altering value on webserver. on: April 21, 2014, 01:32:37 am
@ PAUL.

I have Google it . i dint find where change value of variable using Web server.Every code are controll the lamp.led, motor action Etc. Suppose i want to edit value that being used for calculation
Example1:
Assume that i have connected to web server, I wanted to perform c=a+b
Where a and b can be assigned 5 and 7 manually . once add button pressed add 7+5 and display it on c.

Example 2
v1=analogRead(A0)*(5.0/1024.0)
output= (voltage* slope)+intercept;
initial, slope 35 , intercept =-75

i wanted to change in webserver from 35 to 40 and -75 to 75 . to perform these operation .
9  Using Arduino / Networking, Protocols, and Devices / Re: How to read and set variable values on arduino by internet? on: April 21, 2014, 01:13:12 am
@maxhack.

I am  facing same problem . I would like to know have you get any code for edting value from webserver. Let me know if you get it worked
10  Using Arduino / Programming Questions / Web server Creating tags on: April 21, 2014, 12:33:00 am
Dear all,
I am currently working on Web server application on Arduino UNo .I wanted to create tag like View and Edit.
If view parameter checked  you can view data.
If Edit  you can edit data. like date time, motor action,
Is any one has Developed application on editing parameter on web server. i searched in Google where most of project on basic of controlling action of motor.led lamp etc . bUt i am looking for example code where i can assign value on web server and find change in view perameter window.

Is there any way to create our own customised tag and link to arduino.

for example add to nos.
i have two variable A and B
c is output variable
c= a+b;
Where  A and B can assigned on webserver  and c check out put
11  Using Arduino / Programming Questions / Webserver failure to communicate on: April 19, 2014, 01:14:37 am
Dear all
i have code as below. This thing tried on below program.
1) Individually both functions are working fine
2) When i put all together web browser doesn't show any data.

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

const int SENSOR_PIN = A0;
const int SAMPLE_COUNT = 10;
const unsigned long SAMPLE_RATE = 1000UL; // every two seconds
int local_day=12;
int local_month=4;
int local_year=2014;
int local_h=12;
int local_m=12;
int local_s=12;
int LED = 3;          // led is connected to digital pin 3
int PIR = 2;          // PIR sensor is connected to digital pin 2
int LDR = 1;          // LDR sensor is connected to analog in 5
int PIRstate = 0;     // variable for PIR sensor status
float photocell = 0;  // variable for photocell (LDR) analog value
char c = 0;           // received data
char command[2] = "\0";  // command


// array to store the samples
float sample[SAMPLE_COUNT];
byte sampleIndex = 0;
float sampleAverage(void);
static int Wind_Exceed_count;
int Stow_flag=0;
float Wind_Speed;
float Wind_Kmph;

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {
  192, 168,1, 120 };   

EthernetServer server(80);


float sampleAverage(void)
{
  float accumulator = 0;
  for (int i = 0; i < SAMPLE_COUNT; i++)
  {
    accumulator += sample[i];
  }
  return accumulator / SAMPLE_COUNT;
}

void Wind_calc()
{
  static unsigned long lastSampleTime = 0;
  unsigned long currentTime = millis();
  // check if time for new reading
  if (currentTime - lastSampleTime >= SAMPLE_RATE)
  {
    lastSampleTime = currentTime;
    int sensorValue = analogRead(SENSOR_PIN);
    float voltage = sensorValue * (5.0 / 1023.0);
    sample[sampleIndex] = voltage;
    sampleIndex++;
    if (sampleIndex == SAMPLE_COUNT)
    {
      sampleIndex = 0;
    }
    float average = sampleAverage();
    Wind_Speed = (6 * average);
    Wind_Kmph = 3.6 * Wind_Speed;

  }
}

void setup()
{
  pinMode(8,OUTPUT);
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
 
}

void loop()
{
  Wind_calc();
  Ethernet_Control();
 
}


void Ethernet_Control()
{
  EthernetClient client = server.available();
  // detect if current is the first line
  boolean current_line_is_first = true;

  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if we've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so we can send a reply
        if (c == '\n' && current_line_is_blank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          // auto reload webpage every 5 second
          client.println("<META HTTP-EQUIV=REFRESH CONTENT=5 URL=>");

          // webpage title
          client.println("<center><p><h1>NORDIC INDIA SOLAR WEB APPPLICATION V1.0</h1></p><center><hr><br />");
          client.print("<p><h2>DATE: = <font color=indigo>");
          client.print(local_day);
          client.print("/");
          client.print(local_month);
          client.print("/");
          client.print(local_year);
          client.println("</font></h2></p>");
          client.print("<p><h2>TIME: = <font color=indigo>");
          client.print(local_h);
          client.print("/");
          client.print(local_m);
          client.print("/");
          client.print(local_s);
          client.println("</font></h2></p>");
         
          client.print(Wind_Speed);
           client.println("</font></h2></p>");
           client.print("<p><h2>WIND_SPEED KMPH: = <font color=indigo>"); 
           client.print(Wind_Kmph);
           client.println("</font></h2></p>");



          // read digital pin 13 for the state of PIR sensor
          PIRstate = digitalRead(8);
          if (PIRstate == HIGH) { // PIR sensor detected movement
            client.println("<p><h2><font color=red>Motion Detected!</font></h2></p>");
          }
          else { // No movement is detected
            client.println("<p><h2><font color=green>No Movement</font></h2></p>");
          } 

          // button functions
          client.println("<form  method=get name=form>");
          client.println("<button name=b value=1 type=submit style=height:80px;width:150px>LED On</button>");
          client.println("<button name=b value=2 type=submit style=height:80px;width:150px>LED Off</button>");
          client.println("</form><br />");

          // webpage footer
          client.println("<hr><center><a href=http://www.robothead2toe.com.my>Robot.Head to Toe</a><br />");
          client.println("<p>P.S.: This page will automatically refresh every 5 seconds.</p></center>");

          break;
        }
        if (c == '\n') {
          // we're starting a new line
          current_line_is_first = false;
          current_line_is_blank = true;
        }
        else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
        // get the first http request
        if (current_line_is_first && c == '=') {
          for (int i = 0; i < 1; i++) {
            c = client.read();
            command[i] = c;
          }
          // LED control
          if (!strcmp(command, "1")) {
            digitalWrite(LED, HIGH);
          }
          else if (!strcmp(command, "2")) {
            digitalWrite(LED, LOW);
          }
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    client.stop();
  }
}


12  Using Arduino / Programming Questions / Altering value on webserver. on: April 18, 2014, 07:19:57 am
Dear all.
I am looking for simple example Code where i can edit value on webserver . I found examples for blinking led. reading analog value. But i didnt find any example program Where i can assign value to variable and get changed when put it into update. If any one has implimented code requested to share example code,
13  Using Arduino / Networking, Protocols, and Devices / Re: SD card Intialise error on: April 18, 2014, 06:45:33 am
Code:
The w5100 ethernet controller slave select is D10.
The SD card slave select is D4.

Unless you did some pin bending and a jumper, you can't change those.

Did you reformat the SD card as I recommended?
Can  you share relvant link  to format and How can i use it

14  Using Arduino / Networking, Protocols, and Devices / Re: SD card Intialise error on: April 18, 2014, 06:35:38 am
I am just running example code from arduino example. I am getting error sd card intialise failure error.
As you said i changed from 10 to 3 . Error still there

Code:
#include <SD.h>

File myFile;

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
   pinMode(3, OUTPUT);
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
 
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
 
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
// close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
 
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
   
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
  // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
// nothing happens after setup
}

15  Using Arduino / Networking, Protocols, and Devices / Re: Editing option In Websever on: April 18, 2014, 06:27:53 am
I have SD card sheild , but not inserted any SD card.  yet.

In below code  I can change status of pin that get reflected on webserver,. But i could not able edit my own date and time. Date is atomically set to default value.I wanted to say

IF Edit option is checked
        Edit date and time
else
     keep updating time

IS  SD card need to above requirement.


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

#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527
static int dd;
static int mm;
static int yy;
static int s;
static int h;
static int m;
static int wkDay;
int CENTURY=2000;
int RTC_ERROR_FLAG=0;


// MAC address from Ethernet shield sticker under board
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 178); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80

String HTTP_req;          // stores the HTTP request
boolean LED_status = 0;   // state of LED, off by default

void setup()
{
  Wire.begin(); 
  Ethernet.begin(mac, ip);  // initialize Ethernet device
  server.begin();           // start to listen for clients
  Serial.begin(9600);       // for diagnostics
  pinMode(8, OUTPUT);       // LED on pin 2
}

void loop()
{
  //getRTCDateTime();
  EthernetClient client = server.available();  // try to get client

  if (client) {  // got client?
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {   // client data available to read
        char c = client.read(); // read 1 byte (character) from client
        HTTP_req += c;  // save the HTTP request 1 char at a time
        // last line of client request is blank and ends with \n
        // respond to client only after last line received
        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("Connection: close");
          client.println();
          // send web page
          client.println("<!DOCTYPE html>");
          client.println("<html>");
          client.println("<head>");
          client.println("<title>Arduino LED Control</title>");
          client.println("</head>");
          client.println("<body>");
          client.println("<h1>EDIT</h1>");
          client.println("<p>Click to switch LED on and off.</p>");
          client.println("<form method=\"get\">");
          ProcessCheckbox(client);
          client.println("<br />");
          client.println("<br />");
          client.print("LOCAL DATE :");
          client.print(dd);
          client.print("/");
          client.print(mm);
          client.print("/");
          client.print(yy);
          client.println("<br />");   
          client.print("LOCAL TIME :");
          client.print(h);
          client.print("/");
          client.print(m);
          client.print("/");
          client.print(s);
          client.println("<br />");
          client.println("</html>");
          break;




          client.println("</form>");
          client.println("</body>");
          client.println("</html>");
          Serial.print(HTTP_req);
          HTTP_req = "";    // finished with request, empty string
          break;
        }
        // every line of text received from the client ends with \r\n
        if (c == '\n') {
          // last character on line of received text
          // starting new line with next character read
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // a text character was received from client
          currentLineIsBlank = false;
        }
      } // end if (client.available())
    } // end while (client.connected())
    delay(1);      // give the web browser time to receive the data
    client.stop(); // close the connection
  } // end if (client)
}

// switch LED and send back HTML for LED checkbox
void ProcessCheckbox(EthernetClient cl)
{
  /*  if (HTTP_req.indexOf("LED2=2") > -1) {  // see if checkbox was clicked
        // the checkbox was clicked, toggle the LED
        if (LED_status) {
            LED_status = 0;
        }
        else {
            LED_status = 1;
        }
    }
   
    if (LED_status) {    // switch LED on
        digitalWrite(8, HIGH);
        // checkbox is checked
        cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \
        onclick=\"submit();\" checked>LED2");
    }
    else {              // switch LED off
        digitalWrite(8, LOW);
        // checkbox is unchecked
        cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \
        onclick=\"submit();\">LED2");
    }
   
    */
    if (HTTP_req.indexOf("LED2=2") > -1)
    {
     if (LED_status) {
            LED_status = 0;
        }
        else {
            LED_status = 1;
        }
    }
   
    if (LED_status)
    {
      rtcWrite(s,m,h,2,dd,mm, yy);
      cl.print("IN SET MODE");
      //setDateTime();
       digitalWrite(8, HIGH);
      cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \
        onclick=\"submit();\" checked>LED2");
     
    }else
    {
     cl.print("read mode");
       digitalWrite(8, LOW);
      getRTCDateTime();
       cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \
        onclick=\"submit();\">LED2");
    }
   
   
}




































void getRTCDateTime(){

  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ADDRESS, 7);

  if(RTC_ERROR_FLAG==0)
  {
    //Serial.println("RTC IS ACTIVE :\n");
    s = bcdToDec(Wire.read());
    m = bcdToDec(Wire.read());
    h = bcdToDec(Wire.read() & 0b111111); //24 hour time
    wkDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
    dd = bcdToDec(Wire.read());
    mm = bcdToDec(Wire.read());
    yy = CENTURY + bcdToDec(Wire.read());

  }
}


byte decToBcd(byte val){
  // Convert normal decimal numbers to binary coded decimal
  return ( (val/10*16) + (val%10) );
}

byte bcdToDec(byte val)  {
  // Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}

int getLastTwoDigOfYear(int y){
  return(y%1000);
}


/*
void setDateTime(){

  byte second =      12; //0-59
  byte minute =      12; //0-59
  byte hour =        12; //0-23
  byte weekDay =    2; //1-7
  byte monthDay =    12; //1-31
  byte month =       12; //1-12
  byte year  =       15; //0-99

  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero); //stop Oscillator

  Wire.write(decToBcd(second));
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));
  Wire.write(decToBcd(weekDay));
  Wire.write(decToBcd(monthDay));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));

  Wire.write(zero); //start

  Wire.endTransmission();

}*/



void rtcWrite(int sec1,int min1,int hour1, int  wkday1,int dd1,int mm1,int yy1){

  /* Serial.println("In RTC write function");
   Serial.print("date");
   Serial.print(dd1);
   Serial.print("/");
   Serial.print(mm1);
   Serial.print("/");
   Serial.print(yy1);
   */
  int year1; 
 // rtcSetup();
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero); //stop Oscillator

  Wire.write(decToBcd(sec1));
  Wire.write(decToBcd(min1));
  Wire.write(decToBcd(hour1)& 0b111111);
  Wire.write(decToBcd(wkday1));
  Wire.write(decToBcd(dd1));
  Wire.write(decToBcd(mm1));
  //Wire.write(decToBcd(yy1);
  Wire.write(decToBcd(getLastTwoDigOfYear(yy1)));

  //year1= Wire.write(decToBcd(getLastTwoDigOfYear(yy1)));
  //Serial.print("date in rtc write:");
  //Serial.println(year1);
  Wire.write(zero); //start
  Wire.endTransmission();
}

Pages: [1] 2 3 ... 41