Show Posts
Pages: 1 ... 166 167 [168] 169 170 ... 391
2506  Using Arduino / Project Guidance / Re: Arduino Uno+Ethernet Shield+DHT 11 project on: April 27, 2013, 07:03:47 am
I use my own stuff. I have 3 servers online all the time, and all have php/mysql extensions enabled on the web servers. However, that would be harder to demonstrate from a remote location.
2507  Using Arduino / Project Guidance / Re: Arduino Uno+Ethernet Shield+DHT 11 project on: April 27, 2013, 06:52:10 am
Ok, so after I share the connection the feed from arduino to cosm should work?
I won't guarantee that, but you should be able to connect to the internet with the Arduino/shield. I don't use Cosm.

2508  Using Arduino / Project Guidance / Re: Arduino Uno+Ethernet Shield+DHT 11 project on: April 27, 2013, 06:44:20 am
http://windows.microsoft.com/en-us/windows-vista/using-ics-internet-connection-sharing

http://answers.microsoft.com/en-us/windows/forum/windows_7-networking/how-to-enable-internet-connection-sharing-on/5a3e34ec-f0af-4a02-a588-e9f091711095
2509  Using Arduino / Project Guidance / Re: Arduino Uno+Ethernet Shield+DHT 11 project on: April 27, 2013, 06:38:18 am
Don't know what OS you have on the laptop, but you need "internet connection sharing". A Google search should help you set up the laptop for your OS.
2510  Using Arduino / Project Guidance / Re: Arduino Uno+Ethernet Shield+DHT 11 project on: April 27, 2013, 06:21:27 am
Quote
The board is connected to my laptop via LAN.
Does that mean you are connected to the internet via wireless with your computer, and the Arduino is connected to your ethernet port on the laptop?
2511  Using Arduino / Networking, Protocols, and Devices / Re: W5100/Ethernet cannot use socket as UDP after using it as TCP on: April 27, 2013, 05:25:07 am
Quote
Are you using the code I put in the message?
I am testing the code from your reply #16 now. I changed the network settings and dns server to mine, and have it resolving my local domain name instead of yahoo. It has not failed yet, despite the requests to the server and the "No data received" message.

When resolving yahoo, I got errors if I try to resolve the name too often, no matter if I loaded the webpage or not.

edit: This is after I removed my SD card from the shield slot. NTP, dhcp and dns have a problem if there is a card in the slot and not disabled or initialized correctly.

It has been running about an hour with several dozen requests to the server, and not one fail of either service.
2512  Using Arduino / Networking, Protocols, and Devices / Re: W5100/Ethernet cannot use socket as UDP after using it as TCP on: April 26, 2013, 04:15:51 pm
If I use a reliable dns server, I cannot replicate your error with my code. Both NTP and DNS work. Is 192.168.10.1 a good dns server? My NTP and DNS changes sockets (they both use the same socket) and has no problem. ??
2513  Using Arduino / Networking, Protocols, and Devices / Re: W5100/Ethernet cannot use socket as UDP after using it as TCP on: April 26, 2013, 01:49:06 pm
Sometimes I amaze myself!  smiley-cool

Remove the Udp.begin(8888) from setup, and use this checkTime function. How does it do? Works ok here.
Code:
void checkTime()
{
if(!Udp.begin(8888)) {
          Serial.println("UDP fail");
          return;
        }

  sendNTPpacket(Udp, timeServer); // send an NTP packet to a time server
Serial.println("");
ShowSockStatus();
// wait to see if a reply is available
delay(1000); 
if ( Udp.parsePacket() ) { 
// We've received a packet, read the data from it
Udp.read(packetBuffer,NTP_PACKET_SIZE);  // read the packet into the buffer

//the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, esxtract the two words:

unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); 
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord; 

// now convert NTP time into everyday time:
Serial.print("Unix time = ");
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
const unsigned long seventyYears = 2208988800UL;     
// subtract seventy years:
unsigned long epoch = secsSince1900 - seventyYears; 
// print Unix time:
Serial.println(epoch); 

else
Serial.println("UDP FAIL!");
Udp.stop();

}
2514  Using Arduino / Networking, Protocols, and Devices / Re: W5100/Ethernet cannot use socket as UDP after using it as TCP on: April 26, 2013, 01:25:40 pm
That one UDP socket will work for every UDP function, like dhcp, ntp, dns, etc...all use that socket. One socket, all that stuff is covered. smiley

I know when I am having a problem, but this isn't it. If this was an Apache server, I would expect more.

I will give you the benefit of the doubt, and try to begin and stop a UDP socket and see how it affects the server and the UDP sockets. I'm not sure why I would do that, and I don't really expect it to work. You are assuming that you will need all the sockets for the server simultaneously at times, which would guarantee a NTP fail in that time.
2515  Using Arduino / Networking, Protocols, and Devices / Re: W5100/Ethernet cannot use socket as UDP after using it as TCP on: April 26, 2013, 12:51:41 pm
You have 4 sockets. Use them wisely. I like the full time UDP socket, and would like to reserve a socket for client stuff when a server is running. Here is my opinion:
http://arduino.cc/forum/index.php/topic,159138.msg1210212.html#msg1210212
Note my sketch uses all the sockets. One (socket#0) for UDP, and the rest (#1-3) for the server.
2516  Using Arduino / Networking, Protocols, and Devices / Re: W5100/Ethernet cannot use socket as UDP after using it as TCP on: April 26, 2013, 12:32:46 pm
Here is yours:
Code:
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip, INADDR_NONE, gateway, subnet);
delay(500);

