Max length for runShellCommand()?

I'm trying to send an array of 50 floats to my server via JSON post. It seems there is a limitation on the command length. In addition once the command is longer than ~270 chars then it will take more than 10sec to execute. If the lenght is over ~400 chars then it will just fail. This limitation is not present if I execute the same command via a SSH session (in this case the command executes instantly and I see the post on my server).

I created a simple test script to replicate the problem. This code execute a JSON POST with a progressively longer string. Each iteration adds ~30 chars .

Once you execute the code you'll see 3 medium-length LED flashes, followed by 3 long ones, and a series of rapid ones. Here the length of characters of the command and its execution time (LED-on time) for the first 8 iterations:

length(char):time(ms)
197:548
230:530
263:751
296:10495
329:10551
362:10665
395:148
428:144
...

Can anybody replicate this problem?

#include <Process.h>
int led = 13;
String command;

void setup()
{
  Bridge.begin();   

  pinMode(led, OUTPUT);
  
  command= "curl -k -X POST http://echo.jsontest.com -d 'u=123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
}

void sendData(String o) {
  digitalWrite(led, HIGH);

  Process p;
  p.runShellCommand(o + "'");
  
  digitalWrite(led, LOW);

}


void loop()
{
  //add ~30 char to the JSON post
  command += "&u=123456789012345678901234567890";

  sendData(command);

  delay(250);

}
nano /usr/bin/run-bridge

Re: Problem with YunClient and long strings

http://forum.arduino.cc/index.php?topic=196091.msg1517378#msg1517378

I did modify the two files and the results are strange. First time I executed it, it was correct for length <400 chars. Now, I'm back as the original problem. I double checked and both files still have the correct "python -u" modification. Any idea/suggestion? I tried to restart the Yun and/or upload a sketch, it just makes no difference.

Thanks,
PS: Why is the execution time is orders of magnitude higher than just running the same command via SSH even for length<300?

sonnyyu:

nano /usr/bin/run-bridge

Re: Problem with YunClient and long strings

Problem with YunClient and long strings [solved] - #8 by federicofissore - Arduino Yún - Arduino Forum

I was trying to find an alternative way and I found that this is indeed a generic problem. It is present even if I use httpclient.

Here's the code

#include <Bridge.h>
#include <HttpClient.h>
String o;

HttpClient client;
  
void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();
  Serial.begin(9600);
  while(!Serial);
  o="http://echo.jsontest.com/u?u=1234567890";
}

void loop() {
  o+="&u=1234567890";
  long now=millis();
  client.get(o);
  long del=millis()-now;
  Serial.print(o.length());
  Serial.print("\t");
  Serial.println(String(del));
}

Here's the results of length of request vs time of execution. Once the length reaches ~300 chars the execution time jumps to 10secs.

273	542
286	644
299	10493
312	10490
325	10542
338	10541
351	10597
364	10595
377	10658
390	10660
403	10687
416	10666
429	10737
442	10729

One possibility;-

MCU at Yun is ATmega32u4, SRAM is only 2.5 KB.

The most common cause for RAM exhaustion is using the String object. You might want monitor memory usage.

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

#include <MemoryFree.h>
...
void loop() {

    Serial.println(freeMemory());

    delay(1000);
}

Thanks for the suggestion but it looks there is still plenty of RAM available:

First column is the command length, second is execution time, last column is amount of free memory.

...
286	749	1605
299	10497	1592
...
507	10900	1384
520	866	1371
...
832	760	1059
845	143	1046
...

In addition with the code provided I found that the 10sec increased resolution is only for command length between 299 and 507 chars, the request is executed correctly if <299 or greater than 520 and less than 845. Anything longer than 845 will fail. This weird behavior is only with this code:

#include <Bridge.h>
#include <HttpClient.h>
#include <MemoryFree.h>

String o;

HttpClient client;
  
void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();
  Serial.begin(9600);
  while(!Serial);
  Serial.println("Starting...");
  o="http://echo.jsontest.com/u?u=1234567890";
}

void loop() {
  o+="&u=1234567890";
  long now=millis();
  client.get(o);
  long del=millis()-now;
  Serial.print(o.length());
  Serial.print("\t");
  Serial.print(String(del));
  Serial.print("\t");
  Serial.println(freeMemory());
}

Any suggestion on how I can send an array of 50 floats to a server using the Yun?

Thanks!

The maximum baudrate is 115200 baud. Tests with 230400 baud always failed on the first read attempt.
With the simple Arduino Sketch (see below) the IO-throughput is about 10kB/s.

10kB/s should be meet your requirement.

http://forum.arduino.cc/index.php?topic=191820.msg1423082#msg1423082

very long thread.

Thank Sonnyyu, I don't think I got what you mean. I think this might relates to another topic. I'm trying to send data to my server on Amazon Cloud and it seems quite hard to do with the yun if I need to send relatively large amount of data (50 floats) every sec.

sonnyyu:

The maximum baudrate is 115200 baud. Tests with 230400 baud always failed on the first read attempt.
With the simple Arduino Sketch (see below) the IO-throughput is about 10kB/s.

10kB/s should be meet your requirement.

Tty for serial port to Arduino from Linino - #10 by wayoda - Arduino Yún - Arduino Forum

very long thread.

It means if speed/bandwidth is very important then do not use bridge ( disable it), use pure UART instead of.

ok, now I understand it what do you mean. I thought this has to be a bug since the yun should be able to support 200 bytes/sec (50 floats *4 byte every sec) without any problem. Do you think the problem is getting the data out of the arduino and into the linino part?

The goal is to get the data out of the yun via the wifi connection and it is requiring quite more effort than I thought. Do you think it'll be easier to just use a Uno with a wifi shield? I'm quite a newbie with the yun.

sonnyyu:
It means if speed/bandwidth is very important then do not use bridge ( disable it), use pure UART instead of.

Roger:
...
Do you think it'll be easier to just use a Uno with a wifi shield? I'm quite a newbie with the yun.
...

I doubt.