Loading...
  Show Posts
Pages: 1 [2] 3 4
16  Using Arduino / Networking, Protocols, and Devices / Re: NRF24L01 + W5100 = Fail on: April 11, 2013, 04:44:50 pm
I reconstructed my test sketch, using the WebServerST code from your link, Tim (says it's for arduino 1.0.1 and is dated Oct 2012).  Still unable to compile.  On a whim, I downloaded 1.5.2 of the GUI and found that it does compile.  The culprit seems to have been @ line 38 of WString.h:

It changed from
Code:
#define F(string_literal) (reinterpret_cast< __FlashStringHelper *>(PSTR(string_literal)))

to

Code:
#define F(string_literal) (reinterpret_cast<[color=red]const[/color] __FlashStringHelper *>(PSTR(string_literal)))

I had been using 1.0.1 of the GUI.

FreeMemory reports 855 bytes available when I run my test code (I get 755 in my 'real' code which is more complex than this).  Still the NRF24L01 still quits talking.  Sample output suddenly started to return 'all ones' (notice how the RF24 functions whatHappened() and getDynamicPayloadSize():

Code:
Client request: GET /?t=&r= HTTP/1.1

POST data:
t=0
r=0
Sending response
freeMemory()=877
done
Data Values Read ==============================
0, 0, 0
Payload Size: 32
220
Client request: GET /?t=&r= HTTP/1.1

POST data:
t=0
r=0
Sending response
freeMemory()=877
done
Data Values Read ==============================
0, 0, 0
Payload Size: 32
221
Client request: GET /?t=&r= HTTP/1.1

POST data:
t=0
r=0
Sending response
freeMemory()=877
done
Data Values Read ==============================
0, 0, 0
Payload Size: 32
222
Client request: GET /?t=&r= HTTP/1.1

POST data:
t=0
r=0
Sending response
freeMemory()=877
done
Data Values Read ==============================
1, 1, 1
Payload Size: 255
223

Updated test sketch:

Code:
/*
   Web server sketch for IDE v1.0.1 and w5100/w5200
   Posted October 2012 by SurferTim
*/

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

#include <nRF24L01.h>
#include <RF24.h>

#include "MemoryFree.h"

RF24     radio(7,6);  // ce, csn
uint64_t pipe = 0xF0F0F0F0E1LL;
uint16_t i = 0;

int data_rate = 0;
int payload_size;

bool tx_ok;
bool tx_fail;
bool rx_ready;
bool good = true;

// this must be unique
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEC };

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

EthernetServer server(80);

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

  // disable w5100 while setting up SD
  // uncomment next 5 lines if using a microSD card

  //  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();
  Serial.println(F("Ready"));
 
  radioOn();               
  //    radio.printDetails();
 
}

void loop()
{
  radio.whatHappened(tx_ok, tx_fail, rx_ready);
  payload_size = radio.getDynamicPayloadSize();

  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.print(F("<head><script type=\"text/javascript\">"));
          client.print(F("function show_alert() {return;alert(\"This is an alert\");}"));
          client.print(F("</script></head"));


          client.print(F("<body><H1>TEST</H1>"));

          client.print(F("<form method=GET onSubmit=\"show_alert()\">T: <input type=text name=t><br>"));
          client.print(F("R: <input type=text name=r><br><input type=submit></form>"));


          client.print(F("</body></html>\r\n\r\n"));
          client.stop();
    Serial.print(F("freeMemory()="));
    Serial.println(freeMemory());
        }
        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"));

    radio.whatHappened(tx_ok, tx_fail, rx_ready);
    //    payload_size = 0;
    payload_size = radio.getDynamicPayloadSize();
    Serial.println(F("Data Values Read ============================== "));  // Try to read something to see if we get it or the radio has stopped talking

    Serial.print(tx_ok);
    Serial.print(F(", "));
    Serial.print(tx_fail);
    Serial.print(F(", "));
    Serial.println(rx_ready);
    Serial.print(F("Payload Size: "));
    Serial.println(payload_size);

    Serial.println(++i);
  }
}

void radioOn() {

  radio.begin();
  radio.setRetries(15,15);
  radio.setPayloadSize(32);
  radio.openReadingPipe(1,pipe);
  radio.startListening();
  Serial.println("Radio ready");
}

