How to correctly set the date and time in a bluetooth low energy peripheral?

后端 未结 3 2126
[愿得一人]
[愿得一人] 2021-02-11 00:26

I am developing a sensor device and a corresponding iOS-app that shall communicate using Bluetooth low energy. The sensor device needs to maintain the current date and time in a

相关标签:
3条回答
  • 2021-02-11 00:46

    The Current Time Service is intended to be a provider of the current time; clients would use it to obtain the time. Hence, having a client write to it does not really make sense. If your device does not have a Real Time Clock then it cannot provide a time service. If your device needs the time and does not have an RTC then your device must become a client to another device which can provide it.

    0 讨论(0)
  • 2021-02-11 00:54

    I have implement this and it will work my side,

    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))
    
    //Current Time Write on tag
    
    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)
    }
    
    0 讨论(0)
  • 2021-02-11 00:56

    Start The time service in iOS Phone. Read the Time from Phone (exposed by service) into sensor. ( for this your iPHone acts as peripheral ) Sensor in this case acts as a Master. Get the data from iPhone and set it into sensor. I hope you can code for Sensor.

    0 讨论(0)
提交回复
热议问题