这可能是一个非常基本的问题,但我现在已经进行了几个小时的谷歌搜索,无法找到解决方案。
我正在尝试将三个值从我的RFduino发送到我的iPhone,然后这三个值应该显示在我的自定义应用程序上(非常简单)。为此,我更改了我在GitHub上找到的给定温度应用程序和RFduino代码。
但在所有示例中,他们只通过BLE发送1个值,如何在不立即覆盖的情况下发送多个值?
在我的代码中,我试图像这样做,我也试过数组,字符数组,但没有任何工作,目前应用程序只是打破..
我的RFduino代码看起来像这样(最小的例子)
#include <Wire.h>
#include <RFduinoBLE.h>
#include "Arduino.h"
int16_t x1,x2,x3;
void setup(){
Wire.begin();
Serial.begin(9600);
Serial.println("setting up Sensor...");
SetupSensor(); // Configure sensor
delay(1500); //wait for the sensor to be ready
RFduinoBLE.advertisementData = "sensor";
// start the BLE stack
RFduinoBLE.begin();
}
void loop(){
RFduino_ULPDelay( 25 );
getSensorValues(); // sensor update
RFduinoBLE.sendByte(x1);
RFduinoBLE.sendByte(x2);
RFduinoBLE.sendByte(x3);
}
(如果我发送Byte或Int或Float以及内部转换的全部内容,我也很困惑。)
&#34;有趣的&#34;应用程序代码的一部分就是这个:
- (void)didReceive:(NSData *)data
{
NSLog(@"RecievedRX");
float x1 = dataFloat(data);
float x2 = dataFloat(data);
float x3 = dataFloat(data);
NSString* string1 = [NSString stringWithFormat:@"%.2f", x1];
NSString* string2 = [NSString stringWithFormat:@"%.2f", x2];
NSString* string3 = [NSString stringWithFormat:@"%.2f", x3];
[label1 setText:string1];
[label2 setText:string2];
[label2 setText:string3];
}
我知道这是完全错误的,但我不知道如何修复它?我可以以某种方式将我的值打包成一个数组并一个一个地发送吗?