Arduino101 BLE how to sending data


hello arduino~
i try use ble send data arduino101 another
so refer heart rate monitor sample code

my code looks this
code: [select]

#include <curieble.h>


bleperipheral bleperipheral;         // ble peripheral device (the board you're programming)
bleservice heartrateservice("180d"); // ble heart rate service

// ble heart rate measurement characteristic"
blecharacteristic heartratechar("2a37",  // standard 16-bit characteristic uuid
    bleread | blenotify, 2);  // remote clients able notifications if characteristic changes
                              // characteristic 2 bytes long first field needs "flags" per ble specifications
                              // https://developer.bluetooth.org/gatt/characteristics/pages/characteristicviewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml
int heartrate = 0;
int oldheartrate = 0;  // last heart rate reading analog input
long previousmillis = 0;  // last time heart rate checked, in ms


int pin = 3;  // 3번핀은 오른쪽과 동시에 되므로 오른쪽 키를 사용하지 말
int pin_button_up = 2;
int pin_button_left = 5;
int pin_analog_x = 0;
int pin_analog_y = 1;
int button[] = {2,5};

int *px;
int *py;


void setup() {
  serial.begin(9600);    // initialize serial communication
  pinmode(13, output);   // initialize led on pin 13 indicate when central connected

  /* set local name ble device
     this name appear in advertising packets
     and can used remote devices identify ble device
     the name can changed maybe truncated based on space left in advertisement packet */
  bleperipheral.setlocalname("controller");
  bleperipheral.setadvertisedserviceuuid(heartrateservice.uuid());  // add service uuid
  bleperipheral.addattribute(heartrateservice);   // add ble heart rate service
  bleperipheral.addattribute(heartratechar); // add heart rate measurement characteristic

  /* activate ble device.  start continuously transmitting ble
     advertising packets , visible remote ble central devices
     until receives new connection */
  bleperipheral.begin();
  serial.println("bluetooth device active, waiting connections...");

  for(int = 0; < 2; i++){pinmode(button[i], input_pullup);}
}

void loop() {
  // listen ble peripherals connect:

  int = digitalread(pin_button_up);
  int left = digitalread(pin_button_left);
  int x = analogread(pin_analog_x);
  int y = analogread(pin_analog_y);

  px = &x;
  py = &y;
 
 
  blecentral central = bleperipheral.central();

  // if central connected peripheral:
  if (central) {
    serial.print("connected central: ");
    // print central's mac address:
    serial.println(central.address());
    // turn on led indicate connection:
    digitalwrite(13, high);

    // check heart rate measurement every 200ms
    // long central still connected:
    while (central.connected()) {
      long currentmillis = millis();
      // if 200ms have passed, check heart rate measurement:
      if (currentmillis - previousmillis >= 200) {
        previousmillis = currentmillis;
        updateheartrate();
      }
    }
    // when central disconnects, turn off led:
    digitalwrite(13, low);
    serial.print("disconnected central: ");
    serial.println(central.address());
  }
}

void updateheartrate() {
    heartrate = controller(*px,*py);
    if(heartrate != oldheartrate)
    {      // if heart rate has changed
      serial.print("heart rate now: "); // print it
      serial.println(heartrate);
      const unsigned char heartratechararray[2] = { 0, (char)heartrate };
      heartratechar.setvalue(heartratechararray, 2);  // , update heart rate measurement characteristic
    oldheartrate = heartrate;           // save level next comparison
    }
}

