Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Programming Questions / Re: Download file via HTTP-request/response on: January 21, 2014, 02:06:41 pm
So... to take this a step further.

Anyone know if it's possible to use a "start-of-data"-> data -> "end-of-data"?

In my case, i knew the exact size, hence: Content-Length: xxxxx

I have a new case where i don't know the size of the file.

Any ideas?
2  Using Arduino / Microcontrollers / Re: Where is serial buffer? on: January 21, 2014, 11:19:57 am
A test showed that the buffer is in the dynamic data memory.

The amount of Bytes used is more than 1:1,  but i couldn't figure out how to calculate it.

3  Using Arduino / Microcontrollers / Where is serial buffer? on: January 21, 2014, 10:46:05 am
Where is the serial buffer located in Ar MEga 2560? in data or program memory?

I know that the default size is 64B and that i can increase that value. So i need to know if it will shrink my data -memory or not.

Also, there're 4 serial ports on the MEGA. Do they share the 64B buffer or is it 64B x4 in total?

thanx
4  Using Arduino / Programming Questions / Re: Download file via HTTP-request/response on: January 21, 2014, 08:19:49 am
This won't work. It sends a blank line, indicating end of header.
Code:
 Serial.println("HTTP/1.1 200 OK\r\n");
Remove the "\r\n" from it.

I did not check the rest of it because you didn't include it in your post. That was what PaulS was saying.
"If the OP thinks it isn't important enough to post, it probably is".

This was not the problem.
I have the double enofLines in my code now, and it works just fine.
After the content-length however, there must be empty row.
Yes it was, just not the only one.


Well, strange, considering it works for me right now, with that line intact...
5  Using Arduino / Programming Questions / Re: Download file via HTTP-request/response on: January 21, 2014, 07:30:00 am
This won't work. It sends a blank line, indicating end of header.
Code:
  Serial.println("HTTP/1.1 200 OK\r\n");
Remove the "\r\n" from it.

I did not check the rest of it because you didn't include it in your post. That was what PaulS was saying.
"If the OP thinks it isn't important enough to post, it probably is".

This was not the problem.
I have the double enofLines in my code now, and it works just fine.
After the content-length however, there must be empty row.

6  Using Arduino / Programming Questions / Re: Download file via HTTP-request/response on: January 20, 2014, 05:19:02 pm
Headers must have a colon separating them from the rest of the line.

Try this:
Code:
Content-disposition: attachment;filename="myfile.csv"

-br

haha... of course, how did i miss that one!? :S
Thanx alot billroy!
7  Using Arduino / Programming Questions / Re: Download file via HTTP-request/response on: January 20, 2014, 05:01:17 pm
Actually, the code i posted was all i had at the time. The result was that nothing happened.
My expectations were a downloaded CSV-file. Obviously.

So i gave all the info i had at the time.  I also decided to include the code i had at that time, in order to show what i've tried.
If i hadn't post a example code, you guys would've moaned about the absence of an example, etc etc.

 
SurferTim was right though, double break lines doesn't seem to work. However, this was not the only problem.


Now, i got it to work, almost.

an update:
After some testing, i almost got this working:

Code:
an update:
After some testing, i almost got this working:

HTTP/1.1 200 OK
Content-Description: File Transfer"
Content-Type: application/force-download
Content-Type: application/CSV
content-disposition attachment;filename="myfile.csv"
Pragma: public
Pragma: no-cache
Content-Length: 20
 \r\n
1;2;3;4;5;6;7:8;9;0;\r\n"

The browser starts to download a file, however, the filename is not "myfile.csv".  The filename comes from my "querystring".
For example:  http://192.168.111.1/xyz   
HTTP-request : GET /xyz/HTTP/1.1

the downloaded file is called xyz (without extension).

Any ideas why the "content-disposition attachment;filename="myfile.csv" is not working?

8  Using Arduino / Programming Questions / Re: "Generic" Pointer? on: January 18, 2014, 02:31:55 pm
But if this pointer is "generic", in myFunction() how you can know what kind of variable/object it point?
I don't know... you're the experts here !:)

I found some solutions in this thread: http://forum.arduino.cc/index.php?topic=211398.new#new

Overloaded functions are ok, but they take up much more Program memory, and makes code-changing more difficult, since one change must be made in several places.  Debugging is more difficult aswell.
9  Using Arduino / Programming Questions / "Generic" Pointer? on: January 18, 2014, 01:32:51 pm
To make a short version of my problem, I have a function that needs to take a String or a byte-pointer.

I could achieve that via a function overload, ie:

void myFunction(String *myStr,....){}
void myFunction(byte *myByte,....){}

Is there a way to do that with only one function? Is there a "generic" data pointer that can point to different data formats?

1. Should i use an void* and send the data size as a parameter?
2. go with templates?
3. Use malloc to get the data size in myFunction?
4. any other way?

For now, i 'll just be handling String and byte, but may have to expand to other datatypes as well.

10  Using Arduino / Programming Questions / Re: Download file via HTTP-request/response on: January 18, 2014, 01:00:28 pm
To answer both your questions.
The csv is created in real-time.
I know the exact size before-hand, since i know how many values and the length of every value.

The 1000 here above was just an example.

