Buffer data to send on HTTP get requests

Yet another probably really simple question. Hopefully these will diminish with more experience in C++/C

I have my spark core sending an HTTP request to my PHP server on interrupt when an input is tripped. Problem is that this is a blocking call so if you hit the button again while the HTTP request is still processing it will be missed. I need to buffer these packets to be sent. However I see I cannot use the C++ Vector object so how is it recommended that I do this.

In short a button is pressed, interrupt method is called, an unsigned char array is created, this unsigned char array needs to be added to some type of multi dimensional buffer array. In the main loop I need to check this multi dimensional array for new data, if it exists then send the HTTP Request. So the main question, what the heck do I use as the object type for this buffer I need?

Thank you

Hi @IOTrav

It sounds like a two-dimensional char array would work well for what you have in mind.

#define NREQS 4
#define REQSZ 64
char requestArray[NREQS][REQSZ];
int readReq  = 0;
int writeReq = 0;

// in loop() do this
if (readReq != writeReq) { //check for any requests
  //to read out
  Serial.print(requestArray[readReq]);  //treated as a simple char array
  // if done
  if (readReq==NREQS) {

//in the interrupt routine do this
strcpy(requestArray[writeReq++], myOriginalCharStr);
if (writeReq==NREQS) {

That should be enough to get started!

1 Like

You can use the C++ vector object if you add

#undef min
#undef max

Before including the STL headers. I would like replace these macros with template functions, but doing so in a fully backwards compatible way is hard (and the error messages emitted by the compiler with templates isn’t very friendly!)

If you’re writing to this from an ISR, be sure to disable interrupts while reading from this in the main loop.

1 Like

Thank you @mdma I thought for sure we would have access to the vector object but didnt know how. I will certainly start putting it to use.