SunTracker_BLE

Dependencies:   BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 X_NUCLEO_IHM01A1 X_NUCLEO_IKS01A1 mbed

Fork of SunTracker_BLE by ST Expansion SW Team

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.

/media/uploads/fabiombed/suntracker_server-client.png

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 structure is 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 efficiency with 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

  • 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

MECHANICAL STRUCTURE

Find here the STL files to print with a 3D printer.

/media/uploads/fabiombed/assembly.png

/media/uploads/fabiombed/mechanical_structure_and_motor_legs.png

FLAT CABLE ASSEMBLY

/media/uploads/fabiombed/flat_cable.png

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

/media/uploads/fabiombed/arduino_pinout.png /media/uploads/fabiombed/morpho_pinout.png

Committer:
mapellil
Date:
Mon May 23 10:05:08 2016 +0000
Revision:
25:00220cf2e628
Parent:
19:b2c04428ffed
Update link to X_NUCLEO_6180XA1 library (inherits from Component class)

Who changed what in which revision?

UserRevisionLine numberNew 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>&copy; 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 18:319a1bb8f837 53 const UUID::LongUUIDBytes_t SENS_STATUS_CHAR_UUID = {0x00,0x00,0x08,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b}; //Status 0x00000800
fabiombed 18:319a1bb8f837 54 const UUID::LongUUIDBytes_t SENS_DIFFERENCE_CHAR_UUID = {0x00,0x00,0x10,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b}; //Difference Light/Mems 0x00001000
fabiombed 18:319a1bb8f837 55 const UUID::LongUUIDBytes_t SENS_POSITION_CHAR_UUID = {0x00,0x00,0x20,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b}; //Motor Position 0x00002000
fabiombed 18:319a1bb8f837 56 const UUID::LongUUIDBytes_t SENS_SUNPANEL_CHAR_UUID = {0x00,0x00,0x40,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b}; //SunPanel Voltage 0x00004000
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 19:b2c04428ffed 112 #ifdef Debug
fabiombed 19:b2c04428ffed 113 printf(" (Update)");
fabiombed 19:b2c04428ffed 114 #endif
fabiombed 17:582eba752042 115 }
fabiombed 17:582eba752042 116
fabiombed 17:582eba752042 117 void updateEnvStatus (uint16_t Sta, uint16_t TimeStamp) {
fabiombed 17:582eba752042 118 if (ble.getGapState().connected && isEnabledStatusNotify ) {
fabiombed 18:319a1bb8f837 119 if (memcmp (&pastenvStatus[2], &Sta, 2) != 0) {
fabiombed 17:582eba752042 120 sendEnvStatus (Sta, TimeStamp);
fabiombed 17:582eba752042 121 }
fabiombed 17:582eba752042 122 }
fabiombed 17:582eba752042 123 }
fabiombed 17:582eba752042 124
fabiombed 17:582eba752042 125 //--
fabiombed 17:582eba752042 126
fabiombed 17:582eba752042 127 void sendEnvDifference (uint16_t Dif, uint16_t TimeStamp) {
fabiombed 17:582eba752042 128 STORE_LE_16(envDifference,TimeStamp);
fabiombed 17:582eba752042 129 STORE_LE_16(envDifference+2,Dif);
fabiombed 17:582eba752042 130 PRINTF("sendEnvDifference handle: %d\n\r", differenceCharacteristic.getValueAttribute().getHandle());
fabiombed 14:644f9e7278e9 131 memcpy (pastenvDifference, envDifference, DIFFERENCE_DATA_LEN);
fabiombed 14:644f9e7278e9 132 ble.gattServer().write(differenceCharacteristic.getValueAttribute().getHandle(), envDifference, DIFFERENCE_DATA_LEN, 0);
fabiombed 19:b2c04428ffed 133 #ifdef Debug
fabiombed 19:b2c04428ffed 134 printf(" (Update)");
fabiombed 19:b2c04428ffed 135 #endif
fabiombed 14:644f9e7278e9 136 }
fabiombed 14:644f9e7278e9 137
fabiombed 17:582eba752042 138 void updateEnvDifference (uint16_t Dif, uint16_t TimeStamp) {
fabiombed 15:019b8d60c89d 139 if (ble.getGapState().connected && isEnabledDifferenceNotify ) {
fabiombed 18:319a1bb8f837 140 if (memcmp (&pastenvDifference[2], &Dif, 2) != 0) {
fabiombed 17:582eba752042 141 sendEnvDifference (Dif, TimeStamp);
fabiombed 15:019b8d60c89d 142 }
fabiombed 14:644f9e7278e9 143 }
fabiombed 14:644f9e7278e9 144 }
fabiombed 14:644f9e7278e9 145
fabiombed 17:582eba752042 146 //--
fabiombed 17:582eba752042 147
fabiombed 17:582eba752042 148 void sendEnvPosition (uint16_t Pos, uint16_t TimeStamp) {
fabiombed 17:582eba752042 149 STORE_LE_16(envPosition,TimeStamp);
fabiombed 17:582eba752042 150 STORE_LE_16(envPosition+2,Pos);
fabiombed 14:644f9e7278e9 151 PRINTF("sendEnvPosition handle: %d\n\r", positionCharacteristic.getValueAttribute().getHandle());
fabiombed 14:644f9e7278e9 152 memcpy (pastenvPosition, envPosition, POSITION_DATA_LEN);
fabiombed 14:644f9e7278e9 153 ble.gattServer().write(positionCharacteristic.getValueAttribute().getHandle(), envPosition, POSITION_DATA_LEN, 0);
fabiombed 19:b2c04428ffed 154 #ifdef Debug
fabiombed 19:b2c04428ffed 155 printf(" (Update)");
fabiombed 19:b2c04428ffed 156 #endif
fabiombed 14:644f9e7278e9 157 }
fabiombed 14:644f9e7278e9 158
fabiombed 17:582eba752042 159 void updateEnvPosition (uint16_t Pos, uint16_t TimeStamp) {
fabiombed 15:019b8d60c89d 160 if (ble.getGapState().connected && isEnabledPositionNotify ) {
fabiombed 18:319a1bb8f837 161 if (memcmp (&pastenvPosition[2], &Pos, 2) != 0) {
fabiombed 17:582eba752042 162 sendEnvPosition (Pos, TimeStamp);
fabiombed 15:019b8d60c89d 163 }
fabiombed 14:644f9e7278e9 164 }
fabiombed 14:644f9e7278e9 165 }
fabiombed 14:644f9e7278e9 166
fabiombed 17:582eba752042 167 //--
fabiombed 17:582eba752042 168
fabiombed 17:582eba752042 169 void sendEnvSunpanel (uint16_t Sun, uint16_t TimeStamp) {
fabiombed 17:582eba752042 170 STORE_LE_16(envSunpanel,TimeStamp);
fabiombed 17:582eba752042 171 STORE_LE_16(envSunpanel+2,Sun);
fabiombed 14:644f9e7278e9 172 PRINTF("sendEnvSunpanel handle: %d\n\r", sunpanelCharacteristic.getValueAttribute().getHandle());
fabiombed 14:644f9e7278e9 173 memcpy (pastenvSunpanel, envSunpanel, SUNPANEL_DATA_LEN);
fabiombed 14:644f9e7278e9 174 ble.gattServer().write(sunpanelCharacteristic.getValueAttribute().getHandle(), envSunpanel, SUNPANEL_DATA_LEN, 0);
fabiombed 19:b2c04428ffed 175 #ifdef Debug
fabiombed 19:b2c04428ffed 176 printf(" (Update)");
fabiombed 19:b2c04428ffed 177 #endif
fabiombed 14:644f9e7278e9 178 }
fabiombed 14:644f9e7278e9 179
fabiombed 17:582eba752042 180 void updateEnvSunpanel (uint16_t Sun, uint16_t TimeStamp) {
fabiombed 15:019b8d60c89d 181 if (ble.getGapState().connected && isEnabledSunpanelNotify ) {
fabiombed 18:319a1bb8f837 182 if (memcmp (&pastenvSunpanel[2], &Sun, 2) != 0) {
fabiombed 17:582eba752042 183 sendEnvSunpanel (Sun, TimeStamp);
fabiombed 15:019b8d60c89d 184 }
fabiombed 14:644f9e7278e9 185 }
fabiombed 14:644f9e7278e9 186 }
fabiombed 14:644f9e7278e9 187
fabiombed 17:582eba752042 188 //----
fabiombed 8:144855fe02bd 189
fabiombed 4:1d3d071a4c2c 190 void enNotify (Gap::Handle_t handle) {
fabiombed 15:019b8d60c89d 191 printf("\n\r\n\renNotify (handle %d)", handle);
fabiombed 17:582eba752042 192 if (isStatusHandle(handle)) { isEnabledStatusNotify = true; memset(envStatus,0,STATUS_DATA_LEN); return; }
fabiombed 14:644f9e7278e9 193 if (isDifferenceHandle(handle)) { isEnabledDifferenceNotify = true; memset(envDifference,0,DIFFERENCE_DATA_LEN); return; }
fabiombed 5:76fb6b783487 194 if (isPositionHandle(handle)) { isEnabledPositionNotify = true; memset(envPosition,0,POSITION_DATA_LEN); return; }
fabiombed 5:76fb6b783487 195 if (isSunpanelHandle(handle)) { isEnabledSunpanelNotify = true; memset(envSunpanel,0,SUNPANEL_DATA_LEN); return; }
fabiombed 4:1d3d071a4c2c 196 }
fabiombed 4:1d3d071a4c2c 197
fabiombed 4:1d3d071a4c2c 198 void disNotify (Gap::Handle_t handle) {
fabiombed 15:019b8d60c89d 199 printf("\n\r\n\rdisNotify (handle %d)", handle);
fabiombed 17:582eba752042 200 if (isStatusHandle(handle)) { isEnabledStatusNotify = false; memset(envStatus,0,STATUS_DATA_LEN); return; }
fabiombed 14:644f9e7278e9 201 if (isDifferenceHandle(handle)) { isEnabledDifferenceNotify = false; memset(envDifference,0,DIFFERENCE_DATA_LEN); return; }
fabiombed 5:76fb6b783487 202 if (isPositionHandle(handle)) { isEnabledPositionNotify = false; memset(envPosition,0,POSITION_DATA_LEN); return; }
fabiombed 5:76fb6b783487 203 if (isSunpanelHandle(handle)) { isEnabledSunpanelNotify = false; memset(envSunpanel,0,SUNPANEL_DATA_LEN); return; }
fabiombed 4:1d3d071a4c2c 204 }
fabiombed 17:582eba752042 205
fabiombed 17:582eba752042 206 //----
fabiombed 17:582eba752042 207
fabiombed 17:582eba752042 208 bool isStatusNotificationEn (void) {
fabiombed 17:582eba752042 209 return isEnabledStatusNotify;
fabiombed 17:582eba752042 210 }
fabiombed 4:1d3d071a4c2c 211
fabiombed 14:644f9e7278e9 212 bool isDifferenceNotificationEn (void) {
fabiombed 14:644f9e7278e9 213 return isEnabledDifferenceNotify;
fabiombed 14:644f9e7278e9 214 }
fabiombed 14:644f9e7278e9 215
fabiombed 5:76fb6b783487 216 bool isPositionNotificationEn (void) {
fabiombed 5:76fb6b783487 217 return isEnabledPositionNotify;
fabiombed 4:1d3d071a4c2c 218 }
fabiombed 4:1d3d071a4c2c 219
fabiombed 5:76fb6b783487 220 bool isSunpanelNotificationEn (void) {
fabiombed 5:76fb6b783487 221 return isEnabledSunpanelNotify;
fabiombed 5:76fb6b783487 222 }
fabiombed 17:582eba752042 223
fabiombed 17:582eba752042 224 //----
fabiombed 17:582eba752042 225
fabiombed 17:582eba752042 226 bool isStatusHandle (Gap::Handle_t handle) {
fabiombed 17:582eba752042 227 if (handle == statusCharacteristic.getValueAttribute().getHandle()) return true;
fabiombed 17:582eba752042 228 return false;
fabiombed 17:582eba752042 229 }
fabiombed 17:582eba752042 230
fabiombed 14:644f9e7278e9 231 bool isDifferenceHandle (Gap::Handle_t handle) {
fabiombed 14:644f9e7278e9 232 if (handle == differenceCharacteristic.getValueAttribute().getHandle()) return true;
fabiombed 14:644f9e7278e9 233 return false;
fabiombed 14:644f9e7278e9 234 }
fabiombed 14:644f9e7278e9 235
fabiombed 5:76fb6b783487 236 bool isPositionHandle (Gap::Handle_t handle) {
fabiombed 5:76fb6b783487 237 if (handle == positionCharacteristic.getValueAttribute().getHandle()) return true;
fabiombed 4:1d3d071a4c2c 238 return false;
fabiombed 4:1d3d071a4c2c 239 }
fabiombed 4:1d3d071a4c2c 240
fabiombed 5:76fb6b783487 241 bool isSunpanelHandle (Gap::Handle_t handle) {
fabiombed 5:76fb6b783487 242 if (handle == sunpanelCharacteristic.getValueAttribute().getHandle()) return true;
fabiombed 4:1d3d071a4c2c 243 return false;
fabiombed 4:1d3d071a4c2c 244 }
fabiombed 4:1d3d071a4c2c 245
fabiombed 17:582eba752042 246 void updateConnectionStatus(ConnectionStatus_t status) {
fabiombed 17:582eba752042 247 isEnabledStatusNotify = false;
fabiombed 14:644f9e7278e9 248 isEnabledDifferenceNotify = false;
fabiombed 5:76fb6b783487 249 isEnabledPositionNotify = false;
fabiombed 17:582eba752042 250 isEnabledSunpanelNotify = false;
fabiombed 17:582eba752042 251 memset (envStatus, 0, STATUS_DATA_LEN);
fabiombed 14:644f9e7278e9 252 memset (envDifference, 0, DIFFERENCE_DATA_LEN);
fabiombed 5:76fb6b783487 253 memset (envPosition, 0, POSITION_DATA_LEN);
fabiombed 5:76fb6b783487 254 memset (envSunpanel, 0, SUNPANEL_DATA_LEN);
fabiombed 4:1d3d071a4c2c 255 isBTLEConnected = status;
fabiombed 4:1d3d071a4c2c 256 }
fabiombed 4:1d3d071a4c2c 257
fabiombed 5:76fb6b783487 258 // Variables Initialization
fabiombed 4:1d3d071a4c2c 259 private:
fabiombed 4:1d3d071a4c2c 260
fabiombed 4:1d3d071a4c2c 261 BLEDevice &ble;
fabiombed 17:582eba752042 262 uint8_t envStatus [STATUS_DATA_LEN];
fabiombed 14:644f9e7278e9 263 uint8_t envDifference [DIFFERENCE_DATA_LEN];
fabiombed 5:76fb6b783487 264 uint8_t envPosition [POSITION_DATA_LEN];
fabiombed 17:582eba752042 265 uint8_t envSunpanel [SUNPANEL_DATA_LEN];
fabiombed 17:582eba752042 266 uint8_t pastenvStatus [STATUS_DATA_LEN];
fabiombed 14:644f9e7278e9 267 uint8_t pastenvDifference [POSITION_DATA_LEN];
fabiombed 7:54984d031243 268 uint8_t pastenvPosition [POSITION_DATA_LEN];
fabiombed 7:54984d031243 269 uint8_t pastenvSunpanel [SUNPANEL_DATA_LEN];
fabiombed 7:54984d031243 270
fabiombed 17:582eba752042 271 GattCharacteristic statusCharacteristic;
fabiombed 14:644f9e7278e9 272 GattCharacteristic differenceCharacteristic;
fabiombed 5:76fb6b783487 273 GattCharacteristic positionCharacteristic;
fabiombed 5:76fb6b783487 274 GattCharacteristic sunpanelCharacteristic;
fabiombed 14:644f9e7278e9 275
fabiombed 4:1d3d071a4c2c 276 ConnectionStatus_t isBTLEConnected;
fabiombed 4:1d3d071a4c2c 277
fabiombed 17:582eba752042 278 bool isEnabledStatusNotify;
fabiombed 14:644f9e7278e9 279 bool isEnabledDifferenceNotify;
fabiombed 5:76fb6b783487 280 bool isEnabledPositionNotify;
fabiombed 5:76fb6b783487 281 bool isEnabledSunpanelNotify;
fabiombed 4:1d3d071a4c2c 282
fabiombed 4:1d3d071a4c2c 283 };