Serial.println("Start!");
// here is where the first socket is assigned:
server.begin();
ShowSockStatus();
timer = millis();
}

Here is mine:
Code:
void setup() {
Serial.begin(9600);

        pinMode(4, OUTPUT);
        digitalWrite(4, HIGH);
       
Ethernet.begin(mac, ip, INADDR_NONE, gateway, subnet);
delay(500);

// here is socket #0
Udp.begin(8888);

Serial.println("Start!");

// here is socket #1
server.begin();
ShowSockStatus();
timer = millis();
}
2517  Using Arduino / Networking, Protocols, and Devices / Re: W5100/Ethernet cannot use socket as UDP after using it as TCP on: April 26, 2013, 12:11:28 pm
Like this?
Quote
Start!
Socket#0:0x22 8888 D:0.0.0.0(0)
Socket#1:0x14 80 D:0.0.0.0(0)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
Client request: GET / HTTP/1.1

POST data:
Sending response
done

Socket#0:0x22 8888 D:198.55.111.50(123)
Socket#1:0x0 80 D:192.168.1.254(3719)
Socket#2:0x17 80 D:192.168.1.254(3720)
Socket#3:0x14 80 D:0.0.0.0(0)
Unix time = 1366996102
Client request: GET /?t=4&r=3 HTTP/1.1

POST data:
t=4
r=3
Sending response
done

Socket#0:0x22 8888 D:198.55.111.50(123)
Socket#1:0x0 80 D:192.168.1.254(3719)
Socket#2:0x0 80 D:192.168.1.254(3720)
Socket#3:0x14 80 D:0.0.0.0(0)
Unix time = 1366996112
Client request: GET /?t=5&r=1 HTTP/1.1

POST data:
t=5
r=1
Sending response
done

Socket#0:0x22 8888 D:198.55.111.50(123)
Socket#1:0x14 80 D:192.168.1.254(3719)
Socket#2:0x0 80 D:192.168.1.254(3720)
Socket#3:0x0 80 D:192.168.1.254(3724)
Unix time = 1366996122
Client request: GET /?t=5&r=1 HTTP/1.1

POST data:
t=5
r=1
Sending response
done

Socket#0:0x22 8888 D:198.55.111.50(123)
Socket#1:0x0 80 D:192.168.1.254(3725)
Socket#2:0x17 80 D:192.168.1.254(3726)
Socket#3:0x14 80 D:192.168.1.254(3724)
Unix time = 1366996132
Client request: GET /favicon.ico HTTP/1.1

POST data:
Sending response
done

edit: Removed my NTP server ip.
2518  Using Arduino / Networking, Protocols, and Devices / Re: W5100/Ethernet cannot use socket as UDP after using it as TCP on: April 26, 2013, 10:31:32 am
Here is the serial monitor for that:
Quote
Socket#0:0x22 8888 D:198.55.111.50(123)
Socket#1:0x14 80 D:192.168.1.254(3287)
Socket#2:0x0 80 D:192.168.1.254(3286)
Socket#3:0x0 80 D:192.168.1.254(3290)
Unix time = 1366989984
Client request: GET /?t=&r= HTTP/1.1

POST data:
t=0
r=0
Sending response
done
Client request: GET /favicon.ico HTTP/1.1

POST data:
Sending response
done

Socket#0:0x22 8888 D:198.55.111.50(123)
Socket#1:0x14 80 D:192.168.1.254(3291)
Socket#2:0x0 80 D:192.168.1.254(3292)
Socket#3:0x0 80 D:192.168.1.254(3290)
Unix time = 1366989994

Socket#0:0x22 8888 D:198.55.111.50(123)
Socket#1:0x14 80 D:192.168.1.254(3291)
Socket#2:0x0 80 D:192.168.1.254(3292)
Socket#3:0x0 80 D:192.168.1.254(3290)
Unix time = 1366990004

Socket#0:0x22 8888 D:198.55.111.50(123)
Socket#1:0x14 80 D:192.168.1.254(3291)
Socket#2:0x0 80 D:192.168.1.254(3292)
Socket#3:0x0 80 D:192.168.1.254(3290)
Unix time = 1366990014

Socket#0:0x22 8888 D:198.55.111.50(123)
Socket#1:0x14 80 D:192.168.1.254(3291)
Socket#2:0x0 80 D:192.168.1.254(3292)
Socket#3:0x0 80 D:192.168.1.254(3290)
Unix time = 1366990024

Socket#0:0x22 8888 D:198.55.111.50(123)
Socket#1:0x14 80 D:192.168.1.254(3291)
Socket#2:0x0 80 D:192.168.1.254(3292)
Socket#3:0x0 80 D:192.168.1.254(3290)
Unix time = 1366990034

