Show Posts
Pages: [1]
1  Using Arduino / Networking, Protocols, and Devices / Ethernet crossover cable on: September 09, 2012, 11:48:48 pm
I am having trouble communicating with my Mega2560 + ethernet shield when not going through a router.

Some computers can identify the need to use a crossover cable and will do the "crossover" internally on a one to one cable - doesn't work!

Seems that there are two types of crossover cable - 2 pair and 4 pair crossover (T568B)

1 - 3
2 - 6
3 - 1
4 - 7
5 - 8
6 - 2
7 - 4
8 - 5     .......doesn't work!

and

1 - 3
2 - 6
3 - 1
4 - 4
5 - 5
6 - 2
7 - 7
8 - 8     .......doesn't work!

2  Using Arduino / Storage / Re: Read a file from SD in reverse order on: September 07, 2012, 12:57:46 am
Thanks John - that will work perfectly!!
3  Using Arduino / Storage / Read a file from SD in reverse order on: September 06, 2012, 10:43:39 am
I wish to display the last 20 entries from a .txt file on the SD card (Ethernet shield on a Mega2560).

Reading the whole file into an array an then iterating through the array backwards works until the file gets to a size that makes the array too large for RAM.

Any suggestions on a way of doing this that won't take up RAM?

If I write the array to flash (PROGMEM) will I be able to delete it and re write it (the array) again every time a new line is written to the SD file and, if so, will the flash memory be freed up after deletion?

All advice is appreciated.
4  Topics / Home Automation and Networked Objects / Re: Having problems reading webserver requests on: September 01, 2012, 02:54:10 am
Thanks zoomkat - problem solved.
Much appreciated.
5  Topics / Home Automation and Networked Objects / Having problems reading webserver requests on: August 31, 2012, 01:53:38 am
I would be very appreciative of any assistance or advice that is given.

My setup is Arduino Mega2560 plus Ethernet shield using the Ethernet.h library

A simple web server with a single html page containing a single button using the html GET method to send the data back to the Mega's ip address for reading. In future there will be more buttons and text fields that will need parsing and further processing.

I am getting stuck on reading the data with client.read().

On the first click of the button it works fine: the buffer contains "?btn=001" and strLine == "?btn001" but, subsequent to that, I get strange results.
On each, subsequent click, the data seems to append to strLine

It seems to me that there is a buffer or cache that is not being cleared somewhere.

All help is appreciated.

Code:

//Libraries:
#include <SPI.h>
#include <Ethernet.h>

const int bufferMax = 128;
char buffer[bufferMax];
int bufferSize;
String strLine = "";

//General declarations:
boolean reading = false;

//Ethernet
byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x24, 0x77 };
IPAddress ip(192,168,0, 177);
String strIPaddress = "192.168.0.177";
static char baseurl[]="http://192.168.0.177/";
EthernetServer server(80);

/***********************************************************************************************
*                      VOID setup
************************************************************************************************/
void setup(){
  // Open serial communications port:
  Serial.begin(9600);
  Serial.println("--------------Setup routine-------------------");
   
  Ethernet.begin(mac, ip);
  server.begin();
 }

/***********************************************************************************************
*                      VOID loop
************************************************************************************************/
void loop(){
 
    checkForClient();
  }

/***********************************************************************************************
*                      VOID checkForClient
************************************************************************************************/
void checkForClient(){
   // listen for incoming clients
   EthernetClient client = server.available();

  if (client) {

    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    boolean sentHeader = false;

    while (client.connected()) {
      if (client.available()) {
        if(!sentHeader){
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
 
          client.println("<!DOCTYPE html>");
          client.println("<html>");
          client.println("<body>");
          client.println("<body style=\"background:#4582C7\">");
          client.println("</body>");
         
          client.println("<p><big><b>Arduino Mega (");
          client.println(")</b></big></p>");
         
          client.println("<form METHOD=GET action=\"" + String(baseurl) + "\">");
          client.println("<INPUT type=hidden name=btn value=\"001\"><INPUT type=\"submit\" value=\"Button\" style=\"background:#FF0303\">");
          client.println("</form>");
         
          client.println("</html>");
          sentHeader = true;
          }                                               //!sentHeader
               
        char c = client.read();
        if(reading && c == ' ') reading = false;
        if(c == '?') reading = true;                //found the ?, begin reading the info
       
        if(reading){
          //Read in the received character
          if (c == '\n')                            //       \n is : carriage return <CR> - the end of the line will end this
              break;
           else
          if (bufferSize < bufferMax) {             // fill up the buffer with this string untill <CR> or untill 128 bits (bufferMax)
              buffer[bufferSize++] = c;
              strLine = strLine + c;
          } else
              break;
        }
       
         if (c == '\n' && currentLineIsBlank)  break;
         if (c == '\n') {
          currentLineIsBlank = true;
        }else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }//available
    } //connected
     delay(1); // give the web browser time to receive the data
     client.println(strLine);
     client.stop(); // close the connection:
     parseReceivedRequest(strLine);    //parse and process the GET return
     strLine = "";                     //clear the returned value
     } //client
 
}   //void checkForClient

 
/***********************************************************************************************
*                      VOID ParseReceivedRequest
************************************************************************************************/
void parseReceivedRequest(String strValue){

  Serial.println("in ParseReceivedRequest........");
  Serial.println(strValue);

}
Pages: [1]