<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How can I send data to peripheral from central when my nRF52832 is central then iPhone is peripheral</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/50398/how-can-i-send-data-to-peripheral-from-central-when-my-nrf52832-is-central-then-iphone-is-peripheral</link><description>Hi everyone 
 I setting my nRF52832 is central and iPhone(iOS 12.3.2) is peripheral and using &amp;quot;ble_app_uart_c(SDK15.3.0 s132 v6.1.1)&amp;quot; sample program. I print the debug message from central, can see the message &amp;quot;&amp;lt;info&amp;gt; app: Connected to device with Nordic</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 01 Aug 2019 06:24:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/50398/how-can-i-send-data-to-peripheral-from-central-when-my-nrf52832-is-central-then-iphone-is-peripheral" /><item><title>RE: How can I send data to peripheral from central when my nRF52832 is central then iPhone is peripheral</title><link>https://devzone.nordicsemi.com/thread/201736?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 06:24:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa41ae64-9336-4dc5-9abb-7fee6da67cab</guid><dc:creator>Jacky Fu</dc:creator><description>&lt;p&gt;Hi awneil&lt;/p&gt;
&lt;p&gt;I am trying to debug from iPhone&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I send data to peripheral from central when my nRF52832 is central then iPhone is peripheral</title><link>https://devzone.nordicsemi.com/thread/201439?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2019 08:24:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4c3ad84-7da9-425c-a034-00d28b68e35b</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;So what &lt;strong&gt;debugging&lt;/strong&gt; have you done on the iPhone end to see what&amp;#39;s happening?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I send data to peripheral from central when my nRF52832 is central then iPhone is peripheral</title><link>https://devzone.nordicsemi.com/thread/201388?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2019 04:12:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:93bb501d-6bde-4335-8da4-dffdbc9c2484</guid><dc:creator>Jacky Fu</dc:creator><description>&lt;p&gt;Hi awneil&lt;/p&gt;
&lt;p&gt;iPhone code for NUS:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;extension BluetoothManager: CBPeripheralManagerDelegate{
    
    func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
        switch peripheral.state {
        case .unknown:
            print(&amp;quot;unknown&amp;quot;)
        case .resetting:
            print(&amp;quot;resetting&amp;quot;)
        case .unsupported:
            print(&amp;quot;unsupported&amp;quot;)
        case .unauthorized:
            print(&amp;quot;unauthorized&amp;quot;)
        case .poweredOff:
            print(&amp;quot;poweredOff&amp;quot;)
        case .poweredOn:
            print(&amp;quot;poweredOn&amp;quot;)
            startAdvertisting()
        }
    }
    
    func startAdvertisting(){
        if let peripheralManager = self.peripheralManager{
            peripheralManager.stopAdvertising()
            peripheralManager.removeAllServices()
            if peripheralManager.state == .poweredOn{
                setupServiceAndCharacteristics()
            }
        }
    }
    
    func stopAdvertising(){
        self.peripheralManager?.stopAdvertising()
    }
    
    func writeDataToCentral(){
        let data = &amp;quot;helloWorld&amp;quot;.data(using: .utf8)
        self.peripheralManager?.updateValue(data!, for: characteristic!, onSubscribedCentrals: nil)
    }
    
    

    func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveRead request: CBATTRequest) {
        request.value = ?elloWorld??data(using: .utf8)
        peripheral.respond(to: request, withResult: .success)
        
        if let delegate = delegate{
            delegate.readCharacteristic()
        }
    }
    
    private func setupServiceAndCharacteristics() {
        let serviceID = CBUUID(string: Service_UUID)
        let service = CBMutableService(type: serviceID, primary: true)
        let characteristicID = CBUUID(string: Characteristic_UUID)
        let characteristicID2 = CBUUID(string: Characteristic_UUID2)
        let characteristic = CBMutableCharacteristic(type: characteristicID, properties: [.read, .write, .notify], value: nil, permissions: [.readable, .writeable])
        let characteristic2 = CBMutableCharacteristic(type: characteristicID2, properties: [.read, .write, .notify], value: nil, permissions: [.readable, .writeable, .readEncryptionRequired, .writeEncryptionRequired])
        service.characteristics = [characteristic, characteristic2]
        self.peripheralManager?.add(service)
    }
    
    func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) {
        for request in requests{
            let text = String.init(data: request.value!, encoding: String.Encoding.utf8)
            if let text = text, let delegate = self.delegate{
                UserDefaults.standard.set(text, forKey: &amp;quot;text&amp;quot;)
                delegate.receiveCentralData(text: text)
            }
        }

    }
    
    func peripheralManager(_ peripheral: CBPeripheralManager, didAdd service: CBService, error: Error?) {
        if let err = error{
            print(&amp;quot;err = \(err)&amp;quot;)
            return
        }
        print(&amp;quot;add service success&amp;quot;)
        self.peripheralManager?.startAdvertising([CBAdvertisementDataServiceUUIDsKey : [CBUUID.init(string: Service_UUID)], CBAdvertisementDataLocalNameKey: &amp;quot;55688&amp;quot;])
    }
    
    func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?) {
        if let err = error{
            print(&amp;quot;err = \(err)&amp;quot;)
            return
        }
    }
}&lt;/pre&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Service_UUID = 6E400001-B5A3-F393-E0A9-E50E24DCCA9E&lt;/p&gt;
&lt;p&gt;Create two Characteristics RX(Characteristic_UUID) and TX(Characteristic_UUID2), have set up &amp;quot;read&amp;quot;, &amp;quot;write&amp;quot;, &amp;quot;notify&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Characteristic_UUID =&amp;nbsp;&amp;nbsp;6E400002-B5A3-F393-E0A9-E50E24DCCA9E&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Characteristic_UUID2 =&amp;nbsp;&amp;nbsp;6E400003-B5A3-F393-E0A9-E50E24DCCA9E&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I send data to peripheral from central when my nRF52832 is central then iPhone is peripheral</title><link>https://devzone.nordicsemi.com/thread/201181?ContentTypeID=1</link><pubDate>Tue, 30 Jul 2019 09:30:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9274272c-7724-4614-a32f-5db9afd55a23</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;So what code have you got running on the iPhone to implement NUS on the phone?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>