Show Posts
Pages: 1 ... 182 183 [184] 185 186 ... 404
2746  Using Arduino / Networking, Protocols, and Devices / Re: Upper limit for client.print() string length on: April 20, 2013, 01:27:13 pm
Maybe if you post your code, it will help me or someone else see the problem.
2747  Using Arduino / Networking, Protocols, and Devices / Re: All these delay() in wifi library?! on: April 20, 2013, 05:40:46 am
There is no 10 second delay unless something went wrong. But I see a lot of code here on the forum written for "perfect world". Unfortunately for me, I live in "real world". If that code did not have that 10 second timeout, it would lock up there forever if it did not establish a connection.
Code:
    unsigned long start = millis();

     // wait 10 second for the connection to establish IF NECESSARY
        // if the connection is established immediately, there is no delay
     while (!connected() && millis() - start < 10000)
     delay(1);

     if (!connected())
       {
     return 0;
     }
I use the same type code for ethernet connections to avoid lockups in my code. I call them "timeouts". All these use that type code. Look for the variable loopCount.
http://playground.arduino.cc/Code/WebClient
http://playground.arduino.cc/Code/WebServerST
http://playground.arduino.cc/Code/Email

edit: If you want to know what I mean by "perfect world" code, here is the same code function written for "perfect world".
Code:
int WiFiClient::connect(IPAddress ip, uint16_t port) {
   // this will ALWAYS get a socket
    _sock = getFirstSocket();
   // this will ALWAYS start the client
    ServerDrv::startClient(uint32_t(ip), port, _sock);
    WiFiClass::_state[_sock] = _sock;
    // all this will ALWAYS work ok, so return success
    return 1;
}
2748  Using Arduino / Networking, Protocols, and Devices / Re: Upper limit for client.print() string length on: April 20, 2013, 05:19:46 am
Yes, there is an upper limit, but you are not even close. The max you can send at a time is about 1400 characters, but most Arduinos do not have enough SRAM for a buffer that big. If you try that with an Uno, you would run out of SRAM.

edit: This applies to the ethernet shield. I don't know about the Wifi shield. I have sent 500 characters at a time with my Mega/ethernet shield, but the code would not run on an Uno due to SRAM limitations.
2749  Using Arduino / Networking, Protocols, and Devices / Re: Get time with NTP over ethernet and send data to Exosite on: April 20, 2013, 05:12:39 am
Normally a reset is caused by running out of SRAM. Try using the F() function on all your static string constants. Here is an example. Do the same to the rest.
Code:
    Serial.println(F("Failed to configure Ethernet using DHCP"));
2750  Using Arduino / Programming Questions / Re: Email alert of temperature on: April 19, 2013, 11:24:09 am
This will cause you problems with some servers like gmail and mine. I put comments at those places in the code. Mine returns a "I don't accept email from rude servers" error message, and "hangs up" on you.
Code:
 //wait for server "queing" response

// once this evaluation falls through (characters available)
// and you do not read the packet,
// this will evaluate to "characters available" for all others like this
  while(!client.available()) delay(1);

  client.println("HELO itismeletschat"); /*hello (statement after helo is needed but irrelevant)*/

  //wait for server "hello" response

// like this one...
  while(!client.available()) delay(1);

  client.println("MAIL From: me@athome.net"); // identify sender, this should be the same as the smtp server you are using*/

  //wait for server "sender ok" response

// and this one...
  while(!client.available()) delay(1);

  client.println("RCPT To: you@athome.net"); /* identify recipient */

  //wait for server "receipent ok" response

// and this one...
  while(!client.available()) delay(1);

  client.println("DATA");

  //wait for server to say "enter your message" response
// and this one...
  while(!client.available()) delay(1);
 
  //send email message to server
  client.println("To: you@athome.net"); /* identify recipient */
  client.println("Subject: You Have Arduino Mail!!"); /* insert subject */
  client.println("Please let me know it worked!!!"); /* insert body */
  client.println("."); /* end email */

  //wait for server "message accepted" response
// and this one...
  while(!client.available()) delay(1);

  client.println("QUIT"); /* terminate connection */
  
  //wait for server "goodby" response
// and this one.
  while(!client.available()) delay(1);
edit: Without any error checking or timeout, you need at a minimum:
Code:
  // after each of these..
  while(!client.available()) delay(1);
  // add this
  while(client.available()) Serial.write(client.read());
