Author Topic: RFduinoGZLL.sendToDevice HELP  (Read 4011 times)

MAVMaster

  • RFduino Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
RFduinoGZLL.sendToDevice HELP
« on: July 28, 2014, 10:17:47 AM »
I have code where a variable is changing from an inputted PWM value. I calculate this PWM time on the Host side and need to send the "value" to the device using GZLL. I have everything setup and modified to the github example. Will these line of code  send the value if all I have for GZLL in the code is-

#include <RFduinoGZLL.h>
device_t role = HOST;

void setup()
{
    RFduinoGZLL.begin(role);
}

void loop()'
{
       RFduinoGZLL.sendToDevice(pulsetime);          #pulsetime being the variable
}

This is the Host end of the code only. Will this successfully send that variable to the device, so the device can use it in a calculation?

lsnyman

  • RFduino Sr. Member
  • ****
  • Posts: 142
  • Karma: +1/-0
    • View Profile
Re: RFduinoGZLL.sendToDevice HELP
« Reply #1 on: July 28, 2014, 01:55:24 PM »
I believe you need the device name, otherwise the host is sending to nobody.
Code: [Select]
RFduinoGZLL.sendToDevice(device, data);Actually it will not even compile without it.
« Last Edit: July 28, 2014, 01:57:47 PM by lsnyman »

MAVMaster

  • RFduino Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: RFduinoGZLL.sendToDevice HELP
« Reply #2 on: July 29, 2014, 09:51:03 AM »
This is the code I have for the Host. I'm brand new to Bluetooth related stuff. Been working on arduino for awhile. I understand the interrupt portion of my code. I will have to fix some small stuff, but on the GZLL side, I will have one HOST sending data to a Device. The Device will not send any data back to the host (but if I understand correctly it needs to acknowledge the HOST). The void calculates the PWM pulse time. I need to send that changing number to the device to process into an algorithm. I will have my pseudo code for the Device later today.



#include <RFduinoGZLL.h>
#define temperaturepin 12

device_t role = HOST;

volatile unsigned long temperaturetimerstart;
volatile int temperaturepulsestart;

void setup()
{
   temperaturetimerstart = 0;
   attachInterrupt(temperaturepin, calc_PWMtemperature, CHANGE)
}

void loop()
{
   RFduinoGZLL.sendToDevice(DEVICE0, temperaturepulsetime);    //Will this send the
                                                                                                        //temperaturepulsetime value to
                                                                                                       //Device0
}

void calc_PWMtemperature()
{
   if(digitalRead(temperaturepin) == HIGH)
      {
         temperaturetimerstart = micros();
      }
      
   else
   {
      if(temperaturetimerstart > 0)
      {
         temperaturepulsetime = ((volatile int)micros() - temperaturetimerstart);
         temperaturetimerstart = 0
      }
   }
}

ChenWXKenny

  • RFduino Jr. Member
  • **
  • Posts: 39
  • Karma: +1/-0
    • View Profile
Re: RFduinoGZLL.sendToDevice HELP
« Reply #3 on: July 29, 2014, 08:04:00 PM »
I think you need the device to initiate communication before the host can send anything to the device. Look at the GZLL example, Host to Device.

mkay

  • RFduino Team
  • *****
  • Posts: 405
  • Karma: +15/-0
    • View Profile
Re: RFduinoGZLL.sendToDevice HELP
« Reply #4 on: July 30, 2014, 10:48:28 AM »
Looks like you are missing RFduinoGZLL.begin(role); to start GZLL

Gorm Aaen

  • RFduino Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: RFduinoGZLL.sendToDevice HELP
« Reply #5 on: October 30, 2014, 04:22:40 AM »
Hi folks,

I am having similar issues with RFduinoGZLL.sendToDevice....

I'm new to this GZLL thing and while doing some basic testing I'm getting a strange behavior..for me that is  ;)

I'm using the basic Gazelle examples as the boilerplate.

For the Host I create a very simple ecco host (send back the message you just got) with the following code:

 
Code: [Select]
#include <RFduinoGZLL.h>

device_t role = HOST;

void setup()
{
 
  // start the GZLL stack
  RFduinoGZLL.begin(role);
}


void loop()
{
  //nothing here..
 
}


void RFduinoGZLL_onReceive(device_t device, int rssi, char *data, int len)
{
 
   if (len > 0)
   {
    char mydata[len + 1];
    memcpy(mydata, data, len);
    mydata[len] = 0;
    RFduinoGZLL.sendToDevice(device, mydata[0]);
   }
 
}

For the Device I use the Device GZLL example and just add some char text.   The idea is now: press key send char A or B (toggle) and print the response from Host (should also be A or B respectively..since the Host is just eccoing).  The Device Code:

Code: [Select]
#include <RFduinoGZLL.h>

device_t role = DEVICE0;

// pin for Button A on the RGB Shield
int button_a = 5;

// debounce time (in ms)
int debounce_time = 10;

char m;
char rm;


// maximum debounce timeout (in ms)
int debounce_timeout = 100;

// starting state is off
char state = 0;

void setup()
{
  pinMode(button_a, INPUT);

  Serial.begin(9600);

  // start the GZLL stack
  RFduinoGZLL.begin(role);
}

int debounce(int button, int state)
{
  int start = millis();
  int debounce_start = start;
 
  while (millis() - start < debounce_timeout)
    if (digitalRead(button) == state)
    {
      if (millis() - debounce_start >= debounce_time)
        return 1;
    }
    else
      debounce_start = millis();

  return 0;
}

int delay_until_button(int button, int state)
{
  while (! debounce(button, state))
    ;
}

void loop()
{
  delay_until_button(button_a, HIGH);
 
  // toggle state
  state = ! state;

  if(state) { m= 'A'; } else {m = 'B';}
  // send state to Host
  RFduinoGZLL.sendToHost(m);
  Serial.print("Sending Message:");
  Serial.println(m);
 
  delay_until_button(button_a, LOW);
}

void RFduinoGZLL_onReceive(device_t device, int rssi, char *data, int len)
{
 
 
   if (len > 0)
   {
    char mydata[len + 1];
    memcpy(mydata, data, len);
    mydata[len] = 0;
    Serial.print("Return Msg:");
    Serial.println(mydata[0]);
   }
   
}


I hook the Device up to a serial monitor and observe some weird behavior:
1.  If the HOST is not powered up and we press the button a couple of times, wait 10 secs, then power up the Host we observe that the Device receives a couple of responses.  It seems the Device is queuing the outbound messages...but for how long and can we clear this buffer?
2. There Device message and the response from the Host quickly become out of sync...we send message A but get response B....any ideas?

Any pointers would be greatly appreciated  :D

Niki_SL

  • RFduino Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: RFduinoGZLL.sendToDevice HELP
« Reply #6 on: May 03, 2016, 12:21:39 PM »
Same Problem here. I'm digging into it. Posting solutions if I find some...

Niki_SL

  • RFduino Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: RFduinoGZLL.sendToDevice HELP
« Reply #7 on: May 15, 2016, 09:45:37 AM »
I know the if statement is a bit clumsy but it workes.
Hope it helps.

Code: [Select]
#include <RFduinoGZLL.h>

device_t role = DEVICE0;

long lastrfsend;
long checktime;
int five = 5;
void setup()
{
  // start the GZLL stack
  RFduinoGZLL.begin(role);
}

void loop()
{
checktime = millis() + 2000;
  if(lastrfsend > five) {
    if(lastrfsend<checktime){
    RFduinoGZLL.end();
    Serial.println("GZLL ended");
    RFduinoGZLL.begin(role); //Starts GZLL stack
    lastrfsend = 1;
    Serial.println("GZLL started");
    }
  }

RFduinoGZLL.sendToHost(stringtosend);
lastrfsend = millis();


}

void RFduinoGZLL_onReceive(device_t device, int rssi, char *data, int len)
{
  process(data);
}