17  Using Arduino / Networking, Protocols, and Devices / Re: NRF24L01 + W5100 = Fail on: April 11, 2013, 09:02:05 am
As I indicated, it's an UNO (real article, not a Chinese clone)

I included the SD to see if having a *different* SPI device sharing the bus would have the same issue.  The problem predates including SD library.

I had to remove the F(), knowing full well the implication, but for some reason the RF24 library's PSTR() causes compile errors with respect to F() and complains the 'constness' of the strings.

I think it has to be a deficiency with the NRF24L01, as running the SD seems fine for serving up a simple file from it over the webserver. 

I just bought one of those cheap USBee logic analyzers and when it arrives I hope to actually see what's happening with the radio
18  Using Arduino / Project Guidance / Re: Exasperation: W5100 locking up nRf24L01 (solved) on: April 07, 2013, 05:17:24 pm
Drat!  Not solved.  I should probably not keep dredging this up on the Guidance thread as I have transitioned into a 'networking' issue. So I started a discussion over there to pick where I left off here.

http://arduino.cc/forum/index.php/topic,159084.0.html
19  Using Arduino / Networking, Protocols, and Devices / NRF24L01 + W5100 = Fail on: April 07, 2013, 05:14:13 pm
OK, I figured I sould get off the 'project guidance' thread since my problem seems more of a programming/interface issue...

I have been trying to make a simple sketch that reads data over the NRF24L01 and then display it in a web browser.  For the purposes of sorting out how to do this, I created the sketch below, starting with SurferTim's WebServerST and adding the RF24 library to it.

Both seem to work perfect by themselves, but when run together it's not stable at all.  The code runs for a while, for some random number of cycles, and then it quits.

By 'quits' I mean that the NRF24L01 quits returning data -- I get FFFF for everything I try to read from it.  At leas 3 times I thought I had it licked and got it to work, but I kept finding it would not provided data from the remote NRF24L01 (which is just sitting there sending 32 bytes of data every 10-20 seconds or so.  It's actually hooked up to a PIR sensor so I can wave my hand at it to get something sent to me.  That code is essentially the RF24 library's 'ping pair' example with the PIR initiating the pings so I could fire them off on demand. (Pushbuttons are so 20th century, you know)

I've tried switching the NRF24L01 modules, changing the pins it uses for ce/cs, and a different UNO board.  Still the problem persists.

So I'm hoping someone might have some recommendations on coding or configuration to truly resolve this.  By all reckoning, this should 'just work'.  My W5100 boards are of recent vintage and seem to have the inverter-fix incorporated for SS that handles the longstanding 'SPI bug'.

Code:
/*
   Web server sketch for IDE v1.0.1 and w5100/w5200
   Posted October 2012 by SurferTim
*/

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

#include <nRF24L01.h>
#include <RF24.h>

RF24     radio(8, 7);
uint64_t pipe = 0xF0F0F0F0E1LL;
uint16_t i = 0;

int data_rate = 0;
int payload_size;

bool tx_ok;
bool tx_fail;
bool rx_ready;
bool good = true;

// this must be unique
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEC };
char payload[32];
// change to your network settings
IPAddress ip( 192,168,0,11 );
IPAddress gateway( 192,168,0,1 );
IPAddress subnet( 255,255,255,0 );

EthernetServer server(80);

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

  // disable w5100 while setting up SD
  // uncomment next 5 lines if using a microSD card

  //  pinMode(10,OUTPUT);
  //  digitalWrite(10,HIGH);
  // Serial.print("Starting SD..");
  // if(!SD.begin(4)) Serial.println("failed");
  // else Serial.println("ok");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  digitalWrite(10,HIGH);

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

    radioOn();               
//    radio.printDetails();
}

