Giter Club home page Giter Club logo

cordova-plugin-rfduino's Introduction

RFduino Plugin for PhoneGap

This plugin enabled Bluetooth communication between a phone and an RFduino.

Supported Platforms

  • iOS
  • Android 4.3 or greater

Limitations

The can only connect to one RFduino at a time. Use the BLE plugin to connect to multiple devices at the same time.

rfduino.write() does not check if data exceeds the max size.

Installing

Install with Cordova cli

$ cordova plugin add cordova-plugin-rfduino

API

Methods

discover

Discover RFduino devices

rfduino.discover(seconds, success, failure);

Description

Function discover discovers the local RFduino devices. The success callback is called each time a peripheral is discovered.

{
    "name": "RFduino",
    "uuid": "BD922605-1B07-4D55-8D09-B66653E51BBA",
    "advertising": "echo",
    "rssi": -79
}

Parameters

  • seconds: Number of seconds to run discovery
  • success: Success callback function that is invoked with a list of bonded devices.
  • failure: Error callback function, invoked when error occurs. [optional]

Quick Example

rfduino.discover(3, function(device) {
    console.log(JSON.stringify(device));
}, failure);

list

Lists known devices

rfduino.list(success, failure);

Description

Function list lists the known RFduino devices. The success callback is called with a list of objects.

This will return an empty list unless discover have previously run. You should prefer discover to list.

[{
    "name": "RFduino",
    "uuid": "AEC00232-2F92-4033-8E80-FD4C2533769C",
    "advertising": "echo",
    "rssi": -79
}, {
    "name": "RFduino",
    "uuid": "AEC00232-2F92-4033-8E80-FD4C2533769C",
    "advertising": "temp",
    "rssi": -55
}]

Parameters

  • success: Success callback function that is invoked with a list of bonded devices.
  • failure: Error callback function, invoked when error occurs. [optional]

Quick Example

rfduino.list(function(devices) {
    devices.forEach(function(device) {
        console.log(device.uuid);
    })
}, failure);

connect

Connect to a RFduino device.

rfduino.connect(uuid, connectSuccess, connectFailure);

Description

Function connect connects to a RFduino device. The callback is long running. Success will be called when the connection is successful. Failure is called if the connection fails, or later if the connection disconnects. An error message is passed to the failure callback.

Parameters

  • uuid: UUID of the remote device
  • connectSuccess: Success callback function that is invoked when the connection is successful.
  • connectFailure: Error callback function, invoked when error occurs or the connection disconnects.

disconnect

Disconnect.

rfduino.disconnect([success], [failure]);

Description

Function disconnect disconnects the current connection.

Parameters

  • success: Success callback function that is invoked when the connection is successful. [optional]
  • failure: Error callback function, invoked when error occurs. [optional]

onData

Adds a callback for processing data from the RFduino.

rfduino.onData(success, failure);

Description

Function onData registers a function that is called whenever phone receives data from the RFduino.

Raw data is passed from ObjectiveC the callback as an ArrayBuffer and must be processed.

Parameters

  • success: Success callback function that is invoked when the connection is successful. [optional]
  • failure: Error callback function, invoked when error occurs. [optional]

write

Writes data to the currently connected device

rfduino.write(data, success, failure);

Description

Function write writes data to the connected device. Data must be an ArrayBuffer for this version.

Parameters

  • data: ArrayBuffer to write to the RFduino
  • success: Success callback function that is invoked when the connection is successful. [optional]
  • failure: Error callback function, invoked when error occurs. [optional]

Quick Example

var data = new ArrayBuffer(3);
data[0] = 0xFF;
data[1] = 0x00;
data[2] = 0x17;
rfduino.write(data.buffer, success, failure);

isConnected

Reports the connection status.

rfduino.isConnected(success, failure);

Description

Function isConnected calls the success callback when connected to a peer and the failure callback when not connected.

Parameters

  • success: Success callback function that is invoked with a boolean for connected status.
  • failure: Error callback function, invoked when error occurs. [optional]

Quick Example

rfduino.isConnected(
    function() {
        console.log("RFduino is connected");
    },
    function() {
        console.log("RFduino is *not* connected");
    }
);

isEnabled

Reports if bluetooth is enabled.

rfduino.isEnabled(success, failure);

Description

Function isEnabled calls the success callback when Bluetooth is enabled and the failure callback when Bluetooth is not enabled.

Parameters

  • success: Success callback function that is invoked with a boolean for connected status.
  • failure: Error callback function, invoked when error occurs. [optional]

Quick Example

rfduino.isEnabled(
    function() {
        console.log("Bluetooth is enabled");
    },
    function() {
        console.log("Bluetooth is *not* enabled");
    }
);

License

Apache 2.0

Feedback

Try the code. If you find an problem or missing feature, file an issue or create a pull request.

cordova-plugin-rfduino's People

Contributors

don avatar sarajo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-rfduino's Issues

write function which supports byte/typed-arrays

Hey Don, thanks for this plugin!
The write function currently just supports strings, but in your code you have a "todo comment" which mentions that you already thought about adding support for bytes. do you still plan to implement this? im waiting for this feature :)
thanks!

<NSInvalidArgumentException> -[NSNull isEqualToString:]

Intermittent errors on iOS

2014-03-25 12:44:02.851 rfduinoBracelet[232:60b] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSInvalidArgumentException> -[NSNull isEqualToString:]: unrecognized selector sent to instance 0x39885a70 13:02:46.318 rfduinoBracelet[300:60b] write

maybe in MEGRFduino.m findPeripheralByUUID

success callback called too early

Hi Don,

thank you again for this plugin!
I ran in to some timing issues the last days, not sure though, if this is a bug or my fault.
Here is the scenario: I am calling the rfduino.connect function while the rfduino is offline, so that once it goes online I connect to it immediatey. When doing so, I figured that I can not send or receive from the rfduino immediately, although the success callback was called. Only after short while (havent figured out exactly but around 1500 ms) then I can send using rfuino.write and receive data.
I solved this problem now in javascript by using a setTimeout, but maybe you have the time to look into this.

Thank you!

Tobi

IOS connect fail callback error

I'm using cordova to install your latest rfduino plugin (0.1.2 I believe it is)for IOS. When the rfduino.connect funtion is called it always fires a fail callback as well as a success callback. So when I connect to a rfduino it connects but also fires the fail callback. I've used the plugin on android with phonegap build and have not had the problem. Seems to be only with IOS (7.12 havent tried other versions) using cordova. Let me know if I'm doing something wrong or if you need more info. thanks.

Not really an issue more a question

Hi Don,

Can't wait to use your plugin, but i do have a question on the write process. I was looking at your example on the write and i see it is using an array buffer, but i can not quite figure out exactly what to give to set one of the io pins. I understand i "discover" the rfduino, then connect to it with the UUID. On the Write, i am guessing i have to say in one of the buffer values the pin(like gpio1) i want to use and then in another either 0 or 1 to turn on or off. is that correct? is there anyway in an example you can show exactly how to both read from a io pin and what values to use to set an io pin to on or off.

thanks

Scanning 2x crashes app

Scanning 2x crashes app. See don/cordova-plugin-ble-central#5

2014-09-22 18:04:12.723 TekCreate[1044:287156] stopScanTimer
2014-09-22 18:04:14.100 TekCreate[1044:287156] stopScanTimer
2014-09-22 18:04:14.108 TekCreate[1044:287156] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: nil argument'
*** First throw call stack:
(0x185e3a084 0x1964180e4 0x185e39fc4 0x186c7ae50 0x186c7ad24 0x100080fa0 0x100081100 0x10008a138 0x186d07818 0x185df2210 0x185df1ec0 0x185def90c 0x185d1d664 0x18ee5f5a4 0x18a622984 0x10008665c 0x196a86a08)
libc++abi.dylib: terminating with uncaught exception of type NSException

NSInternalInconsistencyException characteristic != nil on iOS

Hi Don,
I am getting an issue in iOS when I try to connect to rfduino. I don't know anything about iOS at this point (just starting). The exception is below, does this mean anything to you? I am using an ipod Touch with latest iOS 7.1.

I appreciate any help you can offer.

2014-03-29 00:52:31.689 AppName[197:60b] didConnectPeripheral

2014-03-29 00:52:31.694 AppName[197:60b] write

2014-03-29 00:52:31.697 AppName[197:60b] *** Assertion failure in -[CBPeripheral writeValue:forCharacteristic:type:], /SourceCache/CoreBluetooth/CoreBluetooth-109/CBPeripheral.m:348

2014-03-29 00:52:31.700 AppName[197:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: characteristic != nil'

*** First throw call stack:

(0x2d5b4fd3 0x37cfdccf 0x2d5b4ead 0x2df61d5b 0x2d2da645 0x7d031 0x75ca9 0x75547 0x764b7 0x2df9dc73 0x2d58025b 0x2d57f72b 0x2d57df1f 0x2d4e8f4f 0x2d4e8d33 0x3240a663 0x2fe3416d 0x7b5bf 0x7b580)

libc++abi.dylib: terminating with uncaught exception of type NSException

callback called multiple times on Android

#2 (comment)
"However, the onConnect message has a very bizzare behavior. First time I connect to an rfduino, it is called once (perfect). If I disconnect and connect again, the onConnect is called twice, third time, it is called 3 times, etc."

failure callbacks on iOS 8.2 although everything appears to work fine.

Hi Don, I'm am getting the following failure callbacks:

with a 10 second discovery -- I get 2 failure callbacks -- although it does discover all the devices the way it is supposed to.

While connecting to device -- I get 2 failure callbacks -- although it will connect to the device. My code retries connecting 1 time if the failure call back is called and then it stops trying to connect. What is happening is it retries 1 time, failure callback is called both times... and then it ends up connecting within 1 second or less.

onData failure callback is called 1 time -- although it appears to receive data from the rfduino without a problem.

Summary: The above results happened 100% of the time with over 20 tries. Everything seems to work fine, however, failure callbacks are being called.

I am using phonegap build 3.7 with an iphone 5 iOS 8.2.

I have tried the same code on an android device and no failure callbacks are called.

Android discover problems

Hi,

i have problems discovering rfduinos on android , soemtimes it works, sometimes not. (about every second time i hit the button) once found & connected everything works fine

no idea what could cause the problem. logcat gives me this.

W/PluginManager(19641): THREAD WARNING: exec() call to RFduino.discover blocked the main thread for 17ms. Plugin should use CordovaInterface.getThreadPool().

cordova 5.1.1
android 4.0.2
moto g2

Thanks for the great Plugin!

recommended settings for discovering multiple rfduinos

Hi Don, what settings do you recommend to discover multiple rfduinos? I'm trying to discover 7 of them, I have the advertising interval set to 500ms and the discovery time set to 7 seconds. My android app discovers 4 of them every time and the other 3 are hit and miss (sometimes it finds them in the 7 seconds, sometimes it doesn't) is this a limitation with the plugin or do you have any ideas on how to discover all 7 every time?

Others BLE Devices

Hi !

I would like to know if it's possible to edit this plugins to detect all BLE device not only rfduino ?

Thanks

Sending RFDuino message after connect fails

Hi Don,
I am trying to send an rfduino message right after I connect. So in your sample app it would be in the showDetailPage. I am using cordova on iOS. The message is not sent and I get an error in xcode that I am attaching below. However, when I try to send the same message after a user action, such as, user changes value in input field and I send that value over to rfduino, that works fine.