Socket#0:0x22 8888 D:198.55.111.50(123)
Socket#1:0x14 80 D:192.168.1.254(3291)
Socket#2:0x0 80 D:192.168.1.254(3292)
Socket#3:0x0 80 D:192.168.1.254(3290)
Unix time = 1366990044
2519  Using Arduino / Networking, Protocols, and Devices / Re: W5100/Ethernet cannot use socket as UDP after using it as TCP on: April 26, 2013, 10:25:10 am
This worked for me. You did have some errors in that code that did not manifest themselves first pass, but did on a second. I moved the Udp.begin() to setup() and commented out the Udp.stop(). I also used my server code.
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <utility/w5100.h>

void ShowSockStatus()
{
for (int i = 0; i < MAX_SOCK_NUM; i++) {
Serial.print("Socket#");
Serial.print(i);
uint8_t s = W5100.readSnSR(i);
Serial.print(":0x");
Serial.print(s,16);
Serial.print(" ");
Serial.print(W5100.readSnPORT(i));
Serial.print(" D:");
uint8_t dip[4];
W5100.readSnDIPR(i, dip);
for (int j=0; j<4; j++) {
Serial.print(dip[j],10);
if (j<3) Serial.print(".");
}
Serial.print("(");
Serial.print(W5100.readSnDPORT(i));
Serial.println(")");
}
}

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

EthernetServer server(80);
IPAddress timeServer(198,55,111,50);

IPAddress ip(192,168,2,2);
IPAddress gateway(192,168,2, 1);
IPAddress subnet(255, 255, 255, 0);

long timer;
EthernetUDP Udp;

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

        pinMode(4, OUTPUT);
        digitalWrite(4, HIGH);
       
Ethernet.begin(mac, ip, INADDR_NONE, gateway, subnet);
delay(500);
Udp.begin(8888);

Serial.println("Start!");
server.begin();
ShowSockStatus();
timer = millis();
}

const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets

// send an NTP request to the time server at the given address
unsigned long sendNTPpacket(EthernetUDP & Udp, IPAddress& address)
{

// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011;   // LI, Version, Mode
packetBuffer[1] = 0;     // Stratum, or type of clock
packetBuffer[2] = 6;     // Polling Interval
packetBuffer[3] = 0xEC;  // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12]  = 49;
packetBuffer[13]  = 0x4E;
packetBuffer[14]  = 49;
packetBuffer[15]  = 52;

// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:    
Udp.beginPacket(address, 123); //NTP requests are to port 123
Udp.write(packetBuffer,NTP_PACKET_SIZE);
Udp.endPacket();
}

void checkTime()
{
sendNTPpacket(Udp, timeServer); // send an NTP packet to a time server
Serial.println("");
ShowSockStatus();
// wait to see if a reply is available
delay(1000); 
if ( Udp.parsePacket() ) { 
// We've received a packet, read the data from it
Udp.read(packetBuffer,NTP_PACKET_SIZE);  // read the packet into the buffer

//the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, esxtract the two words:

unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); 
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord; 

// now convert NTP time into everyday time:
Serial.print("Unix time = ");
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
const unsigned long seventyYears = 2208988800UL;     
// subtract seventy years:
unsigned long epoch = secsSince1900 - seventyYears; 
// print Unix time:
Serial.println(epoch); 

else
Serial.println("UDP FAIL!");
// Udp.stop();

}

void loop()
{
//Check if a web client has attached.
        checkServer();
       
if ((millis() - timer) > 10000) {
timer = millis();
checkTime();
}
}


void checkServer()
{
  EthernetClient client = server.available();
  if(client) {
    boolean currentLineIsBlank = true;
    boolean currentLineIsGet = true;
    int tCount = 0;
    char tBuf[64];
    int r,t;
    char *pch;

    Serial.print(F("Client request: "));

    // this controls the timeout
    int loopCount = 0;

    while (client.connected()) {
      while(client.available()) {
        // if packet, reset loopCount
        loopCount = 0;
        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("t=");
              Serial.println(t,DEC);             
            }

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


            pch = strtok(NULL,"& ");
          }
          Serial.println(F("Sending response"));
          client.print(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>"));
          client.stop();
        }
        else if (c == '\n') {
          currentLineIsBlank = true;
          currentLineIsGet = false;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }

      loopCount++;

      // if 10000ms has passed since last packet
      if(loopCount > 10000) {
        // close connection
        client.stop();
        Serial.println("\r\nTimeout");
      }

      // delay 1ms for timeout timing
      delay(1);
    }
    Serial.println(F("done"));
  }
}
2520  Development / Suggestions for the Arduino Project / Re: BUG: W5100 cannot use socket as UDP after using it as TCP on: April 26, 2013, 06:40:23 am
Not a bug. It works fine on IDE v1.0.4. I'm still running your code, and it is doing great, except the "No data received" message on my web browser.
Pages: 1 ... 166 167 [168] 169 170 ... 391