SunTracker_BLE
Dependencies: BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 X_NUCLEO_IHM01A1 X_NUCLEO_IKS01A1 mbed
Fork of SunTracker_BLE by
Overview
The SunTracker is a demo application running on ST Nucleo-F401RE stacking a set of ST X-NUCLEO expansion boards.
Main features provided are:
- A solar panel follows the light source, orienting the panel in order to achieve the best panel efficiency.
- Orientation is controlled thanks to a couple of VL6180X FlightSense light sensors mounted on a X-NUCLEO-6180XA1 expansion board and driven by X-NUCLEO-IHM01A1 controlled stepper motor acting as actuator to orientate the panel.
- The system features a progressive control on the stepper motor in order to modulate the panel rotation speed according to the light angle.
- The application is also able to control the panel productivity reading the panel voltage through an ADC and proving feedback on the local display.
- A manual orientation is possible by using the accelerometer on a X-NUCLEO-IKS01A1 expansion board that, according on board tilt, controls the speed and the rotate direction.
- A remote control is available using a X-NUCLEO-IDB04A1 or a X-NUCLEO-IDB05A1 Bluetooth Low Energy expansion board. Remote control software is here.
Working Status
- SunTracker has 3 working status visible on FlightSense display and switchable by pressing the User Button:
Status 0 (Idle)
- Motor: Free Turning
- Display: Waiting for User Button
Status 1
- Motor: Driven by Light
- Display: Direction and Light Intensity = Direction and Motor Speed
Status 2
- Motor: Driven by Light
- Display: Solar Panel Efficiency
Status 3
- Motor: Driven by Accelerometer
- Display: Direction and Accelerometer Intensity
Server Startup
- When you plug the power supply, the word ‘PUSH’ is shown on display.
- You can manually rotate the structure to assign the ‘Zero Point’. Then press the User Button to launch the application.
- The display will show this status, which means that the structureis oriented to maximize the efficiency of the solar panel.
- If there is a light displacement, the structure will rotate, left or right,to follow the light source and on display is shown the direction and the speed.
- You can press the User Button to show the panel efficiencywith 4 digits that represent the range from 0v (0000) to 3,3v (3300).
- Further pressing the User Button you will manual rotate the panel by tilt the Server or Client accelerometer depending by BLE connection.
Client Startup
- The Client application can remotely control the User Button and the Accelerometer functions.
- Power on the Client AFTER the Server, it will automatically search for the SunTracker and will establish a BLE connection.
- The Green Led on Nucleo Client board will be powered on.
Rotation Features
- It has been implemented a block of rotation to avoid cables twist.
- The blocking point can be set in the firmware by changing a constant.
- You can manually rotate the structure to assign the ‘Zero Point’ before press the User Button to launch the application.
- The system features a progressive control on the stepper motor in order to modulate the rotation speed according to the light or accelerometer angle.
List of Components
SERVER SunTracker_BLE
- Nucleo-F401RE platform using a STM32F401RET6 microcontroller.
- X-NUCLEO-IHM01A1 - Stepper motor driver board based on the EasySPIN L6474.
- X-NUCLEO-6180XA1 - 3-in-1 proximity and ambient light sensor board based on ST FlightSense technology.
- VL6180X-SATEL - Satellite boards compatible with X-NUCLEO-6180XA1 board.
- X-NUCLEO-IKS01A1 - Motion MEMS and environmental sensor board.
- X-NUCLEO-IDB04A1 or X-NUCLEO-IDB05A1 - Bluetooth Low Energy Bluetooth low energy evaluation board.
- Stepper Motor 400’’ (Part Number 5350401) - To orientate the Mechanical Structure.
- Solar Panel 0.446w (Part Number 0194127) - To capture sunlight and generate electrical current.
- Power Supply 12v (Part Number 7262993) - To provide power supply at the Stepper Motor.
- Flat Cable 6 ways (Part Number 1807010) - To plug VL6180X-SATEL with X-NUCLEO-6180XA1 (60cm length each x2).
- Cable Connector (Part Number 6737694) - To plug the Flat Cable (x4).
- Power Connector (Part Number 0487842) - To provide Power Supply to X-NUCLEO-IHM01A1.
CLIENT SunTracker_BLE_Remote
- Nucleo-F401RE platform using a STM32F401RET6 microcontroller.
- X-NUCLEO-IKS01A1 - Motion MEMS and environmental sensor board.
- X-NUCLEO-IDB04A1 or X-NUCLEO-IDB05A1- Bluetooth Low Energy Bluetooth low energy evaluation board.
MECHANICAL STRUCTURE
Find here the STL files to print with a 3D printer.
FLAT CABLE ASSEMBLY
HARDWARE SETUP
Nucleo ADC + Solar Panel
Connect Solar Panel cables to Nucleo Morpho PC_3 (white) and Nucleo Morpho GND (black). Connect a capacitor 10uF between PC_3 and GND to stabilize its voltage value shown on display.
EasySpin (L6474) + BLE
Hardware conflict between EasySpin DIR1 and BLE Reset, both on same Arduino Pin PA_8. Disconnect PA_8 between EasySpin and Nucleo by fold EasySpin Pin. PB_2 has been configured as EasySpin DIR1 in the firmware .Connect Nucleo Morpho PB_2 to FlightSense Arduino PA_8 by a wire.
FlightSense Satellites
In case of instability with I2C due to long flat cables, solder 4 SMD capacitors 47pF on FlightSense board in parallel between R15, R16, R17, R18 and plug 2 capacitors 15pF between FlightSense Arduino PB_8 and PB_9 to GND pin to cut-off noises over 720 KHz.
Arduino & Morpho Pinout
CustomSensorsService.h@17:582eba752042, 2016-04-19 (annotated)
- Committer:
- fabiombed
- Date:
- Tue Apr 19 08:53:07 2016 +0000
- Revision:
- 17:582eba752042
- Parent:
- 15:019b8d60c89d
- Child:
- 18:319a1bb8f837
Updated to BlueST Protocol
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fabiombed | 4:1d3d071a4c2c | 1 | /****************************************************************************** |
fabiombed | 5:76fb6b783487 | 2 | * @file CustomSensorsService.h |
fabiombed | 5:76fb6b783487 | 3 | * @author Fabio Brembilla |
fabiombed | 5:76fb6b783487 | 4 | * @version V1.0.0 |
fabiombed | 17:582eba752042 | 5 | * @date April, 2016 |
fabiombed | 5:76fb6b783487 | 6 | * @brief SunTracker Custom Service for BlueTooth (IDB0XA1 expansion board) |
fabiombed | 5:76fb6b783487 | 7 | ***************************************************************************** |
fabiombed | 5:76fb6b783487 | 8 | * @attention |
fabiombed | 5:76fb6b783487 | 9 | * |
fabiombed | 5:76fb6b783487 | 10 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
fabiombed | 5:76fb6b783487 | 11 | * |
fabiombed | 5:76fb6b783487 | 12 | * Redistribution and use in source and binary forms, with or without modification, |
fabiombed | 5:76fb6b783487 | 13 | * are permitted provided that the following conditions are met: |
fabiombed | 5:76fb6b783487 | 14 | * 1. Redistributions of source code must retain the above copyright notice, |
fabiombed | 5:76fb6b783487 | 15 | * this list of conditions and the following disclaimer. |
fabiombed | 5:76fb6b783487 | 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
fabiombed | 5:76fb6b783487 | 17 | * this list of conditions and the following disclaimer in the documentation |
fabiombed | 5:76fb6b783487 | 18 | * and/or other materials provided with the distribution. |
fabiombed | 5:76fb6b783487 | 19 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
fabiombed | 5:76fb6b783487 | 20 | * may be used to endorse or promote products derived from this software |
fabiombed | 5:76fb6b783487 | 21 | * without specific prior written permission. |
fabiombed | 5:76fb6b783487 | 22 | * |
fabiombed | 5:76fb6b783487 | 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
fabiombed | 5:76fb6b783487 | 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
fabiombed | 5:76fb6b783487 | 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
fabiombed | 5:76fb6b783487 | 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
fabiombed | 5:76fb6b783487 | 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
fabiombed | 5:76fb6b783487 | 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
fabiombed | 5:76fb6b783487 | 29 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
fabiombed | 5:76fb6b783487 | 30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
fabiombed | 5:76fb6b783487 | 31 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
fabiombed | 5:76fb6b783487 | 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
fabiombed | 5:76fb6b783487 | 33 | * |
fabiombed | 5:76fb6b783487 | 34 | ****************************************************************************** |
fabiombed | 5:76fb6b783487 | 35 | */ |
fabiombed | 4:1d3d071a4c2c | 36 | |
fabiombed | 4:1d3d071a4c2c | 37 | #include "BLE.h" |
fabiombed | 5:76fb6b783487 | 38 | #include "UUID.h" |
fabiombed | 4:1d3d071a4c2c | 39 | |
fabiombed | 14:644f9e7278e9 | 40 | /* BLE Services: Primary + 3 Secondary (Char Desk) */ |
fabiombed | 17:582eba752042 | 41 | //const LongUUIDBytes_t SENS_SERVICE_UUID = {0x00,0x00,0x00,0x00,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B}; //Primary |
fabiombed | 17:582eba752042 | 42 | //const LongUUIDBytes_t SENS_DIFFERENCE_CHAR_UUID = {0x00,0x00,0x00,0x01,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B}; //Difference Light/Mems |
fabiombed | 17:582eba752042 | 43 | //const LongUUIDBytes_t SENS_POSITION_CHAR_UUID = {0x00,0x00,0x00,0x02,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B}; //Motor Position |
fabiombed | 17:582eba752042 | 44 | //const LongUUIDBytes_t SENS_SUNPANEL_CHAR_UUID = {0x00,0x00,0x00,0x03,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B}; //SunPanel Voltage |
fabiombed | 17:582eba752042 | 45 | //const ShortUUIDBytes_t SENS_SERVICE_UUID = 0xB000; //Primary |
fabiombed | 17:582eba752042 | 46 | //const ShortUUIDBytes_t SENS_STATUS_CHAR_UUID = 0xB001; //Status |
fabiombed | 17:582eba752042 | 47 | //const ShortUUIDBytes_t SENS_DIFFERENCE_CHAR_UUID = 0xB002; //Difference Light/Mems Sensors |
fabiombed | 17:582eba752042 | 48 | //const ShortUUIDBytes_t SENS_POSITION_CHAR_UUID = 0xB003; //Motor Position |
fabiombed | 17:582eba752042 | 49 | //const ShortUUIDBytes_t SENS_SUNPANEL_CHAR_UUID = 0xB004; //SunPanel Voltage |
fabiombed | 17:582eba752042 | 50 | |
fabiombed | 17:582eba752042 | 51 | /* BLE Services: Primary + 4 Secondary (Char Desk) */ |
fabiombed | 17:582eba752042 | 52 | const UUID::LongUUIDBytes_t SENS_SERVICE_UUID = {0x00,0x00,0x00,0x00,0x00,0x01,0x11,0xe1,0x9a,0xb4,0x00,0x02,0xa5,0xd5,0xc5,0x1b}; //Primary |
fabiombed | 17:582eba752042 | 53 | const UUID::LongUUIDBytes_t SENS_STATUS_CHAR_UUID = {0x00,0x00,0x04,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b}; //Status 0x00000400 |
fabiombed | 17:582eba752042 | 54 | const UUID::LongUUIDBytes_t SENS_DIFFERENCE_CHAR_UUID = {0x00,0x00,0x08,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b}; //Difference Light/Mems 0x00000800 |
fabiombed | 17:582eba752042 | 55 | const UUID::LongUUIDBytes_t SENS_POSITION_CHAR_UUID = {0x00,0x00,0x10,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b}; //Motor Position 0x00001000 |
fabiombed | 17:582eba752042 | 56 | const UUID::LongUUIDBytes_t SENS_SUNPANEL_CHAR_UUID = {0x00,0x00,0x20,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b}; //SunPanel Voltage 0x00002000 |
fabiombed | 17:582eba752042 | 57 | |
fabiombed | 17:582eba752042 | 58 | //#define DIFFERENCE_DATA_LEN 2 |
fabiombed | 17:582eba752042 | 59 | //#define POSITION_DATA_LEN 2 |
fabiombed | 17:582eba752042 | 60 | //#define SUNPANEL_DATA_LEN 2 |
fabiombed | 15:019b8d60c89d | 61 | // 1 byte 0xFF 8 bit int8 |
fabiombed | 15:019b8d60c89d | 62 | // 2 byte 0xFFFF 16 bit int16 |
fabiombed | 4:1d3d071a4c2c | 63 | |
fabiombed | 17:582eba752042 | 64 | #define STATUS_DATA_LEN 2+2 // TimeStamp + Status |
fabiombed | 17:582eba752042 | 65 | #define DIFFERENCE_DATA_LEN 2+2 // TimeStamp + Difference |
fabiombed | 17:582eba752042 | 66 | #define POSITION_DATA_LEN 2+2 // TimeStamp + Position |
fabiombed | 17:582eba752042 | 67 | #define SUNPANEL_DATA_LEN 2+2 // TimeStamp + SunPanel |
fabiombed | 17:582eba752042 | 68 | |
fabiombed | 4:1d3d071a4c2c | 69 | /* Custom Sensors Service */ |
fabiombed | 4:1d3d071a4c2c | 70 | class CustomSensorService { |
fabiombed | 4:1d3d071a4c2c | 71 | public: |
fabiombed | 4:1d3d071a4c2c | 72 | CustomSensorService(BLEDevice &_ble) : |
fabiombed | 4:1d3d071a4c2c | 73 | ble(_ble), |
fabiombed | 17:582eba752042 | 74 | statusCharacteristic(SENS_STATUS_CHAR_UUID, envStatus, STATUS_DATA_LEN, STATUS_DATA_LEN, |
fabiombed | 17:582eba752042 | 75 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
fabiombed | 17:582eba752042 | 76 | differenceCharacteristic(SENS_DIFFERENCE_CHAR_UUID, envDifference, DIFFERENCE_DATA_LEN, DIFFERENCE_DATA_LEN, |
fabiombed | 17:582eba752042 | 77 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
fabiombed | 17:582eba752042 | 78 | positionCharacteristic(SENS_POSITION_CHAR_UUID, envPosition, POSITION_DATA_LEN, POSITION_DATA_LEN, |
fabiombed | 17:582eba752042 | 79 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
fabiombed | 17:582eba752042 | 80 | sunpanelCharacteristic(SENS_SUNPANEL_CHAR_UUID, envSunpanel, SUNPANEL_DATA_LEN, SUNPANEL_DATA_LEN, |
fabiombed | 7:54984d031243 | 81 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) |
fabiombed | 5:76fb6b783487 | 82 | { |
fabiombed | 5:76fb6b783487 | 83 | static bool serviceAdded = false; // To be sure to define just one time |
fabiombed | 4:1d3d071a4c2c | 84 | if (serviceAdded) { |
fabiombed | 4:1d3d071a4c2c | 85 | return; |
fabiombed | 4:1d3d071a4c2c | 86 | } |
fabiombed | 4:1d3d071a4c2c | 87 | |
fabiombed | 17:582eba752042 | 88 | GattCharacteristic *charTable[] = {&statusCharacteristic, &differenceCharacteristic, &positionCharacteristic, &sunpanelCharacteristic}; |
fabiombed | 17:582eba752042 | 89 | GattService envService(SENS_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
fabiombed | 4:1d3d071a4c2c | 90 | ble.gattServer().addService(envService); |
fabiombed | 4:1d3d071a4c2c | 91 | |
fabiombed | 17:582eba752042 | 92 | isEnabledStatusNotify = false; |
fabiombed | 14:644f9e7278e9 | 93 | isEnabledDifferenceNotify = false; |
fabiombed | 5:76fb6b783487 | 94 | isEnabledPositionNotify = false; |
fabiombed | 17:582eba752042 | 95 | isEnabledSunpanelNotify = false; |
fabiombed | 17:582eba752042 | 96 | memset (envStatus, 0, STATUS_DATA_LEN); |
fabiombed | 14:644f9e7278e9 | 97 | memset (envDifference, 0, DIFFERENCE_DATA_LEN); |
fabiombed | 14:644f9e7278e9 | 98 | memset (envPosition, 0, POSITION_DATA_LEN); |
fabiombed | 14:644f9e7278e9 | 99 | memset (envSunpanel, 0, SUNPANEL_DATA_LEN); |
fabiombed | 4:1d3d071a4c2c | 100 | isBTLEConnected = DISCONNECTED; |
fabiombed | 4:1d3d071a4c2c | 101 | serviceAdded = true; |
fabiombed | 4:1d3d071a4c2c | 102 | } |
fabiombed | 4:1d3d071a4c2c | 103 | |
fabiombed | 5:76fb6b783487 | 104 | // Tests Method |
fabiombed | 7:54984d031243 | 105 | |
fabiombed | 17:582eba752042 | 106 | void sendEnvStatus (uint16_t Sta, uint16_t TimeStamp) { |
fabiombed | 17:582eba752042 | 107 | STORE_LE_16(envStatus,TimeStamp); |
fabiombed | 17:582eba752042 | 108 | STORE_LE_16(envStatus+2,Sta); |
fabiombed | 17:582eba752042 | 109 | PRINTF("sendEnvStatus handle: %d\n\r", statusCharacteristic.getValueAttribute().getHandle()); |
fabiombed | 17:582eba752042 | 110 | memcpy (pastenvStatus, envStatus, STATUS_DATA_LEN); |
fabiombed | 17:582eba752042 | 111 | ble.gattServer().write(statusCharacteristic.getValueAttribute().getHandle(), envStatus, STATUS_DATA_LEN, 0); |
fabiombed | 17:582eba752042 | 112 | printf(" (Update)"); |
fabiombed | 17:582eba752042 | 113 | } |
fabiombed | 17:582eba752042 | 114 | |
fabiombed | 17:582eba752042 | 115 | void updateEnvStatus (uint16_t Sta, uint16_t TimeStamp) { |
fabiombed | 17:582eba752042 | 116 | if (ble.getGapState().connected && isEnabledStatusNotify ) { |
fabiombed | 17:582eba752042 | 117 | if (memcmp (&pastenvStatus[2], &Sta, STATUS_DATA_LEN) != 0) { |
fabiombed | 17:582eba752042 | 118 | sendEnvStatus (Sta, TimeStamp); |
fabiombed | 17:582eba752042 | 119 | } |
fabiombed | 17:582eba752042 | 120 | } |
fabiombed | 17:582eba752042 | 121 | } |
fabiombed | 17:582eba752042 | 122 | |
fabiombed | 17:582eba752042 | 123 | //-- |
fabiombed | 17:582eba752042 | 124 | |
fabiombed | 17:582eba752042 | 125 | void sendEnvDifference (uint16_t Dif, uint16_t TimeStamp) { |
fabiombed | 17:582eba752042 | 126 | STORE_LE_16(envDifference,TimeStamp); |
fabiombed | 17:582eba752042 | 127 | STORE_LE_16(envDifference+2,Dif); |
fabiombed | 17:582eba752042 | 128 | PRINTF("sendEnvDifference handle: %d\n\r", differenceCharacteristic.getValueAttribute().getHandle()); |
fabiombed | 14:644f9e7278e9 | 129 | memcpy (pastenvDifference, envDifference, DIFFERENCE_DATA_LEN); |
fabiombed | 14:644f9e7278e9 | 130 | ble.gattServer().write(differenceCharacteristic.getValueAttribute().getHandle(), envDifference, DIFFERENCE_DATA_LEN, 0); |
fabiombed | 14:644f9e7278e9 | 131 | printf(" (Update)"); |
fabiombed | 14:644f9e7278e9 | 132 | } |
fabiombed | 14:644f9e7278e9 | 133 | |
fabiombed | 17:582eba752042 | 134 | void updateEnvDifference (uint16_t Dif, uint16_t TimeStamp) { |
fabiombed | 15:019b8d60c89d | 135 | if (ble.getGapState().connected && isEnabledDifferenceNotify ) { |
fabiombed | 17:582eba752042 | 136 | if (memcmp (&pastenvDifference[2], &Dif, DIFFERENCE_DATA_LEN) != 0) { |
fabiombed | 17:582eba752042 | 137 | sendEnvDifference (Dif, TimeStamp); |
fabiombed | 15:019b8d60c89d | 138 | } |
fabiombed | 14:644f9e7278e9 | 139 | } |
fabiombed | 14:644f9e7278e9 | 140 | } |
fabiombed | 14:644f9e7278e9 | 141 | |
fabiombed | 17:582eba752042 | 142 | //-- |
fabiombed | 17:582eba752042 | 143 | |
fabiombed | 17:582eba752042 | 144 | void sendEnvPosition (uint16_t Pos, uint16_t TimeStamp) { |
fabiombed | 17:582eba752042 | 145 | STORE_LE_16(envPosition,TimeStamp); |
fabiombed | 17:582eba752042 | 146 | STORE_LE_16(envPosition+2,Pos); |
fabiombed | 14:644f9e7278e9 | 147 | PRINTF("sendEnvPosition handle: %d\n\r", positionCharacteristic.getValueAttribute().getHandle()); |
fabiombed | 14:644f9e7278e9 | 148 | memcpy (pastenvPosition, envPosition, POSITION_DATA_LEN); |
fabiombed | 14:644f9e7278e9 | 149 | ble.gattServer().write(positionCharacteristic.getValueAttribute().getHandle(), envPosition, POSITION_DATA_LEN, 0); |
fabiombed | 14:644f9e7278e9 | 150 | printf(" (Update)"); |
fabiombed | 14:644f9e7278e9 | 151 | } |
fabiombed | 14:644f9e7278e9 | 152 | |
fabiombed | 17:582eba752042 | 153 | void updateEnvPosition (uint16_t Pos, uint16_t TimeStamp) { |
fabiombed | 15:019b8d60c89d | 154 | if (ble.getGapState().connected && isEnabledPositionNotify ) { |
fabiombed | 17:582eba752042 | 155 | if (memcmp (&pastenvPosition[2], &Pos, POSITION_DATA_LEN) != 0) { |
fabiombed | 17:582eba752042 | 156 | sendEnvPosition (Pos, TimeStamp); |
fabiombed | 15:019b8d60c89d | 157 | } |
fabiombed | 14:644f9e7278e9 | 158 | } |
fabiombed | 14:644f9e7278e9 | 159 | } |
fabiombed | 14:644f9e7278e9 | 160 | |
fabiombed | 17:582eba752042 | 161 | //-- |
fabiombed | 17:582eba752042 | 162 | |
fabiombed | 17:582eba752042 | 163 | void sendEnvSunpanel (uint16_t Sun, uint16_t TimeStamp) { |
fabiombed | 17:582eba752042 | 164 | STORE_LE_16(envSunpanel,TimeStamp); |
fabiombed | 17:582eba752042 | 165 | STORE_LE_16(envSunpanel+2,Sun); |
fabiombed | 14:644f9e7278e9 | 166 | PRINTF("sendEnvSunpanel handle: %d\n\r", sunpanelCharacteristic.getValueAttribute().getHandle()); |
fabiombed | 14:644f9e7278e9 | 167 | memcpy (pastenvSunpanel, envSunpanel, SUNPANEL_DATA_LEN); |
fabiombed | 14:644f9e7278e9 | 168 | ble.gattServer().write(sunpanelCharacteristic.getValueAttribute().getHandle(), envSunpanel, SUNPANEL_DATA_LEN, 0); |
fabiombed | 14:644f9e7278e9 | 169 | printf(" (Update)"); |
fabiombed | 14:644f9e7278e9 | 170 | } |
fabiombed | 14:644f9e7278e9 | 171 | |
fabiombed | 17:582eba752042 | 172 | void updateEnvSunpanel (uint16_t Sun, uint16_t TimeStamp) { |
fabiombed | 15:019b8d60c89d | 173 | if (ble.getGapState().connected && isEnabledSunpanelNotify ) { |
fabiombed | 17:582eba752042 | 174 | if (memcmp (&pastenvSunpanel[2], &Sun, SUNPANEL_DATA_LEN) != 0) { |
fabiombed | 17:582eba752042 | 175 | sendEnvSunpanel (Sun, TimeStamp); |
fabiombed | 15:019b8d60c89d | 176 | } |
fabiombed | 14:644f9e7278e9 | 177 | } |
fabiombed | 14:644f9e7278e9 | 178 | } |
fabiombed | 14:644f9e7278e9 | 179 | |
fabiombed | 17:582eba752042 | 180 | //---- |
fabiombed | 8:144855fe02bd | 181 | |
fabiombed | 4:1d3d071a4c2c | 182 | void enNotify (Gap::Handle_t handle) { |
fabiombed | 15:019b8d60c89d | 183 | printf("\n\r\n\renNotify (handle %d)", handle); |
fabiombed | 17:582eba752042 | 184 | if (isStatusHandle(handle)) { isEnabledStatusNotify = true; memset(envStatus,0,STATUS_DATA_LEN); return; } |
fabiombed | 14:644f9e7278e9 | 185 | if (isDifferenceHandle(handle)) { isEnabledDifferenceNotify = true; memset(envDifference,0,DIFFERENCE_DATA_LEN); return; } |
fabiombed | 5:76fb6b783487 | 186 | if (isPositionHandle(handle)) { isEnabledPositionNotify = true; memset(envPosition,0,POSITION_DATA_LEN); return; } |
fabiombed | 5:76fb6b783487 | 187 | if (isSunpanelHandle(handle)) { isEnabledSunpanelNotify = true; memset(envSunpanel,0,SUNPANEL_DATA_LEN); return; } |
fabiombed | 4:1d3d071a4c2c | 188 | } |
fabiombed | 4:1d3d071a4c2c | 189 | |
fabiombed | 4:1d3d071a4c2c | 190 | void disNotify (Gap::Handle_t handle) { |
fabiombed | 15:019b8d60c89d | 191 | printf("\n\r\n\rdisNotify (handle %d)", handle); |
fabiombed | 17:582eba752042 | 192 | if (isStatusHandle(handle)) { isEnabledStatusNotify = false; memset(envStatus,0,STATUS_DATA_LEN); return; } |
fabiombed | 14:644f9e7278e9 | 193 | if (isDifferenceHandle(handle)) { isEnabledDifferenceNotify = false; memset(envDifference,0,DIFFERENCE_DATA_LEN); return; } |
fabiombed | 5:76fb6b783487 | 194 | if (isPositionHandle(handle)) { isEnabledPositionNotify = false; memset(envPosition,0,POSITION_DATA_LEN); return; } |
fabiombed | 5:76fb6b783487 | 195 | if (isSunpanelHandle(handle)) { isEnabledSunpanelNotify = false; memset(envSunpanel,0,SUNPANEL_DATA_LEN); return; } |
fabiombed | 4:1d3d071a4c2c | 196 | } |
fabiombed | 17:582eba752042 | 197 | |
fabiombed | 17:582eba752042 | 198 | //---- |
fabiombed | 17:582eba752042 | 199 | |
fabiombed | 17:582eba752042 | 200 | bool isStatusNotificationEn (void) { |
fabiombed | 17:582eba752042 | 201 | return isEnabledStatusNotify; |
fabiombed | 17:582eba752042 | 202 | } |
fabiombed | 4:1d3d071a4c2c | 203 | |
fabiombed | 14:644f9e7278e9 | 204 | bool isDifferenceNotificationEn (void) { |
fabiombed | 14:644f9e7278e9 | 205 | return isEnabledDifferenceNotify; |
fabiombed | 14:644f9e7278e9 | 206 | } |
fabiombed | 14:644f9e7278e9 | 207 | |
fabiombed | 5:76fb6b783487 | 208 | bool isPositionNotificationEn (void) { |
fabiombed | 5:76fb6b783487 | 209 | return isEnabledPositionNotify; |
fabiombed | 4:1d3d071a4c2c | 210 | } |
fabiombed | 4:1d3d071a4c2c | 211 | |
fabiombed | 5:76fb6b783487 | 212 | bool isSunpanelNotificationEn (void) { |
fabiombed | 5:76fb6b783487 | 213 | return isEnabledSunpanelNotify; |
fabiombed | 5:76fb6b783487 | 214 | } |
fabiombed | 17:582eba752042 | 215 | |
fabiombed | 17:582eba752042 | 216 | //---- |
fabiombed | 17:582eba752042 | 217 | |
fabiombed | 17:582eba752042 | 218 | bool isStatusHandle (Gap::Handle_t handle) { |
fabiombed | 17:582eba752042 | 219 | if (handle == statusCharacteristic.getValueAttribute().getHandle()) return true; |
fabiombed | 17:582eba752042 | 220 | return false; |
fabiombed | 17:582eba752042 | 221 | } |
fabiombed | 17:582eba752042 | 222 | |
fabiombed | 14:644f9e7278e9 | 223 | bool isDifferenceHandle (Gap::Handle_t handle) { |
fabiombed | 14:644f9e7278e9 | 224 | if (handle == differenceCharacteristic.getValueAttribute().getHandle()) return true; |
fabiombed | 14:644f9e7278e9 | 225 | return false; |
fabiombed | 14:644f9e7278e9 | 226 | } |
fabiombed | 14:644f9e7278e9 | 227 | |
fabiombed | 5:76fb6b783487 | 228 | bool isPositionHandle (Gap::Handle_t handle) { |
fabiombed | 5:76fb6b783487 | 229 | if (handle == positionCharacteristic.getValueAttribute().getHandle()) return true; |
fabiombed | 4:1d3d071a4c2c | 230 | return false; |
fabiombed | 4:1d3d071a4c2c | 231 | } |
fabiombed | 4:1d3d071a4c2c | 232 | |
fabiombed | 5:76fb6b783487 | 233 | bool isSunpanelHandle (Gap::Handle_t handle) { |
fabiombed | 5:76fb6b783487 | 234 | if (handle == sunpanelCharacteristic.getValueAttribute().getHandle()) return true; |
fabiombed | 4:1d3d071a4c2c | 235 | return false; |
fabiombed | 4:1d3d071a4c2c | 236 | } |
fabiombed | 4:1d3d071a4c2c | 237 | |
fabiombed | 17:582eba752042 | 238 | void updateConnectionStatus(ConnectionStatus_t status) { |
fabiombed | 17:582eba752042 | 239 | isEnabledStatusNotify = false; |
fabiombed | 14:644f9e7278e9 | 240 | isEnabledDifferenceNotify = false; |
fabiombed | 5:76fb6b783487 | 241 | isEnabledPositionNotify = false; |
fabiombed | 17:582eba752042 | 242 | isEnabledSunpanelNotify = false; |
fabiombed | 17:582eba752042 | 243 | memset (envStatus, 0, STATUS_DATA_LEN); |
fabiombed | 14:644f9e7278e9 | 244 | memset (envDifference, 0, DIFFERENCE_DATA_LEN); |
fabiombed | 5:76fb6b783487 | 245 | memset (envPosition, 0, POSITION_DATA_LEN); |
fabiombed | 5:76fb6b783487 | 246 | memset (envSunpanel, 0, SUNPANEL_DATA_LEN); |
fabiombed | 4:1d3d071a4c2c | 247 | isBTLEConnected = status; |
fabiombed | 4:1d3d071a4c2c | 248 | } |
fabiombed | 4:1d3d071a4c2c | 249 | |
fabiombed | 5:76fb6b783487 | 250 | // Variables Initialization |
fabiombed | 4:1d3d071a4c2c | 251 | private: |
fabiombed | 4:1d3d071a4c2c | 252 | |
fabiombed | 4:1d3d071a4c2c | 253 | BLEDevice &ble; |
fabiombed | 17:582eba752042 | 254 | uint8_t envStatus [STATUS_DATA_LEN]; |
fabiombed | 14:644f9e7278e9 | 255 | uint8_t envDifference [DIFFERENCE_DATA_LEN]; |
fabiombed | 5:76fb6b783487 | 256 | uint8_t envPosition [POSITION_DATA_LEN]; |
fabiombed | 17:582eba752042 | 257 | uint8_t envSunpanel [SUNPANEL_DATA_LEN]; |
fabiombed | 17:582eba752042 | 258 | uint8_t pastenvStatus [STATUS_DATA_LEN]; |
fabiombed | 14:644f9e7278e9 | 259 | uint8_t pastenvDifference [POSITION_DATA_LEN]; |
fabiombed | 7:54984d031243 | 260 | uint8_t pastenvPosition [POSITION_DATA_LEN]; |
fabiombed | 7:54984d031243 | 261 | uint8_t pastenvSunpanel [SUNPANEL_DATA_LEN]; |
fabiombed | 7:54984d031243 | 262 | |
fabiombed | 17:582eba752042 | 263 | GattCharacteristic statusCharacteristic; |
fabiombed | 14:644f9e7278e9 | 264 | GattCharacteristic differenceCharacteristic; |
fabiombed | 5:76fb6b783487 | 265 | GattCharacteristic positionCharacteristic; |
fabiombed | 5:76fb6b783487 | 266 | GattCharacteristic sunpanelCharacteristic; |
fabiombed | 14:644f9e7278e9 | 267 | |
fabiombed | 4:1d3d071a4c2c | 268 | ConnectionStatus_t isBTLEConnected; |
fabiombed | 4:1d3d071a4c2c | 269 | |
fabiombed | 17:582eba752042 | 270 | bool isEnabledStatusNotify; |
fabiombed | 14:644f9e7278e9 | 271 | bool isEnabledDifferenceNotify; |
fabiombed | 5:76fb6b783487 | 272 | bool isEnabledPositionNotify; |
fabiombed | 5:76fb6b783487 | 273 | bool isEnabledSunpanelNotify; |
fabiombed | 4:1d3d071a4c2c | 274 | |
fabiombed | 4:1d3d071a4c2c | 275 | }; |