Show Posts
Pages: 1 ... 182 183 [184] 185 186 ... 409
2746  Using Arduino / Networking, Protocols, and Devices / Re: UDP Broadcast with Ethernet Shield? on: May 02, 2013, 09:08:38 am
I think you still need to use a port and ip, but for broadcast, the ip is 255.255.255.255. You should take a look at the dhcp files for the ethernet shield. It does a broadcast for a dhcp server discovery.
2747  Using Arduino / Networking, Protocols, and Devices / Re: Problem with two servers on: May 02, 2013, 06:23:54 am
Try this to get started. It doesn't use the SD yet, but you can add that later.
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

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

// change to your network settings
IPAddress ip( 192,168,2,2 );
IPAddress gateway( 192,168,2,1 );
IPAddress subnet( 255,255,255,0 );

EthernetServer server(80);
EthernetServer server2(8080);

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

  // disable w5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);

  Serial.print(F("Starting SD.."));
  if(!SD.begin(4)) Serial.println(F("failed"));
  else Serial.println(F("ok"));
  
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  digitalWrite(10,HIGH);

  delay(2000);
  server.begin();
  server2.begin();
  Serial.println(F("Ready"));
}

void loop()
{
  EthernetClient client = server.available();
  if(client) {
    boolean currentLineIsBlank = true;
    boolean currentLineIsGet = true;
    int tCount = 0;
    char tBuf[64];
    int r,t;
    char *pch;
    IPAddress ipBuf;
    
    Serial.print(F("Client request: "));
    
    while (client.connected()) {
      while(client.available()) {
        char c = client.read();

        if(currentLineIsGet && tCount < 63)
        {
          tBuf[tCount] = c;
          tCount++;
          tBuf[tCount] = 0;          
        }

        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response
          Serial.println(tBuf);
          Serial.print(F("POST data: "));
          while(client.available()) Serial.write(client.read());
          Serial.println();
          
          pch = strtok(tBuf,"?");

          while(pch != NULL)
          {
            if(strncmp(pch,"t=",2) == 0)
            {
              t = atoi(pch+2);
              Serial.print(F("t="));
              Serial.println(t,DEC);            
            }

            if(strncmp(pch,"r=",2) == 0)
            {
              r = atoi(pch+2);
              Serial.print(F("r="));              
              Serial.println(r,DEC);
            }


            pch = strtok(NULL,"& ");
          }
          Serial.println(F("Sending response"));
          client.println(F("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<html>"));
          client.println(F("<body><H1>TEST</H1>"));
          client.println(F("<form method=GET>T: <input type=text name=t><br>"));
          client.println(F("R: <input type=text name=r><br><input type=submit></form>"));
          client.println(F("</body></html>\r\n"));
          client.stop();
        }
        else if (c == '\n') {
          currentLineIsBlank = true;
          currentLineIsGet = false;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    Serial.println(F("done"));
  }

  client = server2.available();
  if(client) {
    Serial.println(F("Server2"));

    boolean currentLineIsBlank = true;
    boolean currentLineIsGet = true;
    int tCount = 0;
    char tBuf[64];
    int r,t;
    char *pch;
    IPAddress ipBuf;
    
    Serial.print(F("Client request: "));
    
    while (client.connected()) {
      while(client.available()) {
        char c = client.read();

        if(currentLineIsGet && tCount < 63)
        {
          tBuf[tCount] = c;
          tCount++;
          tBuf[tCount] = 0;          
        }

        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response
          Serial.println(tBuf);
          Serial.print(F("POST data: "));
          while(client.available()) Serial.write(client.read());
          Serial.println();
          
          Serial.println(F("Sending response"));
          client.println(F("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<html>"));
          client.println(F("<body><H1>TEST Server 2</H1>"));
          
          client.println(F("</body></html>\r\n"));
          client.stop();
        }
        else if (c == '\n') {
          currentLineIsBlank = true;
          currentLineIsGet = false;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    Serial.println(F("done"));
  }
}
2748  Using Arduino / Storage / Re: Problems with Sparkfun micro SD card + Arduino 2560( gps data logging) on: May 02, 2013, 02:23:27 am
Maybe a problem with the uSD card? You have the SPI data lines still jumpered?
D50 -> D12
D51 -> D11
D52 -> D13

Just don't jumper D53. Use D8 for the slave select.
2749  Using Arduino / Storage / Re: Problems with Sparkfun micro SD card + Arduino 2560( gps data logging) on: May 01, 2013, 03:36:41 am
Do not jumper D53 to D8. That is a really bad idea. D53 will be set to OUTPUT, and so will D8. One will win, and one will lose.

edit: That is presuming that D8 is actually your slave select for the SD card.
2750  Using Arduino / Installation & Troubleshooting / Re: A problem with 3 exclamations in the code & uploading the sketch on: April 30, 2013, 06:28:19 am
Quote
is it specifically just 3 !!! on their own or is it when its 3 or more?...ie having "words!!!!!!!!!!" would also not work?
Actually, you could use 100, but the bootloader will go into a debug mode after the first 3 in a row.
2751  Using Arduino / Storage / Re: Wiring needed for Arduino Mega 2560 Rev3 and Arduino Ethernet/microSD Shield on: April 30, 2013, 05:33:41 am
Quote
Are we talking Mega here?

There have been a couple of related threads of late and I have wondered if I have  been working in a fools' paradise. I always have used


  pinMode(10,OUTPUT);

When I was obliged to move from Uno to mega I simply carried this code over and everything worked so I didn't question it. I now recognise that pin 10 is no longer on the SPI and assume it isn't a good idea, even though my Ethernet and SD operations are all OK.
It doesn't matter if a Mega, Uno, Leonardo. The ethernet shield W5100 slave select is D10. The default slave select for the Mega is D53 and the Uno is D10, but that does not change the W5100 slave select. Still D10. My code is NOT setting the SPI to MASTER mode, it is disabling the W5100 SPI so it won't trash up the SPI bus when initializing the SD card.

Quote
I noticed this is ONLY a problem with the microSD card.init which fails (FF/01 from SDinfo I think)
...suspecting that Pin 4 is likely High when the error occurs, but I took out a logic analyzer and pin 4 appears to be
low when making the calls.  Ethernet never seems to have any issues.
The W5100 does have issues if the SD is not disabled or initialized, but sometimes they won't manifest themselves right away. Normally you will notice error on UDP more frequently than TCP, but both suffer from SPI corruption if not initialized correctly. You will see a lot of my posts that refer to this. Like this one:
http://arduino.cc/forum/index.php/topic,162799.msg1220013.html#msg1220013
edit: The code in the link above works fine with the SD card in the slot if you add this to setup().
Code:
void setup() {
  Serial.begin(9600);

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

  // then everything else
}
2752  Using Arduino / Storage / Re: Wiring needed for Arduino Mega 2560 Rev3 and Arduino Ethernet/microSD Shield on: April 29, 2013, 10:32:57 pm
This setup should start both the SD and W5100.
Code:
void setup() {
  Serial.begin(9600);

  // disable W5100 while starting SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);

  Serial.print(F("Starting SD..."));
  if(!SD.begin(4)) Serial.println(F("failed"));
  else Serial.println(F("ok"));

  Serial.print(F("Starting W5100..."));
  Ethernet.begin(mac,ip);
  Serial.println(Ethernet.localIP());
}
2753  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Ethernet Freezes on: April 29, 2013, 11:37:06 am
Are you certain it is the client.println()? I have not used client.clearWriteError().
Code:
    Serial.println("Here2");
    client.clearWriteError();
    Serial.println("Here2a");
    client.println("GetStatus=1");
2754  Using Arduino / Networking, Protocols, and Devices / Re: About HTTP server on Arduino on: April 29, 2013, 06:12:51 am
The W5100 has 4 sockets, each with a 1500 byte buffer. The packets are buffered on the w5100.

You read them a character at a time over the SPI bus, but out of the W5100 socket rx buffer, not off the network. When the socket rx buffer is empty, it sends an ack (if tcp protocol) and will accept another packet from the sender.

Writing depends on the protocol. UDP buffers the output in the W5100 until you call udp.endPacket(), then it sends the packet. TCP sends a packet every time you call client.write(), client.print(), or client.println().
2755  Using Arduino / Storage / Re: spi trouble when adding second device on: April 28, 2013, 02:59:03 pm
Quote
Thanks Tim you made my day!!!
...and you made mine!  smiley
2756  Using Arduino / Networking, Protocols, and Devices / Re: W5100/Ethernet cannot use socket as UDP after using it as TCP on: April 28, 2013, 12:52:29 pm
It does nothing for "reliable". It waits 1 second. If no response, it bails.

And the remote server thing just went out the window. I forgot to remove my SD card again, and you code does not disable it. It is working fine with my domain and a remote dns server.
2757  Using Arduino / Networking, Protocols, and Devices / Re: W5100/Ethernet cannot use socket as UDP after using it as TCP on: April 28, 2013, 12:42:56 pm
That could be it. I just tried the same test using a remote dns server and my domain, and it crashed like the Hindenberg.  smiley-sad

Now I am back to a localnet dns server and it is ok.

@sonnyyu: No question there. Arduino NTP uses UDP.
2758  Using Arduino / Storage / Re: spi trouble when adding second device on: April 28, 2013, 12:22:32 pm
Quote
SDcard starts working AND the kta remains working??? But that is what I wanted... ;-)
OH NO!! I'll call Delta Force and send in an extraction team!!

edit: I always forget the smiley face.  smiley
2759  Using Arduino / Networking, Protocols, and Devices / Re: W5100/Ethernet cannot use socket as UDP after using it as TCP on: April 28, 2013, 12:12:04 pm
Maybe you are right. Maybe the delay waiting for the response from the dns server is not long enough. That could cause the dns fail.

edit: Your test is still running on my Arduino. It has not missed a beat since I started it.
Just so you know...
2760  Using Arduino / Networking, Protocols, and Devices / Re: W5100/Ethernet cannot use socket as UDP after using it as TCP on: April 28, 2013, 12:05:37 pm
I'm not firing at you.  smiley  I'm just stating a fact. I am not fond of UDP either as a reliable transfer, but we are subjected to it through theses services.
Pages: 1 ... 182 183 [184] 185 186 ... 409