将数据从Arduino传输到iPhone

将数据从Arduino传输到iPhone,iphone,ios,arduino,bluetooth-lowenergy,Iphone,Ios,Arduino,Bluetooth Lowenergy,我正在使用RedBear不断地将数据流传输到iOS 我正在使用中提供的聊天iOS应用程序调试以下arduino代码: #include <Arduino.h> #include <SPI.h> #include "ble.h" unsigned int reading = 0; void setup() { SPI.setDataMode(SPI_MODE0); SPI.setBitOrder(LSBFIRST); SPI.setClockDivider(

我正在使用RedBear不断地将数据流传输到iOS

我正在使用中提供的聊天iOS应用程序调试以下arduino代码:

#include <Arduino.h>
#include <SPI.h>
#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 << 8;
      reading |= 11; //again same fake data
      buf[1] = reading & 0xFF;
      len = 2;
      Serial.print(reading); Serial.print(" -> LSB:"); Serial.print(buf[1], HEX); Serial.print(" MSB:"); Serial.println(buf[0], HEX);

    len = 2;
    for (int i = 0; i < len; i++)
      ble_write(buf[i]);
    ble_write(0x0D);
    len = 0;

    ble_do_events();

    delay(20);
  }
}
#包括
#包括
#包括“ble.h”
无符号整数读取=0;
无效设置()
{
SPI.setDataMode(SPI_MODE0);
SPI.Setbitor(LSBFfirst);
设置时钟分频器(SPI时钟分频器16);
SPI.begin();
ble_begin();
序列号。开始(57600);
}
无符号字符buf[16]={0};
无符号字符len=0;
void循环()
{
ble_do_events();
如果(ble_connected()){
reading=10;//这是用于测试目的的假数据。
buf[0]=读数;

reading=reading我使用BLE Simple来测试你的程序。你的程序确实卡住了。但是如果你把上一个BLE_do_events()注释掉,一切都很好

似乎应用程序会在一段时间后自动连接并断开与BLE屏蔽的连接。我是BLE新手,对此并不理解……是因为当调用BLE_write时,BLE会广播应用程序以通知这里有短信。然后应用程序会连接BLE并获取短信吗