Bluno General Arduino

Sending AT commands through the DFB2 Characteristic

userHead shawt 2018-03-30 00:46:53 878 Views0 Replies
I have learned that dfb2 is the characteristic used to send AT commands, but I am not having any success sending AT commands from my Swift program. Would you please post some detailed instructions about the format that the write command should be in? I have tried several variations of the code below. The parameter variable is an array of Uint8 bytes that represent the ASCII string: AT+NAME=TSBOT with cr and lf bytes tacked on to the end.

It is not at all clear from the documentation if I need to trigger AT mode with +++ before sending commands, if I need to prefix commands sent with AT+ or if I need to finish the command with a crlf. Also, it is not clear what format I should be sending the data in.
Code: Select all
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
        for i in 0..<service.characteristics!.count {
            print(service.characteristics![i])
            if (service.characteristics![i].uuid == CBUUID.init(string: "DFB2")) {
                
                var parameter: [UInt8] = [0x41,0x54,0x2b,0x4e,0x41,0x4d,0x45,0x3d,0x54,0x53,0x42,0x4f,0x54,0x0a,0x0D,0x0A]
            
                let data = Data(bytes: &parameter, count: MemoryLayout<UInt8>.size)
                
                peripheral.writeValue(data as Data, for: service.characteristics![i], type: CBCharacteristicWriteType.withResponse)

            }
            
        }
    }