Bluetooth LE and LightBlue Bean.

87 views
Skip to first unread message

Massimo Rigoni Savioli

unread,
Aug 31, 2016, 6:01:13 AM8/31/16
to DroidScript
Hello,
I have done many tests with the plugin for new Bluetooth LE and LightBlue Bean.
I wrote the following code in the Bean:to detect the connection:

void setup() {
  // Configure Bean to wake up when a client connects
  Bean.enableWakeOnConnect(true);
}

// Loop runs once at program start.
// When a client connects, Bean wakes up and runs loop again.
// Loop continues to run as long as a client is connected.

void loop() {
  // Check if client has disconnected
  bool connected = Bean.getConnectionState();

  if (connected) {
    // Client connected: set LED to green
    Bean.setLed(0, 255, 0);

  } else {
    // Client disconnected: turn off LED
    Bean.setLed(0, 0, 0);

    // This sketch runs only when a client is connected.
    // This might be useful for interactive installations, where you don't want
    // Bean to spend any power unless someone is actively connected.

    // Sleep for a long time to conserve power.
    // 0xFFFFFFFF = 4,294,967,295 milliseconds = 49 days
    Bean.sleep(0xFFFFFFFF);
  }
}
When I tried it with Droidscript the Bean worked and the Led turned on.

What I could not get is to receive data.
I wrote the following code in the Bean to transmit some data to my app but it didn't read anything.

void setup() {
  Serial.begin(57600);
}
void loop() {
  Serial.print("Hello Word");
  Bean.sleep(750);
}

Do you have any suggestions?
Best Regards 

Dave Smart

unread,
Sep 2, 2016, 7:59:52 AM9/2/16
to DroidScript
Hi Massimo,

I just looked at the Bean specs.... they have invented their own flavor of Serial emulation over BLE, rather than the Nordic nRF51X style which DroidScript expects, so you are going to need to choose one of two ways to solve this problem:-

1. Don't use the serial communications, but create a BLE service and characteristic to transmit data from the Bean instead.

2. Create a DroidScript plugin that wraps their Android API and then you can use their serial emulation.

Regards
David
Reply all
Reply to author
Forward
0 new messages