Arduino Yun and long command line executions

posted in: Arduino, tricks | 0

I recently had a problem while I was making a temperature logger on arduino. The size of strings is really limited.

You can look at this post for more informations. with this answer:

 

I had similar difficulties trying to build JSON using the Arduino String class. Eventually I gave up because I realized I was trying to force large system techniques onto a tiny embedded system. Now I use preallocated char arrays and C functions like sprintf for string manipulation, and I encode data in the most compact way that I can still use from my application.

You might find this link interesting (I didn’t write it):

Five things I never use in Arduino projects….

  1. The String class

On the face if it, the String class in the Arduino library makes string handling easier. It provides a host of functions to do things that you can’t easily do if you represent strings as pointers to char arrays, as is usual in C. So what’s the problem?

The problem is that String operations allocate memory dynamically and in ways that are hard to predict when the inputs to the program are variable, combined with the fact that Arduinos have a very limited amount of RAM (2K on the Arduino Uno). Dynamic memory allocation typically causes memory fragmentation. This means that your program may work correctly for some inputs or a short while, but crashes with other inputs or after a longer time, due to memory exhaustion. Seehttp://critical.eschertech.com/2010/07/30/dynamic-memory-allocation-in-critical-embedded-systems/ for more about why dynamic memory allocation is a bad idea in embedded software implemented in C/C++.

When might I use String? When writing a quick-and-dirty sketch to try something out, as long it doesn’t have to hold together for more than a few minutes!

 Solution

 

 

I found a quick and dirty solution to execute my curl post commands, create a script in /tmp/ write the command line there and execute it.

 

This looks like this:

 

This solution can be used for any type of long command, and you can even add bash loops and conditions.

 

Here is the detailed workflow:

  1. We create a script file in tmp
  2. Write our command to execute
  3. Give Execution rights to the file
  4. Execute it
  5. Read output and print it!

 

Have fun!

 

Leave a Reply