int controller(int x, int y)
  {
    if(0 <= x && x < 134 && 583 <= y && y < 1025){heartrate = 10;}         // fl30
    else if(134 <= x && x < 198 && 583 <= y && y < 1025){heartrate = 11;}  // fl25
    else if(198 <= x && x < 262 && 583 <= y && y < 1025){heartrate = 12;}  // fl20
    else if(262 <= x && x < 326 && 583 <= y && y < 1025){heartrate = 13;}  // fl15
    else if(326 <= x && x < 390 && 583 <= y && y < 1025){heartrate = 14;}  // fl10
    else if(390 <= x && x < 454 && 583 <= y && y < 1025){heartrate = 15;}  // fl05
    else if(454 <= x && x < 554 && 583 <= y && y < 1025){heartrate = 16;}  // fs00
    else if(554 <= x && x < 632 && 583 <= y && y < 1025){heartrate = 17;}  // fr05
    else if(632 <= x && x < 710 && 583 <= y && y < 1025){heartrate = 18;}  // fr10
    else if(710 <= x && x < 788 && 583 <= y && y < 1025){heartrate = 19;}  // fr15
    else if(788 <= x && x < 866 && 583 <= y && y < 1025){heartrate = 20;}  // fr20
    else if(866 <= x && x < 944 && 583 <= y && y < 1025){heartrate = 21;}  // fr25
    else if(944 <= x && x < 1025 && 583 <= y && y < 1025){heartrate = 22;} // fr30
 
 
    else if(0 <= x && x < 134 && 473 <= y && y < 583){heartrate = 23;}     // hl30
    else if(134 <= x && x < 198 && 473 <= y && y < 583){heartrate = 24;}   // hl25
    else if(198 <= x && x < 262 && 473 <= y && y < 583){heartrate = 25;}   // hl20
    else if(262 <= x && x < 326 && 473 <= y && y < 583){heartrate = 26;}   // hl15
    else if(326 <= x && x < 390 && 473 <= y && y < 583){heartrate = 27;}   // hl10
    else if(390 <= x && x < 454 && 473 <= y && y < 583){heartrate = 28;}   // hl05
    else if(454 <= x && x < 554 && 473 <= y && y < 583){heartrate = 29;}   // hs00
    else if(554 <= x && x < 632 && 473 <= y && y < 583){heartrate = 30;}   // hr05
    else if(632 <= x && x < 710 && 473 <= y && y < 583){heartrate = 31;}   // hr10
    else if(710 <= x && x < 788 && 473 <= y && y < 583){heartrate = 32;}   // hr15
    else if(788 <= x && x < 866 && 473 <= y && y < 583){heartrate = 33;}   // hr20
    else if(866 <= x && x < 944 && 473 <= y && y < 583){heartrate = 34;}   // hr25
    else if(944 <= x && x < 1025 && 473 <= y && y < 583){heartrate = 35;}  // hr30
 
    else if(0 <= x && x < 134 && 0 <= y && y < 473){heartrate = 36;}       // bl30
    else if(134 <= x && x < 198 && 0 <= y && y < 473){heartrate = 37;}     // bl25
    else if(198 <= x && x < 262 && 0 <= y && y < 473){heartrate = 38;}     // bl20
    else if(262 <= x && x < 326 && 0 <= y && y < 473){heartrate = 39;}     // bl15
    else if(326 <= x && x < 390 && 0 <= y && y < 473){heartrate = 40;}     // bl10
    else if(390 <= x && x < 454 && 0 <= y && y < 473){heartrate = 41;}     // bl05
    else if(454 <= x && x < 554 && 0 <= y && y < 473){heartrate = 42;}     // bs00
    else if(554 <= x && x < 632 && 0 <= y && y < 473){heartrate = 43;}     // br05
    else if(632 <= x && x < 710 && 0 <= y && y < 473){heartrate = 44;}     // br10
    else if(710 <= x && x < 788 && 0 <= y && y < 473){heartrate = 45;}     // br15
    else if(788 <= x && x < 866 && 0 <= y && y < 473){heartrate = 46;}     // br20
    else if(866 <= x && x < 944 && 0 <= y && y < 473){heartrate = 47;}     // br25
    else if(944 <= x && x < 1025 && 0 <= y && y < 473){heartrate= 48;}     // br30

    return heartrate;
  }


well code not made code
full of errors, compiled anyway
i use joystick shield , read data that
and send specific data via ble

return topic
when upload , connect android nrf toolbox applications
nothing shows in graph

why happens?
because service read analog sample?

if want send data service fit me?


please me  :o

quote
full of errors, compiled anyway
i haven't looked through code specific problems, if code compiled lot of warnings, that's sign program may not behave in way you're expecting :)

fixing warnings might go long way you!


Arduino Forum > Products > Arduino 101 (Moderators: cmaglie, facchinm) > Arduino101 BLE how to sending data


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor