Wireless : Bluetooth Communication

char display[20];
uint8_t rx_char,i;
extern UART_HandleTypeDef huart1;
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
  if(huart->Instance==USART1 )
  {
    if(rx_char=='\r' || rx_char=='\n')
    i=0;
    else
    display[i++]=rx_char;
    HAL_UART_Receive_IT(&huart1,&rx_char,1);
  }
}
if(strstr(display,"load1"))
    {
      HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_0);
      if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0))
      OLCD_write_string(5,1,"LD1 ON ");
      else OLCD_write_string(5,1,"LD1 OFF");
    }
if(strstr(display,"load2"))
    {
      HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_1);
      if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_1))
      OLCD_write_string(5,9,"LD2 ON ");
      else OLCD_write_string(5,9,"LD2 OFF");
    }
uint8_t b_fan,duty=50;
char fan_display[16];
if(strstr(display,"fan"))
    {
      b_fan=b_fan^0x01;
      if(b_fan)
      {
        HAL_TIM_PWM_Start(&htim15,TIM_CHANNEL_1);
        sprintf(fan_display,"FAN Sp:%i    ",duty);
        OLCD_write_string(6,1,fan_display);
      }else{
        HAL_TIM_PWM_Stop(&htim15,TIM_CHANNEL_1);
        OLCD_write_string(6,1,"FAN OFF        ");
      }
    }
if(strstr(display,"increment"))
    {
      if(b_fan)
      {
       speed++;
       if(speed>=5)speed=4;
       switch(speed)
       {
       case 0: TIM15->CCR1=4999; //for 25% duty cycle
       OLCD_write_string(6,1,"FAN ON SP:25% ");
       duty=25;
       break;
       case 1: TIM15->CCR1=9999; //for 50% duty cycle
       OLCD_write_string(6,1,"FAN ON SP:50% ");
       duty=50;
       break;
       case 2: TIM15->CCR1=14999;//for 75% duty cycle
       OLCD_write_string(6,1,"FAN ON SP:75% ");
       duty=75;
       break;
       case 3: TIM15->CCR1=17999;//for 90% duty cycle
       OLCD_write_string(6,1,"FAN ON SP:90%  ");
       duty=90;
       break;
	   case 4: TIM15->CCR1=19998;//for 100% duty cycle
       OLCD_write_string(6,1,"FAN ON SP:100%  ");
       duty=100;
       break;
       }
      }
    }
if(strstr(display,"decrement"))
    {
      if(b_fan)
      {
       speed--;
       if(speed<=0)speed=0;
       switch(speed)
       {
       case 0: TIM15->CCR1=4999; //for 25% duty cycle
       OLCD_write_string(6,1,"FAN ON SP:25% ");
       duty=25;
       break;
       case 1: TIM15->CCR1=9999; //for 50% duty cycle
       OLCD_write_string(6,1,"FAN ON SP:50% ");
       duty=50;
       break;
       case 2: TIM15->CCR1=14999;//for 75% duty cycle
       OLCD_write_string(6,1,"FAN ON SP:75% ");
       duty=75;
       break;
       case 3: TIM15->CCR1=17999;//for 90% duty cycle
       OLCD_write_string(6,1,"FAN ON SP:90% ");
       duty=90;
       break;
	   case 4: TIM15->CCR1=19998;//for 100% duty cycle
       OLCD_write_string(6,1,"FAN ON SP:100%  ");
       duty=100;
       break;
       }
      }
	}

For setting please see my Youtube video. Here I use OLED for display purpose. In the video part I use RTC timer to ON/OFF any load at any time&date, but I don’t describe it in this article. Since I only describe the basic part I omitted that. Leave the EN & STATE pin unconnected, since the microcontroller just only read the sting from the mobile terminal.