void loop()
{
    radio.whatHappened(tx_ok, tx_fail, rx_ready);
    payload_size = radio.getDynamicPayloadSize();
   
    EthernetClient client = server.available();
  if(client && good) {
   
//    radioOff();
   
    boolean currentLineIsBlank = true;
    boolean currentLineIsGet = true;
    int tCount = 0;
    char tBuf[64];
    int r,t;
    char *pch;

    Serial.print("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("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("Sending response");
          client.print("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<html>");

          client.print("<head><script type=\"text/javascript\">");
          client.print("var timer = setInterval(function(){if (document.forms[0].t.value != '32') clearInterval(timer); else document.forms[0].submit()},3000);");
          client.print("function show_alert() {return;alert(\"This is an alert\");}");
          client.print("</script></head");


          client.print("<body><H1>TEST</H1>");
// Send back the payload_size and millis(), just so we can see that the page has reloaded.
          client.print("<form method=GET onSubmit=\"show_alert()\">T: <input type=text name=t value=\""); client.print(payload_size); client.print("\"><br>");
          client.print("R: <input type=text name=r value=\""); client.print(millis()); client.print("\"><br><input type=submit></form>");

          data_rate = 0;  // Clear it so we know if radio contines to set it
         
          client.print("</body></html>\r\n\r\n");
          client.stop();
        }
        else if (c == '\n') {
          currentLineIsBlank = true;
          currentLineIsGet = false;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    Serial.println("done");
//    radioOn();
    if (payload_size > 32) good = false;
  }
 
  if (good && millis() % 5000 == 0) {
//    radio.printDetails();

    radio.whatHappened(tx_ok, tx_fail, rx_ready);
    payload_size = 0;
    payload_size = radio.getDynamicPayloadSize();
    Serial.println("Data Values Read ============================== ");  // Try to read something to see if we get it or the radio has stopped talking

    Serial.print(tx_ok);
    Serial.print(", ");
    Serial.print(tx_fail);
    Serial.print(", ");
    Serial.println(rx_ready);
    Serial.print("Payload Size: ");
    Serial.println(payload_size);
   
    Serial.println(++i);
  }
}
void radioOff() {
  radio.stopListening();
//  radio.powerDown();
  Serial.println("Radio is off");
}

void radioOn() {
 
  radio.begin();
  radio.setRetries(1,1);
  radio.setPayloadSize(32);
  radio.openReadingPipe(1,pipe);
  radio.startListening();
  Serial.println("Radio ready");
}
20  Using Arduino / Project Guidance / Re: Exasperation: W5100 locking up nRf24L01 (solved) on: April 07, 2013, 09:07:40 am
I think I have found the source of my problem.  

The RF24 library has quite a few 'print' statements in it for debugging, etc.  It defines its own PSTR to accomplish those printouts.  There is some difficulty with using them when other SPI devices are in use.  On the surface, it sounds absurd to make such a claim, but by using just the data acquisition methods of the RF24 class, all seems well.

Based on my limited c++ expertise, it seems the RF24 library defines PSTR and some other statements that ought to be the equivalent of the F() function from the Wire library which SurferTim's code example -- however, it directly conflicts with what RF24 does.  I was not able to comprehend these mechanisms for using ProgMem well enough to 'fix' RF24 so it also used F().

Regardless, my test sketch hums along nicely without calling the RF24 printDetails() (which I had been using as a way to tell when it 'locks up').   Persumably as long as I steer clear of using any of the RF24 'print' statements, my code will work fine.

For future reference, this is the code I have been running for hours now without any (apparent) problems:

Code:
/*
   Web server sketch for IDE v1.0.1 and w5100/w5200
   Posted October 2012 by SurferTim
*/

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

#include <nRF24L01.h>
#include <RF24.h>

RF24     radio(8, 7);
uint64_t pipe = 0xF0F0F0F0E1LL;
uint16_t i = 0;

int data_rate = 0;

bool tx_ok;
bool tx_fail;
bool rx_ready;

// this must be unique
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEC };
char payload[32];
// change to your network settings
IPAddress ip( 192,168,0,11 );
IPAddress gateway( 192,168,0,1 );
IPAddress subnet( 255,255,255,0 );

EthernetServer server(80);

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

  // disable w5100 while setting up SD
  // uncomment next 5 lines if using a microSD card

  //  pinMode(10,OUTPUT);
  //  digitalWrite(10,HIGH);
  // Serial.print("Starting SD..");
  // if(!SD.begin(4)) Serial.println("failed");
  // else Serial.println("ok");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  digitalWrite(10,HIGH);

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

radio.begin();

// optionally, increase the delay between retries & # of retries
radio.setRetries(15,15);

// optionally, reduce the payload size.  seems to
// improve reliability

radio.setPayloadSize(32);

//
// Open pipe to other node for communication
//

radio.openReadingPipe(1,pipe);

//
// Start listening
//

