removed old stuff
This commit is contained in:
parent
52c1ffdb5d
commit
5507d11fe8
26 changed files with 2 additions and 540 deletions
|
|
@ -1,92 +0,0 @@
|
|||
#include <BLEDevice.h>
|
||||
#include <BLEServer.h>
|
||||
#include <BLE2902.h>
|
||||
#include "BluetoothServer.h"
|
||||
|
||||
#define INTERNAL_LED_PIN 2
|
||||
#define BLE_SERVER_NAME "ClimateGO"
|
||||
#define SERVICE_UUID "2150123c-af53-4038-bc92-ba3d0870a9e4"
|
||||
#define TEMPERATURE_CHARACTERISTIC_UUID "cba1d466-344c-4be3-ab3f-189f80dd7518"
|
||||
#define PRESSURE_CHARACTERISTIC_UUID "ca73b3ba-39f6-4ab3-91ae-186dc9577d99"
|
||||
|
||||
//Setup callbacks onConnect and onDisconnect
|
||||
class ServerCallbacks : public BLEServerCallbacks {
|
||||
void onConnect(BLEServer *pServer) override {
|
||||
Serial.println("New device connected.");
|
||||
digitalWrite(INTERNAL_LED_PIN, HIGH);
|
||||
};
|
||||
|
||||
void onDisconnect(BLEServer *pServer) override {
|
||||
Serial.println("Device disconnected.");
|
||||
digitalWrite(INTERNAL_LED_PIN, LOW);
|
||||
//restart advertising on device disconnect
|
||||
pServer->getAdvertising()->start();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents the Bluetooth server that handles all interactions
|
||||
*/
|
||||
BluetoothServer::BluetoothServer() {
|
||||
// Create the BLE Device
|
||||
BLEDevice::init(BLE_SERVER_NAME);
|
||||
|
||||
// Create the BLE Server
|
||||
this->bleServer = BLEDevice::createServer();
|
||||
bleServer->setCallbacks(new ServerCallbacks());
|
||||
|
||||
// Create the BLE Service
|
||||
this->sensorService = bleServer->createService(SERVICE_UUID);
|
||||
|
||||
//create characteristics that will enable data sharing
|
||||
BLECharacteristic *temperatureCharacteristic = sensorService->createCharacteristic(
|
||||
TEMPERATURE_CHARACTERISTIC_UUID,
|
||||
BLECharacteristic::PROPERTY_READ
|
||||
);
|
||||
BLECharacteristic *pressureCharacteristic = sensorService->createCharacteristic(
|
||||
PRESSURE_CHARACTERISTIC_UUID,
|
||||
BLECharacteristic::PROPERTY_READ
|
||||
);
|
||||
|
||||
//set initial values
|
||||
temperatureCharacteristic->setValue("NA");
|
||||
pressureCharacteristic->setValue("NA");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to start the Bluetooth server and enable advertising to allow other devices to connect
|
||||
*/
|
||||
void BluetoothServer::startServer() {
|
||||
// Start the service
|
||||
this->sensorService->start();
|
||||
|
||||
// Start advertising
|
||||
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
|
||||
pAdvertising->addServiceUUID(SERVICE_UUID);
|
||||
this->bleServer->getAdvertising()->start();
|
||||
Serial.println("Started BLE Server.");
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Convert temperature to string somehow
|
||||
* Publish a new temperature to the appropriate characteristic
|
||||
* @param temperature the new temperature
|
||||
*/
|
||||
void BluetoothServer::setTemperature(float temperature) {
|
||||
sensorService
|
||||
->getCharacteristic(TEMPERATURE_CHARACTERISTIC_UUID)
|
||||
->setValue(temperature);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Convert pressure to string somehow
|
||||
* Publish a new pressure to the appropriate characteristic
|
||||
* @param pressure the new pressure
|
||||
*/
|
||||
void BluetoothServer::setPressure(float pressure) {
|
||||
sensorService
|
||||
->getCharacteristic(PRESSURE_CHARACTERISTIC_UUID)
|
||||
->setValue(pressure);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
#ifndef NEW_CLIMTE_GO_BLUETOOTHSERVER_H
|
||||
#define NEW_CLIMTE_GO_BLUETOOTHSERVER_H
|
||||
|
||||
#include <BLEDevice.h>
|
||||
#include <BLEServer.h>
|
||||
#include <BLEUtils.h>
|
||||
#include <BLE2902.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
#define temperatureCelsius
|
||||
|
||||
class BluetoothServer {
|
||||
private:
|
||||
BLEService *sensorService;
|
||||
BLEServer *bleServer;
|
||||
public:
|
||||
BluetoothServer();
|
||||
|
||||
void startServer();
|
||||
void setTemperature(float temperature);
|
||||
void setPressure(float pressure);
|
||||
};
|
||||
|
||||
|
||||
#endif //NEW_CLIMTE_GO_BLUETOOTHSERVER_H
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
#include <Arduino.h>
|
||||
#include <sensors/BmpSensor.h>
|
||||
#include <ble/BluetoothServer.h>
|
||||
|
||||
#define SLEEP_TIME 2
|
||||
#define BAUD_RATE 112500
|
||||
#define INTERNAL_LED_PIN 2
|
||||
|
||||
|
||||
Sensor *bmpSensor;
|
||||
BluetoothServer *server;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(BAUD_RATE);
|
||||
pinMode(INTERNAL_LED_PIN, OUTPUT);
|
||||
|
||||
bmpSensor = new BmpSensor();
|
||||
|
||||
server = new BluetoothServer();
|
||||
server->startServer();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
sensor_data_t sample = ((BmpSensor *) bmpSensor)->sampleLowEnergy();
|
||||
server->setPressure(sample.pressure);
|
||||
server->setTemperature(sample.temperature);
|
||||
delay(SLEEP_TIME * 1000);
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_BMP280.h>
|
||||
#include "BmpSensor.h"
|
||||
|
||||
/**
|
||||
* Creates a new BMP Sensor and initializes it
|
||||
*/
|
||||
BmpSensor::BmpSensor() {
|
||||
this->BmpSensor::sensor_setup();
|
||||
this->state = SensorState::ASLEEP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function responsible for setting up the sensor and the I2C connection
|
||||
*/
|
||||
void BmpSensor::sensor_setup() {
|
||||
while (!Serial) delay(100); // wait for native usb
|
||||
|
||||
unsigned status = this->bmp.begin(0x76); //set the correct I2C port
|
||||
|
||||
//query status and reboot the board if no sensor is detected
|
||||
if (!status)
|
||||
ESP.restart();
|
||||
|
||||
//put sensor to standby mode
|
||||
this->enableStandbyMode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to wake sensor up from standby mode
|
||||
*/
|
||||
void BmpSensor::wakeUp() {
|
||||
this->bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
|
||||
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
|
||||
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
|
||||
Adafruit_BMP280::FILTER_X16, /* Filtering. */
|
||||
Adafruit_BMP280::STANDBY_MS_500 /* Standby time. */
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to put sensor to standby mode
|
||||
*/
|
||||
void BmpSensor::enableStandbyMode() {
|
||||
this->bmp.setSampling(Adafruit_BMP280::MODE_SLEEP, /* Operating Mode. */
|
||||
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
|
||||
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
|
||||
Adafruit_BMP280::FILTER_X16, /* Filtering. */
|
||||
Adafruit_BMP280::STANDBY_MS_500 /* Standby time. */
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* read a sample from the sensor
|
||||
* @return a struct containing all necessary sensor data
|
||||
*/
|
||||
sensor_data_t BmpSensor::sample() {
|
||||
//wake sensor up if it is in standby mode
|
||||
if (this->state == SensorState::ASLEEP)
|
||||
this->wakeUp();
|
||||
|
||||
//sample pressure and temperature
|
||||
sensors_event_t temp_event, pressure_event;
|
||||
this->bmp_temp->getEvent(&temp_event);
|
||||
this->bmp_pressure->getEvent(&pressure_event);
|
||||
|
||||
|
||||
return sensor_data_t
|
||||
{
|
||||
temp_event.temperature,
|
||||
pressure_event.pressure
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a sample and put sensor to standby mode.
|
||||
* !!! Do not use this if sampling time is <= 500ms !!!
|
||||
* @return the sample read
|
||||
*/
|
||||
sensor_data_t BmpSensor::sampleLowEnergy() {
|
||||
//read sample
|
||||
sensor_data_t sampledData = this->sample();
|
||||
//put sensor to standby
|
||||
this->enableStandbyMode();
|
||||
return sampledData;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
#ifndef NEW_CLIMTE_GO_BMPSENSOR_H
|
||||
#define NEW_CLIMTE_GO_BMPSENSOR_H
|
||||
|
||||
#include "Sensor.h"
|
||||
#include "Adafruit_BMP280.h"
|
||||
|
||||
class BmpSensor : public Sensor {
|
||||
private:
|
||||
Adafruit_BMP280 bmp; // use I2C interface
|
||||
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
|
||||
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
|
||||
|
||||
public:
|
||||
BmpSensor();
|
||||
|
||||
sensor_data_t sample() override;
|
||||
sensor_data_t sampleLowEnergy();
|
||||
|
||||
void enableStandbyMode() override;
|
||||
|
||||
void wakeUp() override;
|
||||
|
||||
protected:
|
||||
void sensor_setup() override;
|
||||
|
||||
};
|
||||
|
||||
#endif //NEW_CLIMTE_GO_BMPSENSOR_H
|
||||
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
#ifndef NEW_CLIMTE_GO_SENSOR_H
|
||||
#define NEW_CLIMTE_GO_SENSOR_H
|
||||
|
||||
#include <sensors/sensor_data_t.h>
|
||||
|
||||
enum class SensorState : unsigned short {
|
||||
AWAKE, ASLEEP
|
||||
};
|
||||
|
||||
class Sensor {
|
||||
public:
|
||||
virtual sensor_data_t sample() = 0;
|
||||
|
||||
virtual void wakeUp() = 0;
|
||||
|
||||
virtual void enableStandbyMode() = 0;
|
||||
|
||||
protected:
|
||||
SensorState state = SensorState::ASLEEP;
|
||||
|
||||
virtual void sensor_setup() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif //NEW_CLIMTE_GO_SENSOR_H
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#ifndef NEW_CLIMTE_GO_SENSOR_DATA_T_H
|
||||
#define NEW_CLIMTE_GO_SENSOR_DATA_T_H
|
||||
|
||||
#include <types.h>
|
||||
|
||||
/**
|
||||
* This struct represents data read from any sensor.
|
||||
* This implies, reading temperature from e.g. the CO2 Sensor
|
||||
* does not make any sense
|
||||
*/
|
||||
struct sensor_data_t {
|
||||
float temperature;
|
||||
float pressure;
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue