Apps download but do not communicate

Greetings,

I have been hard at work and I have the following Arduino IDE and MIT App Inventor sketches that compile and download respectively, but there seem to be no communication between them. Pressing the "Connect" button fails to establish a connection.

I would really appreciate it if someone would give these codes a look-over and, perhaps, let me know where I am failing. I feel like I am 95% of the way there when everything shows up like the app on my Android phone but I am currently running in circles.

Arduino Code Follows:

#include <ArduinoBLE.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define BLE_NAME "Psychrometer"
#define SERVICE_UUID "19B10000-E8F2-537E-4F6C-D104768A1214"
#define TEMPERATURE_UUID "19B10001-E8F2-537E-4F6C-D104768A1214"
#define HUMIDITY_UUID "19B10002-E8F2-537E-4F6C-D104768A1214"
#define PRESSURE_UUID "19B10003-E8F2-537E-4F6C-D104768A1214"

Adafruit_BME280 bme;

BLEService bmeService(SERVICE_UUID);
BLEFloatCharacteristic temperatureCharacteristic(TEMPERATURE_UUID, BLERead | BLENotify);
BLEFloatCharacteristic humidityCharacteristic(HUMIDITY_UUID, BLERead | BLENotify);
BLEFloatCharacteristic pressureCharacteristic(PRESSURE_UUID, BLERead | BLENotify);

void setup() {
  Serial.begin(9600);
  while (!Serial);

  if (!bme.begin()) {
    Serial.println("Could not find BME280 sensor, check wiring!");
    while (1);
  }

  if (!BLE.begin()) {
    Serial.println("Failed to start BLE!");
    while (1);
  }

  BLE.setLocalName(BLE_NAME);
  BLE.setAdvertisedService(bmeService);

  bmeService.addCharacteristic(temperatureCharacteristic);
  bmeService.addCharacteristic(humidityCharacteristic);
  bmeService.addCharacteristic(pressureCharacteristic);

  BLE.addService(bmeService);

  temperatureCharacteristic.writeValue(0);
  humidityCharacteristic.writeValue(0);
  pressureCharacteristic.writeValue(0);

  BLE.advertise();

  Serial.println("BLE peripheral is now active");
}

void loop() {
  BLEDevice central = BLE.central();

  if (central) {
    Serial.print("Connected to central: ");
    Serial.println(central.address());

    while (central.connected()) {
      float temperature = bme.readTemperature();
      float humidity = bme.readHumidity();
      float pressure = bme.readPressure() / 100.0F;

      Serial.print("Temperature: ");
      Serial.print(temperature);
      Serial.println(" °C");

      Serial.print("Humidity: ");
      Serial.print(humidity);
      Serial.println(" %");

      Serial.print("Pressure: ");
      Serial.print(pressure);
      Serial.println(" hPa");

      temperatureCharacteristic.writeValue(temperature);
      humidityCharacteristic.writeValue(humidity);
      pressureCharacteristic.writeValue(pressure);

      delay(1000);
    }

    Serial.print("Disconnected from central: ");
    Serial.println(central.address());
  }
}

MIT App Inventor block diagram:

MIT App Inventor:
[Psychrometer.aia |attachment]

(upload://xc1x04cRUew47CpYOMydUrRXXhz.aia) (198.3 KB)

I have no BLE experience, but I have read some BLE posts on this board, so I will take a guess in the hope that one of the real BLE experts will come along to save you.

I notice these lines of code in your sketch:

Further down in the sketch you write to those characteristics:

Is it possible that besides the permission BLERead and BLENotify those 3 characteristics need a third permission, to Write or Send data?

Regarding the AI2 app, a good way to bypass AI2 is to look for a general purpose BLE terminal app in the Play Store, and use that app to verify that your sketch is sending data, as an impartial third party.

Regarding your app, unfortunately the .aia upload failed, so I have only access to your screen shots.

I don't see any BLE block to ask for floats, nor any BLE event blocks for FloatsReceived.

I assume your app is trying to send floats because that's the data type of the variables you feed to the writeValue commands. (As opposed to PRINT commands, which yield text.)

In your app, that BLE Strings Received event looks unlikely to get anything, because:

  • You sent floats, not text
  • You did not register to receive Strings (or floats, for that matter, as far as I can see.)

Greetings,

Thank you, that is a lot to chew on. I will look over what you have written and try to solve this. My 3rd party nRF Connect app cannot find the Arduino sketch when it is running so I think you are on to something.

Respectfully - Baran