title: Streaming data from BLE SHIELD Arduino to iPhone
body: <p>I am using RedBear <a href="http://redbearlab.com/bleshield/" rel="nofollow">BLE Shield</a> to continuously stream data to iOS.</p>
  
  <p>I'm using chat iOS app provided in the <a href="https://github.com/RedBearLab/Release/tree/master/BLEShield" rel="nofollow">SDK</a> to debug the following arduino code:</p>
  
  <pre><code>#include &lt;Arduino.h&gt;
  #include &lt;SPI.h&gt;
  #include "ble.h"
  
  unsigned int reading = 0;
  
  void setup()
  {
    SPI.setDataMode(SPI_MODE0);
    SPI.setBitOrder(LSBFIRST);
    SPI.setClockDivider(SPI_CLOCK_DIV16);
    SPI.begin();
  
    ble_begin();
  
    Serial.begin(57600);
  }
  
  unsigned char buf[16] = {0};
  unsigned char len = 0;
  
  void loop()
  {
  
    ble_do_events();
  
    if(ble_connected()){
  
        reading = 10; //this is fake data for testing purposes.
        buf[0] = reading;
        reading = reading &lt;&lt; 8;
        reading |= 11; //again same fake data
        buf[1] = reading &amp; 0xFF;
        len = 2;
        Serial.print(reading); Serial.print(" -&gt; LSB:"); Serial.print(buf[1], HEX); Serial.print(" MSB:"); Serial.println(buf[0], HEX);
  
      len = 2;
      for (int i = 0; i &lt; len; i++)
        ble_write(buf[i]);
      ble_write(0x0D);
      len = 0;
  
      ble_do_events();
  
      delay(20);
    }
  }
  </code></pre>
  
  <p>I'm encountering the following problem: 
  the first time I try to connect to the BLE Shield it just executes the loop once and it gets stuck. then, if I disconnect and reconnect, data starts to stream as I would like to.</p>
  
  <p>Anyone has tried this?</p>