2016-02-29 93 views
3

我正在开发一个传感器设备和一个相应的iOS应用程序,它应该使用蓝牙低功耗进行通信。传感器设备需要在实时时钟中保持当前的日期和时间。现在,我很困惑,如果我想尽可能实现蓝牙标准服务,那么在传感器设备中设置时间和日期的正确方法是什么,因为官方文档是相互矛盾的:如何在蓝牙低能耗外设中正确设置日期和时间?

  • “当前时间服务”为ServiceViewer,它表示可以选择写入“当前时间”特征。这意味着GATT客户端(即智能手机)可以通过写入该特性来简单地设置传感器的时间。
  • detailed specifications关于该服务,但它说,写入该特征是被禁止的。

与详细规格(2011)相比,服务查看器中的信息更近(2014年),因此可以安全地认为详细规格尚未更新?

尽管广泛的在线研究,我无法找到某人在BT-LE传感器中设置当前日期和时间的任何示例。

任何线索最好的办法是什么?

+1

你将不得不编写一个应用程序来无论如何都要和设备交谈,所以使用哪种方法并不重要;您可以更新当前时间服务属性或定义您自己的属性。 – Paulw11

+0

据我所知,iOS本地支持当前时间特征服务器实现。因此,如果您的传感器设备中实施了当前的时间特征客户端,那么您将收到每分钟的时间更新(假设您的设备已绑定) –

+0

在当前时间服务规范v1.0中不允许写入日期时间特征。稍后的版本V1.1将写支持指定为可选。 – HarryQ

回答

1

开始iOS Phone中的时间服务。 将电话时间(通过服务暴露)读入传感器。 (为此,您的iPHone充当外设) 本例中的传感器充当主设备。 从iPhone获取数据并将其设置到传感器中。 我希望你可以编码传感器。

0

当前时间服务旨在成为当前时间的提供者;客户会用它来获得时间。因此,让客户写信给它并不合乎情理。如果您的设备没有实时时钟,则无法提供时间服务。如果您的设备需要时间并且没有RTC,那么您的设备必须成为可提供该设备的其他设备的客户端。

1

我有实现这个和它的工作我的身边,

let date = Date() 
let calendar = Calendar.current 
var comp = calendar.dateComponents([.day, .month, .year, .hour, .minute, .second, .weekday, .nanosecond], from: date) 
let milisecond = comp.nanosecond!/1000000 
let quiterValue = milisecond/256 
let year_mso = comp.year! & 0xFF 
let year_lso = (comp.year! >> 8) & 0xFF 
let ajjust_reason = 1 

let timeZone = calendar.component(.timeZone, from: date) 
let DSTZoon = Calendar.current.timeZone.isDaylightSavingTime() 

let Year_MSO_Unsinged = Int8(bitPattern: UInt8(year_mso)) 
let Year_LSO_Unsinged = Int8(bitPattern: UInt8(year_lso)) 
let MONTH_Unsinged = Int8(bitPattern: UInt8(comp.month!)) 
let DAY_Unsinged = Int8(bitPattern: UInt8(comp.day!)) 
let HOUR_Unsinged = Int8(bitPattern: UInt8(comp.hour!)) 
let MINUTE_Unsinged = Int8(bitPattern: UInt8(comp.minute!)) 
let SECOND_Unsinged = Int8(bitPattern: UInt8(comp.second!)) 
let WEEKDAY_Unsinged = Int8(bitPattern: UInt8(comp.weekday!)) 
let QUITERVALUE_Unsinged = Int8(bitPattern: UInt8(quiterValue)) 
let AJRSON_Unsinged = Int8(bitPattern: UInt8(ajjust_reason)) 

//当前时间写在标签

let currentTimeArray = [Year_MSO_BYTE, Year_LSO_BYTE, MONTH_BYTE, DAY_BYTE ,HOUR_BYTE ,MINUTE_BYTE ,SECOND_BYTE , WEEKDAY_BYTE , QUITERVALUE_BYTE , AJRSON_BYTE]; 
let currentTimeArray_data = NSData(bytes: currentTimeArray, length: currentTimeArray.length) 
if Device.Current_Time != nil { 
     deviceValue.peripheral.writeValue(currentTimeArray_data as Data, for: GrillRightDevice.Current_Time!, type: CBCharacteristicWriteType.withResponse) 

}