0

Bluefruit LE Connect for iOS and MQTT
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Bluefruit LE Connect for iOS and MQTT

by Samou on Thu Mar 25, 2021 5:27 am

Hello;

I have an adafruit nRF52832 card AND I use the mobile application (Bleufruitconnect) to send the sensor data to my mailbox, I then discovered the io adafruit platform, I followed a tutorial https://learn.adafruit.com/bluefruit-le-connect/mqtt but its not working I do not know if it is MQTT cause if I have to install something?

I have an adafruit io account.
for the application (Bleufruitconnect) I use it to collect the signal from 4 sensors this is my code
Code: Select all | TOGGLE FULL SIZE
    #include <bluefruit.h>
    #include <Adafruit_LittleFS.h>
    #include <InternalFileSystem.h>
    #define  PIN_VBAT          A7
    #define VBAT_MV_PER_LSB   (0.73242188F)   // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096
    #ifdef NRF52840_XXAA
    #define VBAT_DIVIDER      (0.5F)          // 150K + 150K voltage divider on VBAT
    #define VBAT_DIVIDER_COMP (2.0F)          // Compensation factor for the VBAT divider
    #else
    #define VBAT_DIVIDER      (0.71275837F)   // 2M + 0.806M voltage divider on VBAT = (2M / (0.806M + 2M))
    #define VBAT_DIVIDER_COMP (1.403F)        // Compensation factor for the VBAT divider
    #endif
    #define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
    uint32_t vbat_pin = PIN_VBAT;
    float readVBAT(void) {
    float raw;
    float V;

  // Set the analog reference to 3.0V (default = 3.6V)
  analogReference(AR_INTERNAL_3_0);

  // Set the resolution to 12-bit (0..4095)
  analogReadResolution(12); // Can be 8, 10, 12 or 14

  // Let the ADC settle
  delay(1);

  // Get the raw 12-bit, 0..3000mV ADC value
  raw = analogRead(vbat_pin);

  // Set the ADC back to the default settings
  analogReference(AR_DEFAULT);
  analogReadResolution(10);

  // Convert the raw value to compensated mv, taking the resistor-
  // divider into account (providing the actual LIPO voltage)
  // ADC range is 0..3000mV and resolution is 12-bit (0..4095)
  return raw * REAL_VBAT_MV_PER_LSB;
}
 

    // BLE Service
    BLEDfu  bledfu;  // OTA DFU service
    BLEDis  bledis;  // device information
    BLEUart bleuart; // uart over ble
    BLEBas  blebas;  // battery
    int adcin = A0;
    int adcin1 = A1;
    int adcin2 = A2;
    int adcin3 = A3;
    float mv_per_lsb = 3600.0F/1024.0F; // 10-bit ADC with 3.6V input range
   
    int  adcvalue = analogRead(adcin);
    int  adcvalue1 = analogRead(adcin1);
    int  adcvalue2 = analogRead(adcin2);
    int  adcvalue3 = analogRead(adcin3);
   
    unsigned long time;
   
   
    void setup()
    {
      Serial.begin(115200);

    #if CFG_DEBUG
      // Blocking wait for connection when debug mode is enabled via IDE
      while ( !Serial ) yield();
      readVBAT();
    #endif
   
      Serial.println("Bluefruit52 BLEUART Example");
      Serial.println("---------------------------\n");

      // Setup the BLE LED to be enabled on CONNECT
      // Note: This is actually the default behaviour, but provided
      // here in case you want to control this LED manually via PIN 19
      Bluefruit.autoConnLed(true);

      // Config the peripheral connection with maximum bandwidth
      // more SRAM required by SoftDevice
      // Note: All config***() function must be called before begin()
      Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);

      Bluefruit.begin();
      Bluefruit.setTxPower(4);    // Check bluefruit.h for supported values
      Bluefruit.setName("Bluefruit52");
      //Bluefruit.setName(getMcuUniqueID()); // useful testing with multiple central connections
      Bluefruit.Periph.setConnectCallback(connect_callback);
      Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
      Bluefruit.Periph.setConnInterval(9,12);

      // To be consistent OTA DFU should be added first if it exists
      bledfu.begin();

      // Configure and Start Device Information Service
      bledis.setManufacturer("Adafruit Industries");
      bledis.setModel("Bluefruit Feather52");
      bledis.begin();

      // Configure and Start BLE Uart Service
      bleuart.begin();

      // Start BLE Battery Service
      blebas.begin();
      blebas.write(100);

      // Set up and start advertising
      startAdv();
     
      Serial.println("Please use Adafruit's Bluefruit LE app to connect in UART mode");
      Serial.println("Once connected, enter character(s) that you wish to send");
    }

    void startAdv(void)
    {
      // Advertising packet
      Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
      Bluefruit.Advertising.addTxPower();

      // Include bleuart 128-bit uuid
      Bluefruit.Advertising.addService(bleuart);

      // Secondary Scan Response packet (optional)
      // Since there is no room for 'Name' in Advertising packet
      Bluefruit.ScanResponse.addName();
      Bluefruit.Advertising.restartOnDisconnect(true);
      Bluefruit.Advertising.setInterval(32, 244);    // in unit of 0.625 ms
      Bluefruit.Advertising.setFastTimeout(30);      // number of seconds in fast mode
      Bluefruit.Advertising.start(0);                // 0 = Don't stop advertising after n seconds
    }

    void loop()
    {
  float vbat_mv = readVBAT();
     while (true)
     {
          time = millis();
          char data[10];
          int adcin = A0;
          int adcin1 = A1;
          int adcin2 = A2;
          int adcin3 = A3;
          int off = A5;
          float vbat_mv = readVBAT();
          int  adcvalue = analogRead(adcin);
          int  adcvalue1 = analogRead(adcin1);
          int  adcvalue2 = analogRead(adcin2);
          int  adcvalue3 = analogRead(adcin3);
          int  offest = analogRead(off);
          float  ad=((float)adcvalue * mv_per_lsb);// tension d'éntrée 1
          float  ad1=((float)adcvalue1 * mv_per_lsb);// tension d'éntrée 2
          float  ad2=((float)adcvalue2 * mv_per_lsb);// tension d'éntrée 3
          float  ad3=((float)adcvalue3 * mv_per_lsb);// tension d'éntrée 4
          float  of=((float)offest* mv_per_lsb);// tension d'éntrée 4
          //float  BAT=((float)vbat_mv);// alimantation Battrie
       
          sprintf(data,"T:%u,A0:%g,A1:%g,A2:%g,A3:%g",time,ad, ad1,ad2,ad3); // acquisition de données sur tt les informations (signal réelle, offset , battrie)
          //sprintf(data,"T:%u,A0:%g,",time,V); // acquisition de données du signal propre (sans l'offset
          //bleuart.print(data);
          bleuart.println(ad);//  visualisation du signal en direct                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          );
          delay(11.25);             
     }
     
    }
     
    // callback invoked when central connects
    void connect_callback(uint16_t conn_handle)
    {
      // Get the reference to current connection
      BLEConnection* connection = Bluefruit.Connection(conn_handle);

      char central_name[32] = { 0 };
      connection->getPeerName(central_name, sizeof(central_name));

      Serial.print("Connected to ");
      Serial.println(central_name);
    }
    void disconnect_callback(uint16_t conn_handle, uint8_t reason){
 
      (void) conn_handle;
      (void) reason;

      Serial.println();
      Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
    }


Thanks

Samou
 
Posts: 34
Joined: Thu May 07, 2020 12:19 pm

Re: Bluefruit LE Connect for iOS and MQTT

by brubell on Fri Mar 26, 2021 9:22 am

, I followed a tutorial https://learn.adafruit.com/bluefruit-le-connect/mqtt but its not working I do not know if it is MQTT cause if I have to install something?


What, specifically is not working?

brubell
 
Posts: 1383
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.