How to change size of readstring() in client.read() on Arduino Ethernet?

I mean another command which is lighter than

if(strstr(tBuf,"example") != NULL) {
  // example exists
}

As for the F() function...I haven't seen any like that. What does the F do?

I haven't thought about one that is lighter (smaller, simpler?).

The F() function allows the sketch to use those strings from program memory without transferring them to SRAM first.

But when I remove all the strstr commands the sketch has 1996 bytes of free sram.

nathanas:
But when I remove all the strstr commands the sketch has 1996 bytes of free sram.

I intentionally ran mine out of SRAM allocating large arrays and initializing the first member. When it runs out of memory, as I suspected it might, it shows wild amounts of free SRAM. I have 8K, and it did fine until the memory finally ran out. When it ran it out, it showed "SRAM free: 11753". I don't have that much!

I'm not happy at all...
I wanted to make the ethernet arduino work as a web server, data logger, and more.
But unfortunately it can't search some strings... :frowning:

If you get your SRAM use under control with the F() function, you should be able to add those strstr() commands without causing a fail. It is the little bit of extra SRAM they use that is causing the SRAM overflow and the crash.

You are right! It was a memory problem. I managed to get some bytes free and now I am good to go...Thats a same that arduino still uses atmega328p. I love it but we need more memory for our projects...!!!

May I suggest a Mega2560/Ethernet shield? :smiley:
It took a bunch of big arrays to run it out of SRAM.

Does it work well enough with the SD card simulationly with the ethernet ?
I have read that ethernet arduino stucks sometimes and needs a reset when changing from ethernet to SD... Is this true?
And you use a regular arduino shield or another especially for your MEGA board?

I use the w5100 and SD card together a lot. That is how I get my files into my SD card. I use a FTP program to transfer them to and from a FTP server. That program may be a bit too memory heavy to use on an Uno or Arduino Ethernet tho. That is why I have a Mega.
http://playground.arduino.cc/Code/FTP
That sketch uses two sockets on the w5100 (one command and one data) and the SD together. Smooth!! :slight_smile:

Is there a way to use this example with TCP packets?
Because I want to login a user of a specific IP.
I dont think UDP packets can be sent through html... I didn;t find anything on google..

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {  
  0x00, 0x00, 0xAA, 0xBB, 0xCC, 0xDD };
IPAddress ip(192, 168, 10, 110);

unsigned int localPort = 8870;      // local port to listen on

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);
}

void loop() {

  int packetSize = Udp.parsePacket();
  Serial.print("1 ");
  if(packetSize)
  {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From IP : ");

    IPAddress remote = Udp.remoteIP();
    //print out the remote connection's IP address
    Serial.print(remote);

    Serial.print(" on port : ");
    //print out the remote connection's port
    Serial.println(Udp.remotePort());
  }

}

How can I copy the "clientIP" value to another array? because I need to compare them afterwards..
I managed to receive the remote IP address but I don't know how to save it.

I declared "char loggedip[];"
and then I try to copy it like that... loggedip[0]=clientIP; but I get other values.
I read that IPAddress value is a unit32_t byte and when I try to strcpy it says I cannot convert it to char.

Can anyone help?

Here is how to use it.

IPAddress clientIP = Ethernet.localIP();
Serial.println(clientIP);
Serial.print(clientIP[0]);
Serial.print(".");
Serial.print(clientIP[1]);
Serial.print(".");
Serial.print(clientIP[2]);
Serial.print(".");
Serial.println(clientIP[3]);

What I do: Serial.println(clientIP);
All I need is to store the IP to an array and then compare it again with the "clientIP" value
I dont care about the format as I can see it using serial.print

Something like that: "loggedip[]= clientIP[];"

How can I copy the "clientIP" value to another array? because I need to compare them afterwards..
I managed to receive the remote IP address but I don't know how to save it.

Start with showing this code.

If you get the IP address as a string, that is not the same type as an IPAddress.

If you have the IP address as 4 bytes, you can simply declare two IPAddress variables, using the same 4 bytes.

If you want to copy the 4 byte array, use a for loop, and copy each element of the array.

Thinking on going to something like this board!
But unfortunately it doesn't support 5V.. :frowning:
http://grobotronics.com/arduino-due-el.html#.UMSDu4N9Dh4

As for the IP serial print code here it is below...

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {  
  0x00, 0x00, 0xAA, 0xBB, 0xCC, 0xDD };
IPAddress ip(192, 168, 10, 110);

// local port to listen on

// An EthernetUDP instance to let us send and receive packets over UDP

EthernetServer server(8070);
void setup() {
  Serial.begin(9600);
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);

  server.begin();
}

void loop() {

  EthernetClient client = server.available();
  Serial.println("Waiting for client... ");
  if(client) {
    Serial.println("Client request!!!! ");
    while (client.connected()) {
      while(client.available()) {
        char c = client.read();
        if (c == '\n' ) {
          client.stop();
        }
        Serial.print("Received packet ...    ");

        Serial.print("From IP : ");

        IPAddress clientIP = client.remoteIP();
        //print out the remote connection's IP address
        Serial.println(clientIP);



      }
    }
  }
}

I've made some changes to the Ethernet.cpp/.h & EthernetClient.cpp/.h files so the " IPAddress clientIP = client.remoteIP();" works.. The changes where made according to SurferTim's link I found from arduino forum.

This is how. Change testIP to another ip. It will not match.

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

IPAddress clientIP(192,168,2,2);
IPAddress testIP(192,168,2,2);

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

  if(clientIP == testIP) Serial.println("match");
  else Serial.println("no match");

  if(clientIP[0] == testIP[0] && clientIP[1] == testIP[1] && clientIP[2] == testIP[2]) {
    Serial.println("Same subnet");
  }
  else Serial.println("different subnets");
}

void loop() {
}

Here is a firewall-type code using the array of IPAddress types. See reply #1.
http://arduino.cc/forum/index.php/topic,135082.0.html

edit: Here is the way I have this planned. One ip changes, the subnet views, and all others are rejected.

if(clientIP == testIP) {
  Serial.println("match");
  // get input from the GET, process, and send page with form inputs here
}
else if(clientIP[0] == testIP[0] && clientIP[1] == testIP[1] && clientIP[2] == testIP[2]) {
  Serial.println("Same subnet");
  // do not get input. send page with data, but no form
}
else {
  Serial.println("different subnets");
  // send 401 Unauthorized page
}

I just bought my Arduino Mega 2560 today and an ethrnet shield. But unfortunately when I tried to compile the same sketch on the mega says:

c:/program files/arduino-1.0.2/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr6/crtm2560.o: In function `__vector_default':
(.vectors+0x8): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_2' defined in .text section in c:/program files/arduino-1.0.2/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr6/crtm2560.o

What same sketch? Didn't I compile that for you to check memory? It did ok here. All my tests are on a Mega2560/ethernet shield with a uSD card and IDE v1.0.2. However, I use Ubuntu 11.10 and 12.04, not Windows.