radio.startListening();
               
                radio.printDetails();
                Serial.println("Radio 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;

    Serial.print("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("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("Sending response");
          client.print("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<html>");

          client.print("<head><script type=\"text/javascript\">");
          client.print("setInterval(function(){document.forms[0].submit()},1000);");
          client.print("function show_alert() {alert(\"This is an alert\");}");
          client.print("</script></head");


          client.print("<body><H1>TEST</H1>");

          client.print("<form method=GET onSubmit=\"show_alert()\">T: <input type=text name=t value=\""); client.print(data_rate); client.print("\"><br>");
          client.print("R: <input type=text name=r value=\""); client.print(millis()); client.print("\"><br><input type=submit></form>");

          data_rate = 0;  // Clear it so we know if radio contines to set it
         
          client.print("</body></html>\r\n\r\n");
          client.stop();
        }
        else if (c == '\n') {
          currentLineIsBlank = true;
          currentLineIsGet = false;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    Serial.println("done");
  }
 
  if (millis() % 5000 == 0) {
//    radio.printDetails();

    radio.whatHappened(tx_ok, tx_fail, rx_ready);
    Serial.print("Data Rate ============================== ");
    Serial.println( data_rate = radio.getPALevel());
    Serial.print(tx_ok);
    Serial.print(", ");
    Serial.print(tx_fail);
    Serial.print(", ");
    Serial.println(rx_ready);
   
    Serial.println(++i);
  }}


(Whoops, initially didn't paste my test sketch, just the WebserverST code I started from.  Fixed.  It's all there now.)
21  Using Arduino / Project Guidance / Re: Exasperation: W5100 locking up nRf24L01 on: April 05, 2013, 06:33:26 am
I plugged the WebserverST example into a sketch with the pingpair code and it seems rock-solid. Not a single misfire/lockup of the SPI bus after several hours of banging on it.  As they say, 3rd times a charm, it seems.  Over the weekend I will sit down with the code and see if I can figure out why the other two don't play well.

This appears to have gotten me past a significant roadblock in my project.  Thanks to all for the guidance!
22  Using Arduino / Project Guidance / Re: Exasperation: W5100 locking up nRf24L01 on: April 04, 2013, 05:02:06 pm
I figured that was going to be the case, Peter.  Never really knew if the admonitions elsewhere to use the standard pins were because the software was 'wired' up to those or the internals demanded it.

Tim, I'lll give the WebserverST a test run, too.  I had assumed the webserver piece was to blame but I already incoporated 2 different variants of webservers with same results.  Next I guess I'll switch the hardware around just in case I have a bad board somewhere.  I fiddled with the SD briefly already and had no issues with that so the W5100 seemed the culprit.

Days like this make me I wish I had a logic analyzer again.  smiley-yell
23  Using Arduino / Project Guidance / Exasperation: W5100 locking up nRf24L01 (solved) on: April 03, 2013, 09:26:12 pm
Is there any reason I could not simply copy the SPI.cpp/.h to SPI2.cpp/.h, change the SPI pin assignments and talk with the nrf24L01 via 'SPI2' without sharing the pins the W5100 uses?  Does SPI HAVE to be done over pins 10-13 of the Uno? (Yes, I did change the csn for the nRFL2401 to a free pin -- not 10).

Since the SPI code is so small that wouldn't be a big burden I suppose.  Worth it if it eliminates the problem.

Hate to do that but I've had no luck making the two share the bus.  The nRF24L01 randomly stops talking (returns FFFF for every register) after the webserver handles some number of requests.   I actually have to power off the whole UNO to get everything running again.  

I built a sketch with the webduino and RF24 pingpair code co-resident, then after having difficulties again with the standard arduino webserver example sketch+pingpair.  Both sketches work for anywhere from 5 to 120 requests made from a web browser, then the nRF24L01 locks up.  This happens after the browser receives a dozen or so copies of the short HTML block all in one single transmission from the W5100.

I seem to have W5100 shields with the 'inverter fix' that's supposed to correct the so-called SPI bug that first plagued the W5100 implementations.  I also have a couple of the ENC28J60 boards to try, hoping they could do better, if it's an actual SPI problem with the W5100.  I expect more headaches getting those to function however as they are not so mainstream as the W5100.
24  Using Arduino / Project Guidance / Encapsulating RF24 into my own library on: March 13, 2013, 07:16:21 pm
Goal:  Moving all the details of RF24 comms out of my mainline code into a library.

I have been successful in building NRF24L01 data links using the ManiacBug examples and libraries

What I'd like to do is move all the logic into my own library and inherit the RF24 library into my class(es) before I start building all sorts of message functions on top of that.

  • Is this even a good idea with respect the way RF24 is architected?
    Is my stab at coding (below) appropriate (from an arduino and a C language perspective)?  I'm not that well-versed in C and this is as much for improving my skills as it is for creating a working end product.

One thing that puzzles me is how the RF24 class initializes with cepin and cspin parameters.  I put what I originally coded inline in my simple testing sketches into the .begin() of my AlarmReceiver class.  Is that the correct way to initialize the RF24 object so my class can use it?

Try to overlook the fact I have not properly declared variables such as payload, _cepin and _cspin, as I'm at the stage where I'm just trying to establish how the library pieces will fit together, not getting something that will necessarily please the compiler.  I saw the 'Hierarchy' tutorial but it is far, far from being complete so I still have a number of blind spots to work through.

Code:
#include <Arduino.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "AlarmReceiver.h"


AlarmReceiver::AlarmReceiver(cepin, cspin) : public RF24 {

_cepin = cepin;
_cspin = cspin;
}

AlarmReceiver::begin() {

RF24 _radio(_cepin, _cspin);

}

void AlarmReceiver::open(uint64_t pipe)
{
uint64_t _pipe = pipe;

_radio.begin();
_radio.setRetries(15,15);
_radio.setPayloadSize(8);
_radio.openReadingPipe(1,_pipe);
_radio.startListening();
}

unsigned long AlarmReceiver::listen() {

    if ( _radio.available() )
    {
      // Dump the payloads until we've gotten everything
      bool done = false;
      while (!done)
      {
        // Fetch the payload, and see if this was the last one.
        done = _radio.read( &payload, sizeof(unsigned long) );

      }
}

return payload;
}
25  Topics / Home Automation and Networked Objects / Re: Sending Data to a Mysql WebServeur using POST method on: February 03, 2013, 06:27:12 pm
@JohnHoward,
Please carefully read my reply #11, re trying without using DHCP, and understand the configuration of your router(s) between Arduino and server.
Also my reply #13, your initial problem of connection issues had little to with what the OP, royalldonkey was asking and so we are mixing up this thread with multiple issues.

@royalldonkey, can you tell us your status?


Apparently I need to explicitly say I was trying to solve the OP's problem for him, hence "my POST above should do what you are trying to do."  And I thought I had, with one reservation which I had noted. It's not terribly polite to lash out at someone about 'thread hijacking' for simply trying to help.  Or at any time, really.
26  Using Arduino / Project Guidance / Re: Arduino MEGA Pinout Diagram on: February 03, 2013, 02:11:29 pm
It's a beautiful thing!  I had recently Googled for the longest time and found some pics of pins, some pics of pin numbers, and still other with different bits of info.  This is what I had been searching for.  Everything in one place.

Thank you!!!
27  Topics / Home Automation and Networked Objects / Re: Sending Data to a Mysql WebServeur using POST method on: February 03, 2013, 01:37:58 pm
Royalldonkey, and others:  I continued to play with this, using the code from zoomkat to build something that would POST as you were POSTing.  I came up with this, which does work -- with a caveat (see below):

Code:
//zoomkat 9-22-12
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields

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

byte mac[] = {
  0xAA, 0xBB, 0xCC, 0xDD, 0xEF, 0x02 };  // Arduino MAC address
byte ip[] = {
  192, 168, 0, 11 };  // Arduino IP address
byte server[] = {
  192,168,0,13 }; // Directly address the web server
char serverName[] = "localhost.at-home";  // If used, will initiate a DNS lookup of web server
//String response;

EthernetClient client;

//////////////////////

void setup(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600);
  Serial.println("Even better client test 02/03/13"); // so I can keep track of what is loaded
  Serial.println("Send a g to GET or a p to POST in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    switch (inChar) {  // checks to see byte is an e
      case 'e': // Backwards compatibility
      case 'g': sendGET(); // call sendGET function below when byte is an e (or g)
                break;
      case 'p': sendPOST();
                break;
    }
  } 
}

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /arduino.php?test=data HTTP/1.0"); //download text
    client.println("Host: localhost.at-home");
    client.println(); //end of get request
  }
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}//////////////////////////

