I would like to check if my Arduino 101 can make bluetooth connection?


i keep getting message
code: [select]
"not connected central " when run code. should when having situation this? please bear me if question broad, beginner hardware programming.

my code below (its line
code: [select]
blecentral central = bleperipheral.central(); causing trouble)

code: [select]
#include "mutichannelgassensor.h"
//#include <spi.h>               // required have support signed/unsigned long type
#include <curieble.h>
//#include <bleperipheral.h>

// create own uuids; used https://www.uuidgenerator.net/
#define data_service_uuid "5badc414-a8f6-4692-849e-23aa5d97aa3c"
#define deviceid_char_uuid "935626b3-6996-4b09-b6dc-02695f307f7a"
#define nh3_char_uuid "fbd5e235-8892-4f51-9d52-1450c94f722d"
#define co_char_uuid "80c50a3f-663f-4a3b-ab54-f73d7e7699f8"
#define no2_char_uuid "b3cb7efc-1352-498f-a4f0-5397ae648b70"
#define c3h8_char_uuid "e002c096-a23e-42b8-a340-571dbded7c47"
#define c4h10_char_uuid "6e02eb88-332d-4a70-920e-fb302169b4b0"
#define ch4_char_uuid "f3bacc86-caac-4db3-ae24-47f424dc22e8"
#define h2_char_uuid "c56089e6-682d-44c4-9e10-4a8beafbe4da"
#define c2h5oh_char_uuid "86599cc0-e642-43c8-86c8-0b97738d5e96"

// arduino 101 acts ble peripheral
bleperipheral bleperipheral;

// data registered ble service
bleservice dataservice(data_service_uuid);

// each data point own characteristic
bleintcharacteristic devicechar(deviceid_char_uuid, bleread | blenotify);
blefloatcharacteristic nh3char(nh3_char_uuid, bleread | blenotify);
blefloatcharacteristic cochar(co_char_uuid, bleread | blenotify);
blefloatcharacteristic no2char(no2_char_uuid, bleread | blenotify);
blefloatcharacteristic c3h8char(c3h8_char_uuid, bleread | blenotify);
blefloatcharacteristic c4h10char(c4h10_char_uuid, bleread | blenotify);
blefloatcharacteristic ch4char(ch4_char_uuid, bleread | blenotify);
blefloatcharacteristic h2char(h2_char_uuid, bleread | blenotify);
blefloatcharacteristic c2h5ohchar(c2h5oh_char_uuid, bleread | blenotify);

// assign pin indicate ble connection
const int indicator_pin = 13;

int deviceid = 1; float nh3 = 0; float co = 0; float no2 = 0; float c3h8 = 0;
float c4h10 = 0; float ch4 = 0; float h2 = 0; float c2h5oh = 0;
// variables each gas element detected gas sensor
long previousmillis = 0;


void setup()
{
    /*
     * setup() sets baud rate, gas sensor (connected board via i2c pin, ,
     * wifi connection
     */

     delay(10000);

     serial.println("start!");

    serial.begin(115200);

    serial.println("1");

    //bleperipheral = new bleperipheral();

    // initialize ble peripheral
    bleperipheral.setlocalname("sensor_data");
    bleperipheral.setadvertisedserviceuuid(dataservice.uuid());
    bleperipheral.addattribute(dataservice);
    bleperipheral.addattribute(devicechar);
    bleperipheral.addattribute(nh3char);
    bleperipheral.addattribute(cochar);
    bleperipheral.addattribute(no2char);
    bleperipheral.addattribute(c3h8char);
    bleperipheral.addattribute(c4h10char);
    bleperipheral.addattribute(ch4char);
    bleperipheral.addattribute(h2char);
    bleperipheral.addattribute(c2h5ohchar);
    serial.println("2");
    // set initial values
    devicechar.setvalue(deviceid);
    nh3char.setvalue(nh3);
    cochar.setvalue(co);
    no2char.setvalue(no2);
    c3h8char.setvalue(c3h8);
    c4h10char.setvalue(c4h10);
    ch4char.setvalue(ch4);
    h2char.setvalue(h2);
    c2h5ohchar.setvalue(c2h5oh);
    serial.println("3");
    // now, activate ble peripheral
    bleperipheral.begin();
    serial.println("bluetooth device active, waiting connections...");

    if (bleperipheral.connected()){
      serial.println("peripheral connected!");
    }else{
      serial.println("peripheral not connected!");
    }
    // configure gas sensor
    gas.begin(0x04);//the default i2c address of slave 0x04
    gas.poweron(); 
}

void loop()
{
 /**
   * loop() retrieves data read gas sensor using instance gas mutichannelgassensor.h,
   * parses them such creates json string, , make api call (insertrawdata)
   * microservice app (the sptring boot project) add data data repository (nosql)
   **/ 

 // check if connection central active or not
 blecentral central = bleperipheral.central();

 if (central){
   serial.print("connected central: ");
   serial.println(central.address());

   while(central.connected()) {
     updatesensordata();
   }

   serial.print("disconnected central: ");
   serial.println(central.address());
 }else{
   serial.println("not connected central ");
 }

  delay(1000);
}

void updatesensordata(){
   /* updatesensordata()
    * 
    */
    // call functions measures gases read sensor
    nh3 = gas.measure_nh3();
    co = gas.measure_co();
    no2 = gas.measure_no2();
    c3h8 = gas.measure_c3h8();
    c4h10 = gas.measure_c4h10();
    ch4 = gas.measure_ch4();
    h2 = gas.measure_h2();
    c2h5oh = gas.measure_c2h5oh();

    nh3char.setvalue(nh3);
    cochar.setvalue(co);
    no2char.setvalue(no2);
    c3h8char.setvalue(c3h8);
    c4h10char.setvalue(c4h10);
    ch4char.setvalue(ch4);
    h2char.setvalue(h2);
    c2h5ohchar.setvalue(c2h5oh);

    serial.println("update complete!");

    delay(1000);
}





Arduino Forum > Products > Arduino 101 (Moderators: cmaglie, facchinm) > I would like to check if my Arduino 101 can make bluetooth connection?


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts