Created
September 2, 2019 00:28
-
-
Save kikermo/50f89a8b79548aac9eef00b057786f45 to your computer and use it in GitHub Desktop.
BLE configuration for greenhouse project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bluefruit.h> | |
| // BLE | |
| #define TX_POWER (4) // Transmission power in dBm (check bluefruit.h) | |
| #define ENVIROMENTAL_SERVICE_UUID (0x181A) | |
| #define HUMIDITY_CHARACTERISTIC_UUID (0x2A6F) | |
| BLEDis bledis; // device information | |
| BLEService bleEnvService = BLEService(ENVIROMENTAL_SERVICE_UUID); | |
| BLECharacteristic bleHumidityC = BLECharacteristic(HUMIDITY_CHARACTERISTIC_UUID); | |
| void setup() { | |
| Bluefruit.autoConnLed(true); | |
| Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); | |
| Bluefruit.begin(); | |
| Bluefruit.setTxPower(TX_POWER); | |
| Bluefruit.setName("Greenhouse Monitor"); | |
| Bluefruit.Periph.setConnectCallback(deviceConnectedCallback); | |
| Bluefruit.Periph.setDisconnectCallback(deviceDisconnectedCallback); | |
| // Configure and Start Device Information Service | |
| bledis.setManufacturer("Kikermo Industries"); | |
| bledis.setModel("Bluefruit Feather52"); | |
| bledis.begin(); | |
| // Start GreenHouse Service | |
| bleEnvService.begin(); | |
| // Configure humidity characteristic | |
| bleHumidityC.setProperties(CHR_PROPS_NOTIFY); | |
| bleHumidityC.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); | |
| bleHumidityC.setFixedLen(1); | |
| bleHumidityC.begin(); | |
| bleHumidityC.write(0); | |
| // Set up and start advertising | |
| startAdv(); | |
| } | |
| 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(bleEnvService); | |
| // 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 | |
| } | |
| // callback invoked when the connection is established | |
| void deviceConnectedCallback(uint16_t connectionHandle) { | |
| } | |
| /** | |
| Callback invoked when a connection is dropped | |
| */ | |
| void deviceDisconnectedCallback(uint16_t connectionHandle, uint8_t reason) { | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment