Latest 0.2.5
Homepage https://github.com/helinyu/YDBluetoothWebBridge
License MIT
Platforms ios 7.0, requires ARC
Dependencies Masonry, BabyBluetooth, WebViewJavascriptBridge, SVProgressHUD, NJKWebViewProgress, YYModel, MJRefresh, Reachability, HardwareDatasStorage
Authors

a framework for develop bluetooth connect hardware like earphone and display with html

this framework depend on some third part code ,as follow:

   s.dependency 'Masonry', '~> 1.0.2'
    s.dependency 'BabyBluetooth', '~> 0.7.0'
    s.dependency 'WebViewJavascriptBridge', '~> 6.0.2'
    s.dependency 'SVProgressHUD', '~> 2.1.2'
    s.dependency 'NJKWebViewProgress', '~> 0.2.3'
    s.dependency 'YYModel', '~> 1.0.4'
    s.dependency 'MJRefresh', '~> 3.1.12'
    s.dependency 'Reachability', '~> 3.2'
    s.dependency 'HardwareDatasStorage', '~> 0.0.1'

YDOpenHardware(HardwareDatasStorage)

用于悦动圈跑步开放平台的简单demo
问题咨询: qq:295235985 邮箱:[email protected]

第三方最终提供给我们一个framework,模拟器和真机通用的
YDOpenHardwarePod

store the datas from the bluetooth & you can selected the datas from the storage which is store by the sqite base on the fmdb framework;
like: heartrate / pedometer /intellegenscale /sleep and so on which we should need to expand
you can invoke these methods from the html by the js program language

function setupWebViewJavascriptBridge(callback) {
if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
window.WVJBCallbacks = [callback];
var WVJBIframe = document.createElement('iframe');
WVJBIframe.style.display = 'none';
WVJBIframe.src = 'https://__bridge_loaded__';
document.documentElement.appendChild(WVJBIframe);
setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
}

2、 invoke the last method to do business neccesary
like that:

setupWebViewJavascriptBridge(function(bridge) {
…………………………
to do the business necessary
}

3、sj invoke the oc method

var callbackButton = document.getElementById('scanBtn')
callbackButton.innerHTML = 'scanBtn'
callbackButton.onclick = function(e) {
e.preventDefault();
log('JS calling handler "scan peripheral"')
// window.location.href='./peripheralList.html';
bridge.callHandler('onScanS3Click', 'S3', function(response) {
log('JS got response', response)
});
};

4、oc invoke the js method , so that we must register the method

bridge.registerHandler('deliverCharacteristic', function(data, responseCallback) {
log('data'+data+':'+data.uuid+data.value.value0 +':'+data.value.value1+':'+data.value.value2+':'+data.value.value3+'.');

var stepLabel = document.getElementById('stepLabel');
// stepLabel.innerHTML =
var calorieLabel = document.getElementById('calorieLabel');
// calorieLabel.innerHTMLp =
var distanceLabel = document.getElementById('distanceLabel');
// distanceLabel.innerHTML =

responseCallback(responseData);
});

5、data deliver protocol:
we must deliver the data by the json format , you can deliver json object or data string and so on which can deliver to the oc
so we recomend the format si key:value which is simpler ,it will more eaier to use.
like the data of oc that :

@{
@"uuid":c.UUID.UUIDString,
@"value":@{
@"value0":value0,
@"value1":value1,
@"value2":value2,
@"value3":value3
}
};

more detail you can see the S3.html

storage & cache datas

invoke this methods in js as follow:

体称
insertIntelligentScale
selectNewIntelligentScaleByInfo
selectIntelligentScaleByInfo
selectIntelligentScaleInPageByInfo

心率
insertHeartRate
selectNewHeartRateByInfo
selectHeartRateByInfo
selectHeartRateInPageByInfo

步数
insertPedometer
selectNewPedometerByInfo
selectPedometerByInfo
selectPedometerInPageByInfo

睡眠
insertSleep
selectNewSleepByInfo
selectSleepByInfo
selectSleepInPageByInfo

参数的传入:parmas
格式:dictionary || (key/value) || jsonObject

下面是对应的数据模型关键系

@interface YDOpenHardwareSleep : NSObject

@property (nonatomic, strong) NSNumber *ohsId;//对应数据库字段:ohs_id
@property (nonatomic, strong) NSString *deviceId;//对应数据库字段:device_id
@property (nonatomic, strong) NSNumber *sleepSec;//对应数据库字段:sleep_sec
@property (nonatomic, strong) NSNumber *sleepSection;//对应数据库字段:sleep_section
@property (nonatomic, strong) NSDate *startTime;//对应数据库字段:start_time
@property (nonatomic, strong) NSDate *endTime;//对应数据库字段:end_time
@property (nonatomic, strong) NSNumber *userId;//对应数据库字段:user_id
@property (nonatomic, strong) NSString *extra;//对应数据库字段:extra
@property (nonatomic, strong) NSNumber *serverId;//对应数据库字段:server_id
@property (nonatomic, strong) NSNumber *status;//对应数据库字段:status
@end

@interface YDOpenHardwareUser : NSObject
@property (nonatomic, copy) NSString *province; //所在省
@property (nonatomic, copy) NSString *city; //城市
@property (nonatomic, strong) NSNumber *userID; //用户id
@property (nonatomic, strong) NSNumber *rank; //用户等级
@property (nonatomic, strong) NSNumber *sex; //0为男,1为女
@property (nonatomic, copy) NSString *nick; //用户昵称
@property (nonatomic, copy) NSString *headImageUrl; //头像url
@property (nonatomic, copy) NSString *loveSports; //用户喜欢的运动 逗号隔开
@property (nonatomic, copy) NSString *phone; //用户手机
@property (nonatomic, copy) NSString *signature; //用户签名
@property (nonatomic, strong) NSDate *birth; //生日
@property (nonatomic, strong) NSNumber *height; //身高cm
@property (nonatomic, strong) NSNumber *weight; //重量g
@end

@interface YDOpenHardwarePedometer : NSObject
@property (nonatomic, strong) NSNumber *ohpId;//对应数据库字段:ohp_id
@property (nonatomic, strong) NSString *deviceId;//对应数据库字段:device_id
@property (nonatomic, strong) NSNumber *numberOfStep;//对应数据库字段:number_of_step
@property (nonatomic, strong) NSNumber *distance;//对应数据库字段:distance
@property (nonatomic, strong) NSNumber *calorie;//对应数据库字段:calorie
@property (nonatomic, strong) NSDate *startTime;//对应数据库字段:start_time
@property (nonatomic, strong) NSDate *endTime;//对应数据库字段:end_time
@property (nonatomic, strong) NSNumber *userId;//对应数据库字段:user_id
@property (nonatomic, strong) NSString *extra;//对应数据库字段:extra
@property (nonatomic, strong) NSNumber *serverId;//对应数据库字段:server_id
@property (nonatomic, strong) NSNumber *status;//对应数据库字段:status
@end

@interface YDOpenHardwareIntelligentScale : NSObject
@property (nonatomic, strong) NSNumber *ohiId;//对应数据库字段:ohi_id
@property (nonatomic, strong) NSString *deviceId;//对应数据库字段:device_id
@property (nonatomic, strong) NSDate *timeSec;//对应数据库字段:time_sec
@property (nonatomic, strong) NSNumber *weightG;//对应数据库字段:weight_g
@property (nonatomic, strong) NSNumber *heightCm;//对应数据库字段:height_cm
@property (nonatomic, strong) NSNumber *bodyFatPer;//对应数据库字段:body_fat_per
@property (nonatomic, strong) NSNumber *bodyMusclePer;//对应数据库字段:body_muscle_per
@property (nonatomic, strong) NSNumber *bodyMassIndex;//对应数据库字段:body_mass_index
@property (nonatomic, strong) NSNumber *basalMetabolismRate;//对应数据库字段:basal_metabolism_rate
@property (nonatomic, strong) NSNumber *bodyWaterPercentage;//对应数据库字段:body_water_percentage
@property (nonatomic, strong) NSNumber *userId;//对应数据库字段:user_id
@property (nonatomic, strong) NSString *extra;//对应数据库字段:extra
@property (nonatomic, strong) NSNumber *serverId;//对应数据库字段:server_id
@property (nonatomic, strong) NSNumber *status;//对应数据库字段:status
@end

@interface YDOpenHardwareHeartRate : NSObject
@property (nonatomic, strong) NSNumber *ohhId;//对应数据库字段:ohh_id
@property (nonatomic, strong) NSString *deviceId;//对应数据库字段:device_id
@property (nonatomic, strong) NSNumber *heartRate;//对应数据库字段:heart_rate
@property (nonatomic, strong) NSDate *startTime;//对应数据库字段:start_time
@property (nonatomic, strong) NSDate *endTime;//对应数据库字段:end_time
@property (nonatomic, strong) NSNumber *userId;//对应数据库字段:user_id
@property (nonatomic, strong) NSString *extra;//对应数据库字段:extra
@property (nonatomic, strong) NSNumber *serverId;//对应数据库字段:server_id
@property (nonatomic, strong) NSNumber *status;//对应数据库字段:status
@end

注意:device_id & user_id 默认不用传入,在native 这边默认是当前的用户设备
其他字段按需传入

`

蓝牙操作过程中的几个必要的方法

var callbackButton = document.getElementById('scanBtn')
callbackButton.innerHTML = 'scanBtn'
callbackButton.onclick = function(e) {
e.preventDefault();
log('JS calling handler "scan peripheral"')
// window.location.href='./peripheralList.html';
var scanParams = {'prefixField':'S3','YDBlueToothFilterType':3};
bridge.callHandler('onScanClick', scanParams, function(response) {
log('JS got response', response)
});
};
method: onScanClick
params: scanParams (key/value)

第一个参数是对应的过滤的类型:

YDBlueToothFilterTypeNone = 0,
YDBlueToothFilterTypeMatch,  // match to filter and find the specify device
YDBlueToothFilterTypeContain,    // contain the keyword to filter and find the specify device
YDBlueToothFilterTypePrefix,     // key word by the prefix
YDBlueToothFilterTypeSuffix,     // key word by the suffix
YDBlueToothFilterTypePrefixAndSuffix, // key word by the prefix & suffix
YDBlueToothFilterTypePrefixAndContain, // key word by the prefix & contain
YDBlueToothFilterTypeSuffixAndContrain, // key word by the suffix & contain
YDBlueToothFilterTypePrefixAndContrainAndSuffix, //key word by the prefix & contrain * suffix

第二个参数是对应的是过滤方式的字段:

@property (nonatomic, copy) NSString *matchField; // 匹配
@property (nonatomic, copy) NSString *prefixField; // 前缀
@property (nonatomic, copy) NSString *suffixField; // 后缀
@property (nonatomic, copy) NSString *containField; //包含

写数据

format : var datas = {"hexString":"0x06","length":1};

writeDatas.onclick = function(e) {
e.preventDefault();
// test value
var datas = {"hexString":"0x06","length":1};
bridge.callHandler('writeDatas',datas,function(response) {
log('respone +',response);
});
};

……

Latest podspec

{
    "name": "YDBluetoothWebBridge",
    "version": "0.2.5",
    "summary": "u8fdeu63a5u84ddu7259u5e76u4e14u83b7u53d6u6570u636eu5c55u793au5728webu4e0au901au8fc7htmlu9875u9762uff0cu5ba2u6237u7aefu53eau9700u8981u770bu6cd5htmlu9875u9762",
    "platforms": {
        "ios": "7.0"
    },
    "homepage": "https://github.com/helinyu/YDBluetoothWebBridge",
    "license": "MIT",
    "authors": {
        "felix": "[email protected]"
    },
    "source": {
        "git": "https://github.com/helinyu/YDBluetoothWebBridge.git",
        "tag": "0.2.5"
    },
    "requires_arc": true,
    "description": "YDBluetoothWebBridge is for easier to use display datas from bluetooth on html web page",
    "vendored_frameworks": "YDBluetoothWebBridge.framework",
    "dependencies": {
        "Masonry": [
            "~> 1.0.2"
        ],
        "BabyBluetooth": [
            "~> 0.7.0"
        ],
        "WebViewJavascriptBridge": [
            "~> 6.0.2"
        ],
        "SVProgressHUD": [
            "~> 2.1.2"
        ],
        "NJKWebViewProgress": [
            "~> 0.2.3"
        ],
        "YYModel": [
            "~> 1.0.4"
        ],
        "MJRefresh": [
            "~> 3.1.12"
        ],
        "Reachability": [
            "~> 3.2"
        ],
        "HardwareDatasStorage": [
            "~> 0.0.1"
        ]
    }
}

Pin It on Pinterest

Share This