The code won't detect the error, but if it fails, you will see why on the serial monitor.
2751  Using Arduino / Networking, Protocols, and Devices / Re: Help me understand this send mail code! Thank you! on: April 19, 2013, 11:13:26 am
You may be able to send now. I would try first. If you need a smtp service, I hear this is ok.
www.smtp2go.com
2752  Using Arduino / Programming Questions / Re: chronometer function on: April 19, 2013, 05:57:48 am
Easy! First time through the loop the millis() function should return about 1000 and that is what you return, so you print that. The second time through, the millis() function returns 2000, but you subtract 1000 from it.
2000 - 1000 = 1000

edit: I did not notice at first, but you are returning an uninitialized value on the first iteration of chronometer() function also (time).
2753  Using Arduino / Programming Questions / Re: chronometer function on: April 19, 2013, 05:40:59 am
This will cause problems. You are setting startingTime to zero every iteration of the loop.
Code:
void loop ()
{
unsigned long startingTime = 0, time;
boolean countEnable = true;
  delay(1000);
  time = chronometer(&startingTime, countEnable);
  Serial.print(time);
  Serial.print('\n'); 
}

Maybe something like this would be better?
Code:
unsigned long startingTime = 0;

void loop ()
{
unsigned long time;
boolean countEnable = true;
  delay(1000);
  time = chronometer(&startingTime, countEnable);
  Serial.print(time);
  Serial.print('\n'); 
}
2754  Using Arduino / Networking, Protocols, and Devices / Re: Help me understand this send mail code! Thank you! on: April 19, 2013, 05:08:51 am
Be careful while testing. With email code loaded in the arduino, mail will be sent every time you reboot the arduino opening the serial monitor and such. You can email bomb your own mail box if not careful.  smiley-eek-blue
My code won't. It requires the 'e' key press (or some other trigger) to send email.

edit: I did not notice the email client code in the playground had no timeouts if the connection failed, so I added timeouts to both the ethernet and wifi email code today.
2755  Community / Website and Forum / Re: Advanced Searching? on: April 18, 2013, 09:30:28 am
My bad. I forgot to end that with  smiley

If you haven't noticed, the search function has one annoying feature, at least to me. If you search for something and select one on the items, when you press the back button, it gets weird about the reload. It isn't too bad unless you have gone a few pages forward to find the item you want, but "back" sends you back to page 1.  smiley-confuse
2756  Using Arduino / Networking, Protocols, and Devices / Re: Sudden unreliability with my network-enabled Arduino project on: April 18, 2013, 08:46:11 am
Your timing is good. I found a problem with the server code we were using. Here is a thread that covers a lot of this without having to duplicate all that.
http://arduino.cc/forum/index.php/topic,160048.msg1200379.html#msg1200379
and
http://arduino.cc/forum/index.php?topic=160912.msg1206332#msg1206332

Here is the server code with the timeout applied.
http://playground.arduino.cc/Code/WebServerST

Maybe that will take care of that pesky crash.
2757  Using Arduino / Project Guidance / Re: ICSP and SPI on: April 18, 2013, 08:14:33 am
And I use the rightmost header?
Yes. The one in the pic marked with "(1) MISO".
2758  Using Arduino / Project Guidance / Re: ICSP and SPI on: April 18, 2013, 07:58:03 am
D11-D13 will be freed up only on the Mega and Leonardo. The Uno still has the SPI data lines mirrored on D11-D13, so if you use the SPI, you can't use those pins on an Uno.
2759  Using Arduino / Project Guidance / Re: ICSP and SPI on: April 18, 2013, 07:46:08 am
So I can simply connect this cable, and keep the pin numbers the same (as in; these are clones of the SPI pins in a standard configuration)?
Or do I need to tell the SPI library to use the 'standard' ISCP header? And would that 'free up' pins 11 to 13?
You do not need to tell the SPI library anything. The SPI data lines are duplicated on the ICSP and the digital pins for each device except the Leonardo. It has the SPI lines only on the ICSP pins.

You must check the pin numbers on that ICSP connector carefully to insure you have the correct pins connected. Connecting two OUTPUT pins together can cause damage, especially if one is HIGH, and the other LOW.
2760  Using Arduino / Project Guidance / Re: ICSP and SPI on: April 18, 2013, 07:20:32 am
Quote
I'm wondering if this is correct. In other words, if the MISO MOSI and CLK pins in (one of) the ICSP header(s) aren't simply 'clones', of a sort, of pins 13 to 11, or can be used for a SPI-interface.
Not only can you use it, but you should. It is the "compatibility patch" for the Uno, Mega, and Leonardo. The newer shields do not use D11-D13. They all use that back ICSP connector now.
Pages: 1 ... 182 183 [184] 185 186 ... 404