I'll check with the fine folks at snippets-r-us. Thanx for the tip.
11  Using Arduino / Programming Questions / Re: Where to put variables on: January 18, 2014, 12:44:44 pm
Quote
.substring(), charAt(), split() etc is functions that are priceless.
Worthless, not priceless. They simply implement C string functions so you can use them without bothering yourself with how they work. Instead, you have to learn how substrng(), etc. work. How that is easier, I don't understand.

As long as one can RTFM, it's quite easy i'd say. smiley
So you mean that we should invent the wheel again, and make functions that do these things? Please walk me throght the advantages in using implemented function vs writing your own.

Ok, it's quite easy to do your own functions for Substring, charAt etc . it's just a for loop with a index from...to or a charBuffer
But when it comes to IndexOf(), toFloat(), toInt() etc, it gets a little more complicated.

The easiest is to use  String(charBuffer).indexOf("xxx"), but i don't know the disadvantages of doing this.
I just noticed there's a subfunction called "buffer". ie: tempString.buffer  description "the actual charArray". I'm not sure how to use this though since i cannot find the manual for it.


Also, i do understand why the "pros" are against Strings, due to Memory fragmentation and that the destruction does not always work with String.

From what I've read, the String destruction problem is fixed in 1.5.5 Beta, right?
As far as memory de-fragmentation goes, doesn't String.reserve(x) fix that problem to some extent?

12  Using Arduino / Programming Questions / Re: Where to put variables on: January 17, 2014, 03:00:54 pm
With that method you are basically setting aside 200 bytes that can never be used by anything else for the few times when you will want to do some string manipulation.

All the rest of the time that 200 bytes is completely wasted.

Far far better to only declare the temp string as and when you need it, then the space is recycled afterwards so it can be used for other things instead.  And remember - local variables are allocated on the stack in a linear fashion, not on the heap.

And as for Strings - don't even go there smiley-wink  It's more than just heap fragmentation - it's the whole multiple objects created with lots of memory being copied around the place just to do simple operations.

I ment the stack of course, not the heap! smiley

You're right, when you put it that way. I am wasting those precious 200Bytes at all times. You convinced me, as easy as that! smiley

Regrding String; i know, i know... but they're so handy at times that one just can't stand using them.

.substring(), charAt(), split() etc is functions that are priceless.
Of course, one could always do String(strBuffer).substring(), but is that really better than using the String variable?





 
13  Using Arduino / Programming Questions / Re: Where to put variables on: January 17, 2014, 02:11:17 pm
What about Strings? in regard to memory de-fragmentation etc. Is there any difference??

(Let's forget that lot of you don't like Strings, and that string defragmentation is fixed (?) in 1.5.5)

On many places in my code, i need a quick way to store a String temporarily. For this, i use a global String variable, that is only used for this purpose.  Instead of having a String variable in every method/function.


For example.

String tmpStr;

void Setup(){
tmpStr.reserve(200);
....



void x(){

tmpStr = readLineFromTxtFile();
Serial.print(tmpStr);

...


void y(){

tmpStr = "hello planet";

doSomething(tmpStr);
..



etc.

of course, this requires to always initiate the variable before using it, since we never know what's stored in there from the last time used.

I also have a global strBuf[200] variable for quick use in different places.

A positive side is that i alway know how much heap space i have to deal with and minimizes the stack-heap collision.

Also, i'm lazy. so with this method, i don't have to declare the tmpStr in every function. smiley

Am i totally wrong about my theory?
Please Enlighten me
14  Using Arduino / Programming Questions / Download file via HTTP-request/response on: January 17, 2014, 08:33:05 am
I'm working with a Arduino Mega + a Wifishield v2.2 from Dfrobot.

I have the communicaion up&working.

Can send a HTTP-request from the broweser, and answer back with a HTTP-response + HTML data. So far so good.

Now i want to be able to download a small file, a csv file in my case.

Does anyone have a good code for this? I'we seen alot of examples, but none seems to work.

Note that the shield is lacking a webserver-functionality, so the HTTP-header must be created in real time by the Arduino.

Here's an example (that dosen't  work):

Code:

Serial.println("\n\nSending HTTP RESPONSE WITH CSV-file");
  Serial.println("HTTP/1.1 200 OK\r\n");
  Serial.println("Content-Type: application/CSV"); //text/plain
  Serial.println("content-disposition: attachment; filename=\"myfileName.csv\"");
  // Serial.print("Content-Type: text/csv");
  // Serial.print("\r\n");
  Serial.println("Content-Length: 1000");
  // Serial.println("Connection: close");
  // Serial.println("Refresh: 5");  // refresh the page automatically every 5 sec
  // Serial.print("\r");
  // Serial.print("\n");
  //     Serial.println("Content-Type: text/csv");
  //         Serial.println();
I'll leave my out-commented lines (residue from a lot of experimenting) in there.
15  Using Arduino / Programming Questions / Re: List of Variables and memory space/usage on: January 17, 2014, 08:27:40 am
Quote
3. i notice thar Booleans take up 1Byte, wasting 7bits per variable.

As soon as you have a 1 bit machine, you can have a 1 bit boolean variable.

In the mean time, you can roll your own with a byte array and some functions to allow you to set and test indvidual bytes.
You have a good point Sir.
I thought, maybe, the compiler is so smart that it boundles a bunch of booleans together, to save memory area. But apparently, it doesn't.
Pages: [1] 2 3 4