Author Topic: RFduino Latency Issue  (Read 568 times)

adamh

  • RFduino Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
RFduino Latency Issue
« on: March 09, 2016, 02:00:28 AM »
Hello,

I'm using RFduino in a project in which I control a remote led (GZLL device 0) from the computer (GZLL host). I'm using the following code:
Host:
Code: [Select]
#include <RFduinoGZLL.h>
device_t role = HOST;

struct infoPacket
{
  unsigned long timeToSleep; 
  bool state;       
};

infoPacket packet;

int debounce_time = 10;
int debounce_timeout = 100;

void setup()
{
  Serial.begin(9600);
  Serial.println("Enter timeToSleep and state:");
  RFduinoGZLL.begin(role);
}

void loop()
{
  while (Serial.available() > 0)
  {
    Serial.println("read input:");
    packet.timeToSleep = unsigned long(Serial.parseInt());
    packet.state = boolean(Serial.parseInt());
  }
 
}

void RFduinoGZLL_onReceive(device_t device, int rssi, char *data, int len)
{
  RFduinoGZLL.sendToDevice(device, (char *)&packet, sizeof(packet));
}

And device:
Code: [Select]
#include <RFduinoGZLL.h>
device_t role = DEVICE0;

int green_led = 6;

struct infoPacket
{
  unsigned long timeToSleep; 
  bool state;
};

infoPacket packet;


void setup()
{
  pinMode(green_led, OUTPUT);
  digitalWrite(green_led, LOW);
  RFduinoGZLL.txPowerLevel = -20;
  packet.state = false;            // start with LED off
  packet.timeToSleep = 190;        // in ms

  RFduinoGZLL.begin(role);
 
}

void loop()
{
  RFduino_ULPDelay(packet.timeToSleep);
  RFduinoGZLL.sendToHost(NULL, 0);
  delay(10); 

}

void RFduinoGZLL_onReceive(device_t device, int rssi, char *data, int len)
{
  if (len > 0)
  {
    memcpy( &packet, &data[0], len);
    if (packet.state == true)
    {
      digitalWrite(green_led, HIGH);
    }
    if (packet.state == false)
    {
      digitalWrite(green_led, LOW);
    }
  }
}

However, when I set the timeToSleep to, say, 100ms, the response time is around a second, and when I set the timeToSleep to 5000 (5sec), it takes about 8 seconds (estimated, I can try to measure it exactly if it helps).

Any idea where this difference is coming from? Maybe something in the serial communication between the computer and the host?

Thanks!

 

anything