Method string parameter length limit ?

Hi, I've noticed that when I have method which uses string as input parameter - there is an length limit - when I will past string with more than 71 characters - it empty in method

why is that ?

string or String class?

How do you parse the string to the function? As a string data type or as a char[] or char* data type?

ciolouise222: How do you parse the string to the function? As a string data type or as a char[] or char* data type?

Parse, or pass?

I past as String

logger.info("This is a free online calculator which counts the number of cdsd1234");
void Logger::info(String log)
{
  Serial.println(decorateLog(log));
}

String Logger::decorateLog(String log)
{
  return memoryVariables.getArduinoName() + " (" + String(millis()) + ") " + log;
}

[/code[

have you tried to put the string literal into PROGMEM or using the F() macro?

logger.info(F("This is a free online calculator which counts the number of cdsd1234"));

BulldogLowell: have you tried to put the string literal into PROGMEM or using the F() macro?

logger.info(F("This is a free online calculator which counts the number of cdsd1234"));

That won't work if the function expects a String object.

OP: How much free memory do you have when you try to pass a huge string literal to that function, forcing the allocation of memory to create the String object to wrap the data?

Why does the function take a String, instead of a char *, to avoid needing to allocate memory to hold the String object that wraps the string?

http://playground.arduino.cc/Code/AvailableMemory

PaulS: That won't work if the function expects a String object.

Yup. I didn't consider the member function expects a String, OP could try to change the function to accommodate a pointer to a char array.

But then again, just drop the String class altogether... Always good advice.

PaulS: That won't work if the function expects a String object.

OP: How much free memory do you have when you try to pass a huge string literal to that function, forcing the allocation of memory to create the String object to wrap the data?

Why does the function take a String, instead of a char *, to avoid needing to allocate memory to hold the String object that wraps the string?

http://playground.arduino.cc/Code/AvailableMemory

There is free approximately 215 I'm using String because its easier to operate, concatenate etc

logger.info("EventHandler.processSettingCommand: Move sensor " + moveSensors[i].getCommand() + " has been set to " + String(state));

How should I define method parameter as F("") ?

lonas: I've noticed that when I have method which uses string as input parameter - there is an length limit - when I will past string with more than 71 characters - it empty in method

why is that ?

If you are cultivating a RAM wasting style of programming your microcontroller will soon run out of RAM.

You'd better either learn programming without wasting RAM (not using "String" but char arrays and pointers, not duplicating "String" objects while transferring them as function parameters but transferring char pointers as parameters only). Or purchase a controller board which provides a lot more RAM for supporting a wasteful programming style (perhaps a DUE).

In general I'm printing log only when debug is enabled but I will rewrite Logger class to use arrays and pointers. DUE looks interesting but EEPROM lake is not acceptable for me right now.

but still how can I define method with parameter which is store in flash?

If you use the F macro, you can declare a parameter using const __FlashStringHelper*.

If its a standard PROGMEM declared value, then you can simply use a char*. To determine between a flash or ram string just use different function names. logger.info() / logger.infoF()

Or you can cast your variables to a __FlashStringHelper pointer when you pass them to the function.

Thanks, one more question why I cant concat String in flash ?

  logger.debug(F(String("EventHandler.processCommand: Received command " + inputCommand + " on topic " + inputTopic)));

lonas: Thanks, one more question why I cant concat String in flash ?

Because flash memory is read only memory.

Ok so why this do not work. Im doing concat in variable created before passing to logger.

  String test = "EventHandler.processCommand: Received command " + inputCommand + " on topic " + inputTopic;
  logger.debug(F(test));

I'm using String because its easier to operate, concatenate etc

Not if you know how to manipulate strings. It's a crutch. Everything it does. it does using the wrapped string object. The overhead is NOT worth it.

Ok so why this do not work. Im doing concat in variable created before passing to logger.

Because the F() macro expects a string literal NOT a String object. Ditch the String class!

Oh my - OK so how can I acheive what I need - concatenate strings and put into flash

lonas: Oh my - OK so how can I acheive what I need - concatenate strings and put into flash

Why do you believe you need that? It sounds crazy.