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)