Show Posts
Pages: 1 [2] 3 4 ... 41
16  Using Arduino / Networking, Protocols, and Devices / Re: Editing option In Websever on: April 18, 2014, 12:30:15 am
Below  code is working fine. I wanted to combine with other part s like View parameter date and time.

Below code only to blink LED using web server

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

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 7, 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()
{
    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()
{
    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>LED</h1>");
                    client.println("<p>Click to switch LED on and off.</p>");
                    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
                    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");
    }
}
17  Using Arduino / Networking, Protocols, and Devices / Re: Editing option In Websever on: April 18, 2014, 12:28:25 am
Not working code That modified. Here webserver get refreshed automatically.
Code:



#include <SPI.h>
#include <Ethernet.h>
#include "actuator.h"
#include "config.h"
#include "mode.h"
#include"timecalc.h"

#include"pos.h"
#include"spa.h"
#include"glob.h"

#include "rtc.h"
#include "diag.h"
#include "hwconfig.h"
#include "diag.h"
#include <Time.h>
#include <avr/wdt.h>
Timer t;
#include"print.h"
#include"wind.h"


String HTTP_req;
boolean LED_status = 0;

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,7, 178);
EthernetServer server(80);
void flash() {
  static boolean output = HIGH;
  digitalWrite(13, output);
  output = !output;
 
}

void setup()
{
  pinMode(9,OUTPUT);
  Serial.begin(9600);
// setSyncProvider(RTC.get);   // the function to get the time from the RTC
  setupActuator();
  wdt_enable(WDTO_8S);
  MODE=INIT;

  rtcSetup();

 

  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());


}


void loop()
{
    Ethernet_webserver();
  Serial.println("......................");
 delay(1000);
}


void Ethernet_webserver()
{
    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>LED</h1>");
                    client.println("<p>Click to switch LED on and off.</p>");
                    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
                    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
    }
}


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(9, HIGH);
        // checkbox is checked
        cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \
        onclick=\"submit();\" checked>LED2");
    }
    else {              // switch LED off
        digitalWrite(9, LOW);
        // checkbox is unchecked
        cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \
        onclick=\"submit();\">LED2");
    }
}


18  Using Arduino / Networking, Protocols, and Devices / Re: Editing option In Websever on: April 17, 2014, 10:55:29 pm
i have made changes  pin 4 to 7 . Even through it is not blinking. Is there any way to make our own customized web server .
19  Using Arduino / Networking, Protocols, and Devices / Re: Editing option In Websever on: April 17, 2014, 05:41:32 am
I could not able to blink led 4 . How can change local date , time on web server.

Code:
#include <SPI.h>
#include <Ethernet.h>
String readString;
int led = 4;
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,7, 150);
EthernetServer server(80);
int local_day=12;
int local_month=04;
int local_year=2014;
int local_h=12;
int local_m=30;
int local_s=21;
float latitude=15.08;
float longitude=58.05;
float tracker_des_angle=45.0;
float tracker_actual_pos=43.0;
int Wind_Speed=12;
int Wind_Kmph=120;

void setup()
{

  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());



}
void loop()
{
  Ethernet_webserver();
}


