arduino-libraries / Bridge

Bridge Library for Arduino
http://arduino.cc/
13 stars 28 forks source link

Bridge.get("key", buffer, 0) takes forever #16

Open Sheldor5 opened 7 years ago

Sheldor5 commented 7 years ago

If the buffer_length is smaller than the actual content of "key" then the Bridge.get() command takes about >5200 ms (yes, more than 5 seconds ...).

Tested with the following code:

#include <Bridge.h>
#define BUFF_LEN 5

bool once = true;
unsigned long start;
unsigned long end;
char *buffer = new char[BUFF_LEN+1] { '\0' };

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Bridge.begin(250000);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (once) {
    delay(1000);
    once = false;
    Bridge.put("key", "Test");

    start = millis();
    Bridge.get("key", buffer, BUFF_LEN);
    end = millis();
    Serial.println(end - start); **// 6ms**

    Bridge.put("key", "TestContent");

    start = millis();
    Bridge.get("key", buffer, BUFF_LEN);
    end = millis();
    Serial.println(end - start); **// 5237ms**

    Bridge.put("key", "Test");

    start = millis();
    Bridge.get("key", buffer, BUFF_LEN);
    end = millis();
    Serial.println(end - start); **// 5237ms**
  }
}

If the buffer_length is bigger than or the exact size of the actual content, it works within ~7ms. Also if the content ONCE is bigger than buffer_length the Bridge.get() will ALLWAYS take >5 seconds, no matter if you reset the content smaller than buffer_length ...

Arduino Yun with Bridge 1.6.3

satmandu commented 6 years ago

For what it is worth, trying to compile the code above in IDE 1.8.5 or later gives this error:

Arduino: 1.8.5 (Linux), Board: "Arduino/Genuino Uno"

/home/.../Arduino/sketch_oct29a/sketch_oct29a.ino: In function 'void loop()':
sketch_oct29a:27: error: void value not ignored as it ought to be
     Bridge.put("key", "TestContent");
                                    ^
sketch_oct29a:34: error: void value not ignored as it ought to be
     Bridge.put("key", "Test");
                             ^
sketch_oct29a:40: error: expected primary-expression before '}' token
   }
   ^
exit status 1
void value not ignored as it ought to be

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.