void sendPOST() //client function to send/receive POST request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
   
    Serial.println("POST /arduino.php HTTP/1.1"); //download text
    Serial.println("From: Arduino1");
    Serial.println("Host: localhost.at-home");
    Serial.println("User-Agent: HTTPTool/1.1");
    Serial.println("Connection: close");
    Serial.println("Cache-Control : no-cache");
    Serial.println("Pragma: no-cache");
    Serial.println("Expires: -1");
    Serial.println("Content-Type: application/x-www-form-urlencoded");
    Serial.print("Content-Length: ");
    Serial.println(31);
    Serial.println();
    Serial.println("data=ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    Serial.println();

    client.println("POST /arduino.php HTTP/1.1"); //download text
    client.println("From: Arduino1");
    client.println("Host: localhost.at-home");  // Will be needed if apache is configured for VHOSTS
    client.println("User-Agent: HTTPTool/1.1");
    client.println("Connection: close");
    client.println("Cache-Control : no-cache");
    client.println("Pragma: no-cache");
    client.println("Expires: -1");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.print("Content-Length: ");
    client.println(31);
    client.println();
    client.println("data=ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    client.println();

    Serial.println("ARDUINO: HTTP message sent");
    delay(3000);
    if(client.available())
    {
      Serial.println("ARDUINO: HTTP message received");
      Serial.println("ARDUINO: printing received headers and script response...\n");

      while(client.available())
      {
        char c = client.read();
        Serial.print(c);
      }
    }
    else
    {
      Serial.println("ARDUINO: no response received / no response received in time");
    }

    client.stop();
  }
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}
/* arduino.php

<?php
echo 
"hello there\r\n";

foreach ($_POST as $key => $value) {

echo "$key=$value\r\n";
}
?>


*/

What I could never do was talk to a webserver on the same subnet as my Arduino.  It has to be a configuration issue, but I can't figure it out.  I have my Arduino on 192.168.0.11 and webserver on 192.168.0.13.  The Arduino never connects to it.  If I simply change the address of the webserver to 192.168.100.1, it works like a champ.  If I use a serverName and reference something outside my local network, it works fine.

So other than that, my POST above should do what you are trying to do.

I hope someone can chime in a explain the wierdness with same-subnet connections.  I have verified the webserver is running and working.   It is just a normal apache 2.2 server.  Deep inspection of the code and the WireShark traces shows me the wiznet library simply never talks to the same-subnet server.
28  Topics / Home Automation and Networked Objects / Re: Sending Data to a Mysql WebServeur using POST method on: February 02, 2013, 10:54:02 pm
I've been wrestling with this (the OP's code), and all the standard examples, trying to get a connection established to a webserver.  The connection never succeeds.

I have found that this bit of code (at line 61 in EthernetClient.cpp) hangs up, getting a status of 21 instead of the SnSR::ESTABLISHED (17) it is looking for:

  while (status() != SnSR::ESTABLISHED) {
    delay(1);
    if (status() == SnSR::CLOSED) {
      _sock = MAX_SOCK_NUM;
      return 0;
    }
  }

I have tried changing SnSR::ESTABLISHED to have a value of 21 but still no luck getting connected.  Looking deeper, I can see the SPI code in W5100Class::read(uint16_t _addr) is indeed reading '21' from the W5100.

Beats me what's going wrong.  Accepting incoming connections from my browser--  communicating with the WebServer example code -- work just fine.

Looking at WireShark traces, there is evidence of the DHCP request being fufilled and an IP address being handed out.  THEN, a couple 'blackjack' port 1025 messages are sent from the arduino and that's it.

No idea what is going awry or what else to try to troubleshoot it.
29  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Network causing severe battery drain on WiFi connected devices. on: February 01, 2013, 08:06:21 pm
Put a cheap router between them and have two subnets (such as 198.168.0.* and 198.168.1.*), or if your gear is capable, change the routing in it to implement this.  The ARPs will not find their way off the arduino's subnet to the other one where your phones and tablets are connected.

I'll hedge a bit and say I'm pretty sure that will solve the problem, but not 100%.  ARP is OSI L1 and therefore does not pass through the router.
30  Using Arduino / Displays / Re: Is it possible to display an Analog meter with Arduino? on: February 01, 2013, 07:54:10 pm
Please.  PLEASE!!!  Do not ruin that beautiful vintage gear by jamming a digital meter into it.  Have a little respect for the little beastie.

(OK, overly dramatic, I know.  But I just hate to see that sort of thing done, especially to such well preserved tube-era hardware.)
Pages: 1 [2] 3 4