Error:
2014-04-07 13:29:15.530 AppName[361:60b] *** Assertion failure in -[CBPeripheral writeValue:forCharacteristic:type:], /SourceCache/CoreBluetooth/CoreBluetooth-109/CBPeripheral.m:348
2014-04-07 13:29:15.532 AppName[361:60b] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: Invalid parameter not satisfying: characteristic != nil

Here is that code snippet:

showDetailPage: function() {

    setTimeout(function(){
               app.sendRFDuinoConfig();
               },500); //without timeout seems that rfduino cordova lib fails on iOS

    mainPage.hidden = true;
    detailPage.hidden = false;

}

//here is my sendRFDuinoConfig
sendRFDuinoConfig: function(){
    rfduino.write("AI:" + advInterval); //send the value
    rfDuinoConfigSent = true; //indicate that it was sent already
}

Can you help me with this issue please?
Thank you

failure callbacks on iOS 8.2 although everything appears to work fine.

Hi Don, I'm am getting the following failure callbacks:

with a 10 second discovery -- I get 2 failure callbacks -- although it does discover all the devices the way it is supposed to.

While connecting to device -- I get 2 failure callbacks -- although it will connect to the device. My code retries connecting 1 time if the failure call back is called and then it stops trying to connect. What is happening is it retries 1 time, failure callback is called both times... and then it ends up connecting within 1 second or less.

onData failure callback is called 1 time -- although it appears to receive data from the rfduino without a problem.

Summary: The above results happened 100% of the time with over 20 tries. Everything seems to work fine, however, failure callbacks are being called.

I am using phonegap build 3.7 with an iphone 5 iOS 8.2.

I have tried the same code on an android device and no failure callbacks are called.

RFDuinno LedButton sample : no data received

Hello Don,

I have tested the temperature sample and it works perfectly !
How cool is your plugin for people like me that want to test but don't know anything about ios programming... :)

I am trying to test now the ledbutton sample from RFDuino.

Normally the duino does a "RFduinoBLE.send(1);" and then I should get data in the ondata function in my app.js.
But I don't get anything. I launch the application in Xcode to see the console.log(data) but nothing appears.

Do I miss anything ?

Thanks in advance for the help.

Regards,
@jeangui

Android 5.0

Do you know if there are any problems with Android 5.0?

I'm attempting to debug to see if there is a problem. Anywhere you think I should be looking?

Android app gets MAC address instead of UUID

Hi Don,

When I use your button example on an android it appears that device.uuid is a mac address (it is in XX:XX:XX:XX:XX:XX format) On an iPhone device.uuid is the actual UUID in (215d0f7d-f01d-46bd-9191-e847d288e3f5 format)

I'm trying to use a custom UUID (as in the RFduino customUUID example sketch) But the android app doesn't seem to use it. It seems to find the MAC address instead and the custom UUID never shows up when you discover. Can you tell me how I would use a custom UUID with Android?

get "disconnected" error when trying to connect

Hi, after about 10 - 13 successful connections I continuously get the error message "disconnected" when trying to run rfduino.connect(uuid, function1, error). Turning bluetooth off and then on again on my phone tends solve the problem for about 10 -13 more times. Any suggestions on how to fix this?

rfduino.disconnect crashes the application

I can't seem to execute the "disconnect" method without the application crashing. I have only tried with iOS. I get the following errors in Xcode:

didDisconnectPeripheral
2014-06-21 18:41:18.104 LR-Test[3619:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: nil argument'
*** First throw call stack:
(0x2d55df0b 0x37cf4ce7 0x2d55de4d 0x2ded73db 0x2ded72c7 0x7ed15 0x7ee3d 0x890c3 0x2d27fdc9 0x2d280083 0x2d28866f 0x381ddd53 0x381ddd3f 0x381e06c3 0x2d528681 0x2d526f4d 0x2d491769 0x2d49154b 0x323fe6d3 0x2fdf0891 0x83e9b 0x381f2ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.