void Ethernet_webserver()
{
  EthernetClient client = server.available();
  if (client)
  {
    boolean currentLineIsBlank = true;
    while (client.connected())
    {
      if (client.available())
      {
        char c = client.read();
        if (c == '\n' && currentLineIsBlank)
        {
          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>");
          // add a meta refresh tag, so the browser pulls again every 5 seconds:
          client.println("<meta http-equiv=\"refresh\" content=\"5\">");
          client.println("<TITLE>NAVYA TITLE </TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");
          client.println("<H1>NAVYA TITLE </H1>");
          client.println("<hr />");
          client.println("<br />"); 
          client.println("<H2>NAVYA TRACKER PROJECT </H2>");
          client.println("<br />"); 
          client.println("<a href=\"/?button1on\"\">Turn On LED</a>");
          client.println("<a href=\"/?button1off\"\">Turn Off LED</a><br />");   
          client.println("<br />");     
          client.println("<br />");

          /*
          client.println("<!DOCTYPE HTML>");
           client.println("<html>");*/
          // add a meta refresh tag, so the browser pulls again every 5 seconds:
          //  client.println("<meta http-equiv=\"refresh\" content=\"5\">");
          // add sententence here
          client.print("LOCAL DATE :");
          client.print(local_day);
          client.print("/");
          client.print(local_month);
          client.print("/");
          client.print(local_year);
          client.println("<br />");   
          client.print("LOCAL TIME :");
          client.print(local_h);
          client.print("/");
          client.print(local_m);
          client.print("/");
          client.print(local_s);
          client.println("<br />");   
          client.print("LATITUDE :");
          client.print(latitude);
          client.print("<br />");   
          client.print("LONGITUDE :");
          client.print(longitude);
          client.println("<br />");   
          client.print("DESIRED ANGLE:");
          client.print(tracker_des_angle);
          client.println("<br />");   
          client.print("ACTUAL ANGLE:");
          client.print(tracker_actual_pos);
          client.println("<br />");   
          client.print("WIND SPEED M/S:");
          client.print(Wind_Speed);
          client.println("<br />");   
          client.print("WIND SPEED KMPH:");
          client.print(Wind_Kmph);
          client.println("<br />");   

          client.println("</html>");
          //break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
          if (readString.indexOf("?button1on") >0){
            digitalWrite(led, HIGH);
          }
          if (readString.indexOf("?button1off") >0){
            digitalWrite(led, LOW);
          }
          readString=""; 
        }
        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");


  }
}


20  Using Arduino / Networking, Protocols, and Devices / Editing option In Websever on: April 16, 2014, 11:53:19 pm
Here i put my code. Here i am displaying date and time on web server. I would like to know how to create tag for Editing date and time . once edited time being changed in Server.

Code:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,7, 100);
EthernetServer server(80);
#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;


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 rtcWrite(){

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

  Wire.write(decToBcd(s));
  Wire.write(decToBcd(m));
  Wire.write(decToBcd(h));
  Wire.write(decToBcd(wkDay));
  Wire.write(decToBcd(dd));
  Wire.write(decToBcd(mm));
  Wire.write(decToBcd(getLastTwoDigOfYear(yy)));

  Wire.write(zero); //start

  Wire.endTransmission();


}




void setup()
{
  Serial.begin(9600);
  Wire.begin();
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}
void loop()
{
  getRTCDateTime();
  Ethernet_webserver();

  delay(1000);
}
void Ethernet_webserver()
{
  EthernetClient client = server.available();
  if (client)
  {
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        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>");
          // add a meta refresh tag, so the browser pulls again every 5 seconds:
          client.println("<meta http-equiv=\"refresh\" content=\"5\">");
          // add sententence here
          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;
        }
        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");
  }
}

21  Using Arduino / Networking, Protocols, and Devices / Re: Ethernet shield Coding on: April 16, 2014, 10:44:59 pm
@ present i have connected to switch . Where my server mentioned connected to modem.

I have similar set up as shown in image.  But all device connected to switch 5 port.

From Model one LAN connection goto switch port 0
from PC one LAN cable connection goto switch port 1
from Ethernet cable goto switch port 2.
And all under same network.
Question are:
1) how to configure IP address for all, I have made test run for static ip address. connecting directly Ethernet shield and Ethernet port of PC . which is working fine
2) How to control LED in below example. Individually the code working fine.
3)How to keep option to change  date and time here. Which can replicate in web server.



Code:
#include <SPI.h>
#include <Ethernet.h>
String readString;
int led = 4;
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,7, 150);
EthernetServer server(80);
int local_day=12;
int local_month=04;
int local_year=2014;
int local_h=12;
int local_m=30;
int local_s=21;
float latitude=15.08;
float longitude=58.05;
float tracker_des_angle=45.0;
float tracker_actual_pos=43.0;
int Wind_Speed=12;
int Wind_Kmph=120;

void setup()
{

  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());



}
void loop()
{
  Ethernet_webserver();
}


void Ethernet_webserver()
{
  EthernetClient client = server.available();
  if (client)
  {
    boolean currentLineIsBlank = true;
    while (client.connected())
    {
      if (client.available())
      {
        char c = client.read();
        if (c == '\n' && currentLineIsBlank)
        {
          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>");
          // add a meta refresh tag, so the browser pulls again every 5 seconds:
          client.println("<meta http-equiv=\"refresh\" content=\"5\">");
          client.println("<TITLE>NAVYA TITLE </TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");
          client.println("<H1>NAVYA TITLE </H1>");
          client.println("<hr />");
          client.println("<br />");  
          client.println("<H2>NAVYA TRACKER PROJECT </H2>");
          client.println("<br />");  
          client.println("<a href=\"/?button1on\"\">Turn On LED</a>");
          client.println("<a href=\"/?button1off\"\">Turn Off LED</a><br />");  
          client.println("<br />");    
          client.println("<br />");

          /*
          client.println("<!DOCTYPE HTML>");
           client.println("<html>");*/
          // add a meta refresh tag, so the browser pulls again every 5 seconds:
          //  client.println("<meta http-equiv=\"refresh\" content=\"5\">");
          // add sententence here
          client.print("LOCAL DATE :");
          client.print(local_day);
          client.print("/");
          client.print(local_month);
          client.print("/");
          client.print(local_year);
          client.println("<br />");  
          client.print("LOCAL TIME :");
          client.print(local_h);
          client.print("/");
          client.print(local_m);
          client.print("/");
          client.print(local_s);
          client.println("<br />");  
          client.print("LATITUDE :");
          client.print(latitude);
          client.print("<br />");  
          client.print("LONGITUDE :");
          client.print(longitude);
          client.println("<br />");  
          client.print("DESIRED ANGLE:");
          client.print(tracker_des_angle);
          client.println("<br />");  
          client.print("ACTUAL ANGLE:");
          client.print(tracker_actual_pos);
          client.println("<br />");  
          client.print("WIND SPEED M/S:");
          client.print(Wind_Speed);
          client.println("<br />");  
          client.print("WIND SPEED KMPH:");
          client.print(Wind_Kmph);
          client.println("<br />");  

          client.println("</html>");
          //break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
          if (readString.indexOf("?button1on") >0){
            digitalWrite(led, HIGH);
          }
          if (readString.indexOf("?button1off") >0){
            digitalWrite(led, LOW);
          }
          readString="";  
        }
        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");


  }
}


22  Using Arduino / Networking, Protocols, and Devices / Re: Ethernet shield Coding on: April 16, 2014, 08:36:54 am
Finally i made i work  webserver.
2nd question over here is how to access over internet.?

I have connection setup like below
I have network switch 5 port.

LAN NETWORK connected to server to switch.  port 0
PC Ethernet port goes to same network switch, port 1
Ethernet shield  from arduino  connected to network port 2

all networks are on same hub. Let me know How to configure for Below setup . I am using Windows XP  operation system.
23  Using Arduino / Networking, Protocols, and Devices / Testing Ethernet shield example on: April 16, 2014, 12:25:13 am
Dear all,

I am new to programming with Ethernet shield. I have setup like below.
Arduino UNo board, windows 7 OS
Ethernet shieldhttp://www.rhydolabz.com/index.php?main_page=product_info&cPath=152_151&products_id=877
web server Example code from Arduino v1.0.5.
I have connected Ethernet port of shield to Ethernet port of computer.

Code compile properly.But i could not able to connect web server
Code:
/*
  Web Server
 
 A simple web server that shows the value of the analog input pins.
 using an Arduino Wiznet Ethernet shield. I have attached how i configured ip address .
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)
 
 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 
 */

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,7,100);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

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
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // listen for incoming clients
  EthernetClient 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("Connection: close");  // the connection will be closed after completion of the response
  client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            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");
  }
}


24  Using Arduino / Networking, Protocols, and Devices / Re: Ethernet shield Coding on: April 15, 2014, 11:14:46 pm
Finally it uploaded. I am getting below error. I think there is problem for assign a mac address
Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

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

  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Serial.print(F("Starting ethernet..."));
  if(!Ethernet.begin(mac))
  {
    Serial.println(F("failed"));
  }
  else {
      Serial.print(F("IP: "));
      Serial.println(Ethernet.localIP());
      Serial.print(F("Subnet: "));
      Serial.println(Ethernet.subnetMask());
      Serial.print(F("Gateway: "));
      Serial.println(Ethernet.gatewayIP());
      Serial.print(F("DNS server: "));
      Serial.println(Ethernet.dnsServerIP());
  }
 /*     Serial.print("Starting ethernet...");
  if(!Ethernet.begin(mac)) Serial.println("failed");
  else {
      Serial.print("IP: ");
      Serial.println(Ethernet.localIP());
      Serial.print("Subnet: ");
      Serial.println(Ethernet.subnetMask());
      Serial.print("Gateway: ");
      Serial.println(Ethernet.gatewayIP());
      Serial.print("DNS server: ");
    Serial.println(Ethernet.dnsServerIP());
  }
  */   
}

void loop() {
   Serial.print(F("Starting ethernet..."));
  if(!Ethernet.begin(mac))
  {
    Serial.println(F("failed"));
  }
  else {
      Serial.print(F("IP: "));
      Serial.println(Ethernet.localIP());
      Serial.print(F("Subnet: "));
      Serial.println(Ethernet.subnetMask());
      Serial.print(F("Gateway: "));
      Serial.println(Ethernet.gatewayIP());
      Serial.print(F("DNS server: "));
      Serial.println(Ethernet.dnsServerIP());
  }
  delay(1000);
}

25  Using Arduino / Networking, Protocols, and Devices / Re: Ethernet shield Coding on: April 15, 2014, 08:03:36 am
I have attached basic Setup i made. I have connected the shield and uploaded example Web server program. I could not able to read anything on ethernet. Is possible to tell what mistake i am doing

I am using LAN connection between PC and Ethernet shield , WIndows7 OS. I am not getting any data.
26  Using Arduino / Networking, Protocols, and Devices / Re: Modbus Lib example Compile error on: April 15, 2014, 01:09:12 am
@ suby
Unless you call the poll somewhere in your loop, this code shall never run. The Arduino shan't react to Master queries, because there is nowhere to handle them.
I already called your poll function.

This is how i am calling function. As i understood. Using master i can read and write the value for addreess in slave. In below code. I dont have problem in reading values. I have assigned those value into particular  buffer and reading using qmodbus as master.

Now i am trying to do this. I want to use write multiple coil. When i write the value it being seen updated While reading Next time.
Let me know how to do it. i have done like this but didnt worked.


Code:
void Modbus_call()
{
int Time1;
int Time2;
int Ntime;
  au16data[0]=wind_int;
  au16data[1]=local_month;
  au16data[2]=local_day;
  au16data[3]=wkDay;
  au16data[4]=local_h;
  au16data[5]=local_m;
  au16data[6]=local_s;
  au16data[7]=(int)Wind_Speed;
  au16data[8]=(int)Wind_Kmph;
  int  desired_deg=360-tracker_des_angle;
  int actual_deg=360-tracker_actual_pos;
  au16data[9]=desired_deg;
  au16data[10]=actual_deg;  
  
  au16data[13] = slave.getInCnt();
  au16data[14] = slave.getOutCnt();
  au16data[15] = slave.getErrCnt();  

*/



 yy=au16data[0];
 mm=au16data[1];
 dd=au16data[2];
 h=au16data[3];
 m=au16data[4];
 
 Time1=(60*5)+(30);
 Time2=60*au16data[3]+au16data[4];
 Ntime=Time2-Time1;
 Ntime=Ntime/60;
 h=(int)(Ntime);
 s=au16data[5];
 wkDay =2;
 void rtcWrite(int sec1,int min1,int hour1, int  wkday1,int dd1,int mm1,int yy1);
 wind_int=au16data[5] ;
 Angle_int=au16data[6];
 
 
 
 }



Code:
void loop()
{
  int Time1;
  int Time2;
  int Ntime;
  state = slave.poll( au16data, 15);
  if (state > 4)
  {
    tempus = millis() + 50;
  }
  if (millis() > tempus) digitalWrite(13, LOW );
 Modbus_call();
  //Serial.println("..........................");

}

27  Using Arduino / Networking, Protocols, and Devices / Ethernet shield Coding on: April 14, 2014, 11:26:06 pm
Dear all,
I am starting new project using Ethernet. I need step for executing web server application. I have Certain data to be monitored on web server.
I have these many data to be monitored on webserver
1) date and time
2)latitude
3)longitude
4)Desired angle
5)actual angle
etc
Action to be control:
Motor forward and reverse
 value to be change:
1)date and time
2)angles
3) limit of wind speed.

Question :
1) is it possible to do using web server application??
2) Basic steps for configure web server
3)How to create our own control tags. see youtube 2

Sheild i am using.
http://arduino.cc/en/Main/ArduinoEthernetShield

Here i have added one video where we can fine any change in analog value also change in web server. How to make it. Is there any software available to create tags.
https://www.youtube.com/watch?v=XrjgFdHH4AI
https://www.youtube.com/watch?v=2J4cx2gA7DQ
Testing code
Code:
#include <SPI.h>
#include <Ethernet.h>
#include<string.h>

// MAC address can be anything that is unique within your network.
// IP is the address the Arduino Ethernet Card would respond to.  It needs to be an unused address within your network.
byte mac[] = {0x00, 0x1E, 0x2A, 0x77, 0x24, 0x02 };
byte ip[] = {192,168,7,12 }; // This is typically 10.0.0.x

Server server(80); // Port 80 is http.

//-- Commands and parameters (sent by browser) --
char cmd[15];    // Nothing magical about 15, increase these if you need longer commands/parameters
char param1[15];
char param2[15];

//-- Sample Ports ---
void SetupSamplePorts()
{
  // To illustrate how to use this, I have an LED and a Potentiometer.
  // The 10K potentiometer left lead is connected to GND, right lead to +5V, and middle lead to Analog 0.
  // The LED cathode is on digital pin 7 and anode is on pin 8.
  pinMode(7,OUTPUT); digitalWrite(7,LOW);  // I use this pin as GND for the LED.
  pinMode(8,OUTPUT); // Sample output, unable to use built-in LED at pin 13 because Ethernet Shield uses pins 10,11,12,13.
}

void setup()
{
  Ethernet.begin(mac, ip);
  server.begin();

  Serial.begin(57600);
  SetupSamplePorts();
}

#define bufferMax 128
int bufferSize;
char buffer[bufferMax];

void loop()
{
  Client client = server.available();
  if (client)
  {
    WaitForRequest(client);
    ParseReceivedRequest();
    PerformRequestedCommands();
    
    client.stop();
  }
}

void WaitForRequest(Client client) // Sets buffer[] and bufferSize
{
  bufferSize = 0;
 
  while (client.connected()) {
    if (client.available()) {
      char c = client.read();
      if (c == '\n')
        break;
      else
        if (bufferSize < bufferMax)
          buffer[bufferSize++] = c;
        else
          break;
    }
  }
  
  PrintNumber("bufferSize", bufferSize);
}

void ParseReceivedRequest()
{
  Serial.println("in ParseReceivedRequest");
  Serial.println(buffer);
  
  //Received buffer contains "GET /cmd/param1/param2 HTTP/1.1".  Break it up.
  char* slash1;
  char* slash2;
  char* slash3;
  char* space2;
  
  slash1 = strstr(buffer, "/") + 1; // Look for first slash
  slash2 = strstr(slash1, "/") + 1; // second slash
  slash3 = strstr(slash2, "/") + 1; // third slash
  space2 = strstr(slash2, " ") + 1; // space after second slash (in case there is no third slash)
  if (slash3 > space2) slash3=slash2;

  PrintString("slash1",slash1);
  PrintString("slash2",slash2);
  PrintString("slash3",slash3);
  PrintString("space2",space2);
  
  // strncpy does not automatically add terminating zero, but strncat does! So start with blank string and concatenate.
  cmd[0] = 0;
  param1[0] = 0;
  param2[0] = 0;
  strncat(cmd, slash1, slash2-slash1-1);
  strncat(param1, slash2, slash3-slash2-1);
  strncat(param2, slash3, space2-slash3-1);
  
  PrintString("cmd",cmd);
  PrintString("param1",param1);
  PrintString("param2",param2);
}

void PerformRequestedCommands()
{
  if ( strcmp(cmd,"digitalWrite") == 0 ) RemoteDigitalWrite();
  if ( strcmp(cmd,"analogRead") == 0 ) RemoteAnalogRead();
}

void RemoteDigitalWrite()
{
  int ledPin = param1[0] - '0'; // Param1 should be one digit port
  int ledState = param2[0] - '0'; // Param2 should be either 1 or 0
  digitalWrite(ledPin, ledState);
 
  //-- Send response back to browser --
  server.print("D");
  server.print(ledPin, DEC);
  server.print(" is ");
  server.print( (ledState==1) ? "ON" : "off" );

  //-- Send debug message to serial port --
  Serial.println("RemoteDigitalWrite");
  PrintNumber("ledPin", ledPin);
  PrintNumber("ledState", ledState);
}

void RemoteAnalogRead()
{
  // If desired, use more server.print() to send http header instead of just sending the analog value.
  int analogPin = param1[0] - '0'; // Param1 should be one digit analog port
  int analogValue = analogRead(analogPin);
  
  //-- Send response back to browser --
  server.print("A");
  server.print(analogPin, DEC);
  server.print(" is ");
  server.print(analogValue,DEC);
  
  //-- Send debug message to serial port --
  Serial.println("RemoteAnalogRead");
  PrintNumber("analogPin", analogPin);
  PrintNumber("analogValue", analogValue);
}

void PrintString(char* label, char* str)
{
  Serial.print(label);
  Serial.print("=");
  Serial.println(str);
}

void PrintNumber(char* label, int number)
{
  Serial.print(label);
  Serial.print("=");
  Serial.println(number, DEC);
}[tt][tt][/tt][/tt]
28  Using Arduino / Networking, Protocols, and Devices / Re: Modbus Lib example Compile error on: April 11, 2014, 07:12:30 am
The code seem working fine. I have small issue here. I want to enable Pin 9 HIGH through modbus master.if Pin High then you can Edit perameters else you can Read the coils.How to impliment this.
I have made angle which reading -ve  to add and subtract 360 degree . Which is posted in Previous thread.
Question here  How to enabe function code  write multiple coil.



Code:
void loop()
{
 Modbus_call();
}


void Modbus_call()
{
if(digitalRead(9)==0)
{
au16data[0]=local_year;
  au16data[1]=local_month;
  au16data[2]=local_day;
  au16data[3]=wkDay;
  au16data[4]=local_h;
  au16data[5]=local_m;
  au16data[6]=local_s;
  au16data[7]=(int)Wind_Speed;
  au16data[8]=(int)Wind_Kmph;
 int desired_deg=360-tracker_des_angle;
int actual_deg=360-tracker_actual_pos;
  au16data[9]=desired_deg;
  au16data[10]=actual_deg; 


 } else
{
  yy=au16data[0];
   mm=au16data[1];
   dd=au16data[2];
   h=au16data[3];
   m=au16data[4];
   
   Time1=(60*5)+(30);
   Time2=60*au16data[3]+au16data[4];
   Ntime=Time2-Time1;
   Ntime=Ntime/60;
   h=(int)(Ntime);
   s=au16data[5];
   wkDay =2;
   void rtcWrite(int sec1,int min1,int hour1, int  wkday1,int dd1,int mm1,int yy1);
   wind_int=au16data[5] ;
   Angle_int=au16data[6];
 } 
    au16data[13] = slave.getInCnt();
  au16data[14] = slave.getOutCnt();
  au16data[15] = slave.getErrCnt(); 

   
   }
   

29  Using Arduino / Programming Questions / Re: negative value Conversion. on: April 10, 2014, 06:48:52 am
I have kept angle constant for testing purpose.If it work on constant value it should also work on variable value
30  Using Arduino / Programming Questions / Re: negative value Conversion. on: April 10, 2014, 06:41:06 am
Intially i tried like this as majenko said, But i found angle for constant value remain same, If i connect the anlog sensor then stop @ particular position . the value being continuously changing .

Code:
  if(tracker_des_angle<0 ||tracker_actual_pos<0 )
  {
 desired_deg=360-tracker_des_angle;
actual_deg=360-tracker_actual_pos;
  au16data[9]=desired_deg;
  au16data[10]=actual_deg; 
  }else
  {
   
  au16data[9]=tracker_des_angle;
  au16data[10]=tracker_actual_pos;
 
  }

Pages: 1 [2] 3 4 ... 41