Simple BLE Example (Scan Advertising Devices, List Details, Connect to One Sensor Device)


#22

Once you know which of the multiple options works for the particular UUIDs you are looking at then you don’t need to include all the alternatives.


#23

@ScruffR - would appreciate your eye on the revised code here. I’m still only outputting Temperature data as per the below example :

Temp 29.5 °C (raw: 2950)
Humd 0.0 (raw: 0)
Temp 29.5 °C (raw: 2950)
Humd 0.0 (raw: 0)

I only assume it is something simple which I’m missing. I was worried that the Temperautre.valid() was causing this but essentially when we receive temperature data we should also have all the other data with…?

Any clues here?


#24

Hold the bus… I seem to have broken through to something here. Am using a hybridisation between two sets of code and am getting something.

Temp 29.6 °C (raw: 2956)
Humd 36.1 (raw: 3606)
Temp 29.6 °C (raw: 2956)
Humd 36.1 (raw: 3606)

No action required yet, thanks, will come back if I get all the sensor data out.

N.


#25
Serial.printlnf("Humd %.1f % (raw: %d)", Humd, rawHumd);

Sincer % is used to escape variable placeholders you need to also escape the percent sign itself.
Consequently you’d need to do this

Serial.printlnf("Humd %.1f %% (raw: %d)", Humd, rawHumd);

in order to get the symbol turn up in the output.

Are you sure you want to have the humidity reading to depend on the validity of the temperature characteristics?

  else if (Temperature.valid()) { 
    loopDelay = 1000;                                                           // when connected read every second could be modulated via delta temp more volatile temperature may warrant a lower loop cadance
    
    Temperature.getValue(&rawTemp);                                             // request temperature from BLE peripheral
    temp = rawTemp / 100.0;                                                     // convert from 100ths, although too simple
    Serial.printlnf("Temp %.1f °C (raw: %d)", temp, rawTemp);
    
    Humidity.getValue(&rawHumd);
    if (sizeof(rawHumd) ==  Humidity.getValue((uint8_t*)&rawHumd, sizeof(rawHumd)))
        Humd = rawHumd / 100.0;
    
    //Humidity.getValue(&rawHumd);                                                // request temperature from BLE peripheral
    //Humd = rawHumd / 100.0;                                                     // convert from 100ths, although too simple
    Serial.printlnf("Humd %.1f %% (raw: %d)", Humd, rawHumd);
    
  }