Author Topic: dualMode for BLE+COM  (Read 281 times)

Tim

  • RFduino Sr. Member
  • ****
  • Posts: 126
  • Karma: +2/-0
    • View Profile
dualMode for BLE+COM
« on: July 15, 2017, 05:36:14 PM »
Hi all ...

RDF_Nelson posted a video tutorial on using dual mode on January 12th in the Videos/Guides/Tutorials section and I posted this as a reply there. Thought more of you might see it here though. Hope it's okay to post here also.

Seeing the video sparked some hope that dual mode might be helpful for our project. I can get COM<->COM working, no problem. But BLE+dualMode+COM <-> COM, as shown in the video, appears not to work.

I created very simple sketches to test: Once (sender) sends a COM message every second. The other (replier) sends a reply COM message half a second after receiving a COM message. The replier is straight COM. If the sender is straight COM, all works well. Here are the sender and replier sketches:

Sender - straight COM:

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

void setup() {
  Serial.begin(9600);
  SimbleeCOM.mode = LONG_RANGE;
  SimbleeCOM.begin();
}

void loop() {
  delay(1000);
  SimbleeCOM.send("ABC", 4);
  Serial.println("sent ABC");
}

void SimbleeCOM_onReceive(unsigned int esn, const char *payload, int len, int rssi) {
  Serial.print("received ");
  Serial.println(payload);
}

The replier - straight COM:

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

volatile bool sendAReply = false;

void setup() {
  Serial.begin(9600);
  SimbleeCOM.mode = LONG_RANGE;
  SimbleeCOM.begin();
}

void loop() {
  if (sendAReply) {
    sendAReply = false;
    // Wait half a second before sending reply.
    delay(500);
    SimbleeCOM.send("DEF", 4);
    Serial.println("sent DEF");
  }
}

void SimbleeCOM_onReceive(unsigned int esn, const char *payload, int len, int rssi)
{
  Serial.print("received ");
  Serial.println(payload);
  // Send a reply in loop().
  sendAReply = true;
}

If I replace the sender (straight COM) with a sender that uses BLE plus dualMode COM, the replier does not receive any COM messages from the sender. I've also verified that the sender (BLE+dualMode COM) does not receive COM messages.

Sender - BLE+dualMode:

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

volatile bool sendAMessage = false;

void setup() {
  Serial.begin(9600);
  SimbleeCOM.mode = LONG_RANGE;
  SimbleeBLE.begin();
}


void loop() {
  // Send a message every second.
  delay(1000);
  sendAMessage = true;
}


void SimbleeBLE_onConnect() {
 
  // Once connected to BLE central, start dual mode.
  // SimbleeBLE_onDualModeStart() / SimbleeBLE_onDualModeStop() will be called
  // repeatedly. Only inside SimbleeBLE_onDualModeStart() is it safe to send
  // a COM message (my understanding).
 
  SimbleeBLE.dualModeBegin();
  Serial.println("dual mode started");
}


void SimbleeBLE_onDisconnect() {

  // When disconnected from BLE central, stop dual mode.
  SimbleeBLE.dualModeEnd();
  Serial.println("dual mode ended");
}


void SimbleeBLE_onDualModeStart() {
  // SimbleeBLE_onDualModeStart is called frequently. Send a message only
  // when sendAMessage is true (once a second, see loop()).
  if (sendAMessage) {
    sendAMessage = false;
    SimbleeCOM.send("ABC", 4);
    Serial.println("sent ABC");
  }
}


void SimbleeCOM_onReceive(unsigned int esn, const char *payload, int len, int rssi) {
  Serial.print("received ");
  Serial.println(payload);
}

As you can see, when using dualMode, SimbleeCOM.send() can be only in the SimbleeBLE_onDualModeStart() routine.

Anyone have any better luck? I will send this to RF Digital support.

The ideal for our project would be:

- A single BLE central (iOS app) connects to 3 Simblees and uses BLE to communicate with them.
- Periodically, one of the Simblees, while still connected to BLE central, sends low latency COM message to other two Simblees, also while still connected to BLE central.

Currently when periodic COM messaging is needed, Simblees are disconnected from BLE central, COM messaging occurs, then all 3 Simblees are reconnected to BLE central. Unfortunately the reconnection process can take a while so that the whole process (disconnect, COM messaging, reconnect) takes as long as 10-15 seconds, sometimes longer.

We choose Simblee on the bases that simultaneous BLE+COM messaging was supported. The how-to video posted by RFD_Nelson gives me hope that it actually might work.

Thanks for any insights.

Cheers,

Tim

Tim

  • RFduino Sr. Member
  • ****
  • Posts: 126
  • Karma: +2/-0
    • View Profile
Re: dualMode for BLE+COM
« Reply #1 on: July 19, 2017, 11:15:56 PM »
I have clarity on this, thanks for replies from RF Digital support. This supplements info at:

http://forum.rfduino.com/index.php?topic=1357.0

When Simblee is connected to a BLE central and is in dualMode, it gives 10 ms slices of time to COM. This is enough time to send a COM message in LOW_LATENCY mode (3 ms latency) and receive an immediate reply from a receiving Simblee. Therefore, dualMode works only for LOW_LATENCY COM.

The only configuration of Simblees that dualMode works for is where you have one Simblee acting as a gateway, and one or more as nodes. The gateway can be connected to a BLE central and, via dualMode, also do COM messaging with one or more nodes. The nodes must use straight COM; they cannot maintain BLE connection. AND, while a COM message sent from the gateway (in between calls to its SimbleeBLE_onDualModeStart() and SimbleeBLE_onDualModeStop() routines) is broadcast to all nearby Simblees with COM stack started, only a single node can reply to the gateway, and it must do so immediately so the reply message reaches the gateway before the end of the 10 ms COM slice in which the original message was sent from the gateway.

This limits the use cases for Simblee's dualMode, but I can imagine there are many where it is very useful.

Hope helpful ...

Tim