Author Topic: Simblee dual mode (BLE & COM)  (Read 3752 times)

Tim

  • RFduino Sr. Member
  • ****
  • Posts: 115
  • Karma: +2/-0
    • View Profile
Simblee dual mode (BLE & COM)
« on: April 13, 2016, 04:51:27 PM »
Hi all ..

Does anyone have experience with Simblee's dual mode capability. I simplified the SimbleeBLE/DualMode/Gateway sketch to this:

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

void setup() { 
  Serial.begin(9600);
  SimbleeBLE.begin();
}

void loop() {
}

void SimbleeBLE_onConnect() {
  SimbleeBLE.dualModeBegin();
}

void SimbleeBLE_onDisconnect() {
  SimbleeBLE.dualModeEnd();
}

void SimbleeBLE_onReceive(char *data, int len) {
}

void SimbleeBLE_onDualModeStart() {
  Serial.println("1");
}

void SimbleeBLE_onDualModeStop() {
  Serial.println("0");
}

void SimbleeCOM_onReceive(unsigned int esn, const char *payload, int len, int rssi) {
  printf("%s\n", payload);
}

I upload and run the sketch and this happens:

- When an iOS app connects to the Simblee via BLE, the callback SimbleeBLE_onConnect() is called. This callback starts dual mode by calling SimbleeBLE.dualModeBegin().

- This results in the SimbleeBLE_onDualModeStart() callback being called, which prints “1” to the console.

- Unexpectedly, SimbleBLE.onDualModeStop() is called, which prints “0” to the console.

- SimbleeBLE.onDualModeStart() and SimbleeBLE.onDualModeStop() are called again and again, repeatedly, until the iOS app disconnects from the Simblee (and SimbleeBLE_onDisconnect() calls SimbleeBLE.dualModeEnd()).

Furthermore, when I first tried integrating dual mode into our product sketch (which resulted in the same above behaviour), when the sketch attempted to send a message via SimbleeCOM, the SimbleeBLE connection with the iOS app was dropped.

Dual mode is vital to using Simblee in our product. Hopeful for a solution.

Thanks for any insights.

Tim

mark_pdx

  • RFduino Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Simblee dual mode (BLE & COM)
« Reply #1 on: May 04, 2016, 08:14:42 AM »
Hello, Tim,

I'm about to embark on a project that would require Simblee Dual Mode, and I'm curious to know if you ever resolved this question and got your project working?

If not, I would be happy to keep in contact as I try it myself and share anything I can learn.

Thanks!
Mark

tolson

  • Global Moderator
  • *****
  • Posts: 831
  • Karma: +19/-0
    • View Profile
    • Thomas Olson Consulting
Re: Simblee dual mode (BLE & COM)
« Reply #2 on: May 04, 2016, 10:53:01 AM »
Hi Guys,

Please do update this thread with what you discover how things really work.

mark_pdx

  • RFduino Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Simblee dual mode (BLE & COM)
« Reply #3 on: May 04, 2016, 03:33:38 PM »
OK folks, I made it over the first hurdle.

Although I was using a different app to connect to the Simblee (LightBlue Explorer), I observed the _same_ behavior that Tim saw -- the BLE connection was made, the SimbleeBLE.dualModeBegin() statement was executed, and then whammo, the connection seemed to drop; then the cycle would repeat.

But I was lucky to have a clue -- I noticed the LED (that turns on to indicate the BLE connection is active) was dimmer than usual. Forehead slap: the Gazelle protocol keeps the nRF radio receiver on continuously, drawing, who knows, maybe 10 - 20 mA. A 2032 coin cell can't really handle that current on a continuous basis, and the voltage sags.

I put in two coin cells in parallel and presto, now the connection doesn't drop when the dual mode is launched.

All is not figured out yet, but I wanted to share this in case it is the same problem you're having, Tim. Onward...
 

mark_pdx

  • RFduino Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Simblee dual mode (BLE & COM)
« Reply #4 on: May 05, 2016, 05:39:26 PM »
Well, I have now tried several of the example sketches in the Simblee library -- GZLL, SimbleeCOM -- device, host, etc -- and I have yet to see any evidence that a transmitted packet has been received over the link.

At this point I don't know what to do. Has anyone got GZLL or SimbleeCOM signal links working? If so, would you share your code?

Tim

  • RFduino Sr. Member
  • ****
  • Posts: 115
  • Karma: +2/-0
    • View Profile
Re: Simblee dual mode (BLE & COM)
« Reply #5 on: May 16, 2016, 10:57:06 AM »
Hi all ..

I have more information about this, thanks to support from RF Digital.

Basically, because there's only one radio, using it for two protocols (BLE and COM) requires sharing the radio. When in dual mode, Simblee slices time and offers the radio to BLE and COM in alternating slices. That way the BLE connection is maintained and outgoing COM messages can be sent in the slice between two BLE slices.

For sending both BLE and COM messages, this is my understanding of how to do it:

- start BLE; BLE central will connect (BLE connection is now established)
- Simblee can now send and receive BLE messages

When you want to send a COM message, first start dual mode. At this point Simblee is time slicing between BLE and COM. You can't simply send the COM message. You have to wait until SimbleeBLE_onDualModeStart is called because only at that point is the radio available for COM messaging. So your SimbleeCOM.send call must be in your SimbleeBLE_onDualModeStart routine. So to send a COM message, the general approach is:

- start dual mode
- in SimbleeBLE_onDualModeStart, call SimbleeCOM.send
- end dual mode

That's for sending BLE and COM. Unfortunately it's not so simple for receiving BLE and COM messages. This requires some coordination of your devices because the radio cannot be in a receive state for both BLE and COM protocols at the same time. In other words, your device needs to know when to expect BLE messages and when to expect COM messages. You can't just start dual mode and have reliable receipt of either BLE or COM messages because at the precise instant a message arrives at the radio, the radio might be listening for messages of the other type.

For our product, BLE is the dominant messaging protocol so BLE is on and Simblee is connected to a BLE central all of the time. When we need to send COM messages between devices (once every 20 minutes or so, to keep clocks in sync), we:

- stop BLE, which drops the connection with the BLE central
- start COM
- send/receive COM messages
- end COM
- start BLE and the BLE central reconnects

This whole process with 2 Simblees, from the point BLE is stopped on the Simblees, to the point where the BLE connection on the BLE central (iOS app) is restored, is anywhere from 1-4 seconds, which is acceptable.

I hope this is helpful.

Tim

duffo64

  • RFduino Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Simblee dual mode (BLE & COM)
« Reply #6 on: May 17, 2016, 12:34:09 PM »
I hope this is helpful.
Sure it is, Tim.

Thanks a million for clarifying.

Claudio
« Last Edit: May 17, 2016, 12:35:56 PM by duffo64 »

duffo64

  • RFduino Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Simblee dual mode (BLE & COM)
« Reply #7 on: June 04, 2016, 02:50:21 AM »
Forehead slap: the Gazelle protocol keeps the nRF radio receiver on continuously, drawing, who knows, maybe 10 - 20 mA. A 2032 coin cell can't really handle that current on a continuous basis, and the voltage sags.
Confirmed about hungriness. I tried only com transmitter like an unconventional iBeacon and the avg current is around 4 mA. Unfortunately, putting in the loop() an ulpdelay does not work, as the transmission is interrupted. An cr2032 cell would last only two days at this rate.
« Last Edit: June 04, 2016, 02:54:41 AM by duffo64 »

RFD_Patty

  • RFduino Team
  • *****
  • Posts: 45
  • Karma: +2/-0
    • View Profile
Re: Simblee dual mode (BLE & COM)
« Reply #8 on: June 13, 2016, 12:11:13 PM »
Those values are not typical.   If you can send your sketch to support @ simblee dot com, we will be happy to review it for you.

RFD_Patty

  • RFduino Team
  • *****
  • Posts: 45
  • Karma: +2/-0
    • View Profile
Re: Simblee dual mode (BLE & COM)
« Reply #9 on: June 15, 2016, 03:18:34 PM »
Response from RFD Tech Support

When trying to keep current consumption low on the transmitter side, it's best to limit the number of transmissions that is sent out. In this case, transmissions are triggered when the pin changes it's read in.

I've also placed a ULP delay in the code as well. One thing to note is that you'll need to call SimbleeCOM.end(); before entering ULP delay, and call SimbleeCOM.begin(); after exiting ULP delay to transmit.

Example Code:

SimbleeCom Button Send

Code: [Select]
/*
 * SimbleeCOM Button Send
 * Input Device Unit
 * Copyright © 2016 RF Digital. All Rights Reserved
 */
 
#include "SimbleeCOM.h"

char packets[] = {0};

// pin 5 on the RGB shield is button 1
int button = 5;

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

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

void setup()
{
  // put your setup code here, to run once:
  pinMode(button, INPUT);
  SimbleeCOM.begin();
}

void loop()
{
  // put your main code here, to run repeatedly:
  delay_until_button(HIGH);
  packets[0] = 1;
  SimbleeCOM.send(packets, sizeof(packets));
 
  delay_until_button(LOW);
  packets[0] = 0;
  SimbleeCOM.send(packets, sizeof(packets));
}

int debounce(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 state)
{
  SimbleeCOM.end();   // end SimbleeCOM before starting ULP
  // set button edge to wake up on
  if (state)
    Simblee_pinWake(button, HIGH);
  else
    Simblee_pinWake(button, LOW);

  do
    // switch to lower power mode until a button edge wakes us up
    Simblee_ULPDelay(INFINITE);
  while (! debounce(state));

  // if multiple buttons were configured, this is how you would determine what woke you up
  if (Simblee_pinWoke(button))
  {
    // execute code here
    Simblee_resetPinWake(button);
  }
  SimbleeCOM.begin(); // start SimbleeCOM after leaving ULP
}

Example Code:

SimbleeCom Button Receive

Code: [Select]
/*
 * SimbleeCOM Button Receive
 * Output Device Unit
 * Copyright © 2016 RF Digital. All Rights Reserved
 */

#include "SimbleeCOM.h"

void setup() {
  Serial.begin(9600);
  pinMode(3, OUTPUT);

  SimbleeCOM.begin();
}

void loop()
{
 
}

void SimbleeCOM_onReceive(unsigned int esn, const char *payload, int len, int rssi)
{
  printf("%d ", rssi);
  printf("0x%08x ", esn);
  for (int i = 0; i < len; i++)
    printf("%02x ", payload[i]);
  printf("\n");

  if (payload[0] == 1)
    digitalWrite(3, payload[0]);
  else
    digitalWrite(3, payload[0]);
}

 

anything