This is a intelligent house system based on stm32f103zet6, integrate mqtt,lvgl into system,can use touchscreen to get data from some sensors and see data in server platform
MIT License
This is a simple intelligent sensor system,which integrate light weight Mqtt server lvgl and so on technologies. Its functions include detecting temperaturehumidity light intensity around the environment(can add more module by yourself),then show the data in touchscreen and you can get the datas by specified platform(here is mqttx server).
keil
vscode
stm32cubemx
Squareline studio
add a function in Gui.h as the lvgl refresh the screen
Find it in F1-Hal-MQTT-LVGL\LVGL\examples\porting\lv_port_disp.c
more message see in F1-Hal-MQTT-LVGL\LVGL\examples\porting\lv_port_indev.c
please follow Weidongshan video to set up
after download mosquitto , running it in windows command screen
cd "c:\Program Files\mosquitto"
.\mosquitto.exe -c mosquitto.conf -v
more message in F1-Hal-MQTT-LVGL\LVGL\APP\UI_demo\ui_events.c
Arc should be the labels father element
Get the data from a global value,then put it into a static buffer by using sprintf,the follow the picture to encode.
In a similar way,control Led is same way,judge two state(checked or unchecked) to run led off or on.
@add : if you want to use printf to debug visually ,it is important to close semi-hosting pattern.
some codes help you close and add it in c document which everywhere.
dont forget redirect the port
(refer to F1-Hal-MQTT-LVGL\SYSTEM\Uart_Redefine.c)
#if 0
#pragma import(__use_no_semihosting) // C
void _sys_exit(int x) // _sys_exit()
{
x = x;
}
struct __FILE //
{
int handle;
};
/* FILE is typedef d in stdio.h. */
FILE __stdout;
#endif
int fputc(int ch, FILE *f)
{
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
return ch;
}
int fgetc(FILE *f)
{
uint8_t ch = 0;
HAL_UART_Receive(&huart1, &ch, 1, HAL_MAX_DELAY);
return ch;
}
When you use the rtos created by hal bank,it is necessary to add heartbeat function in a important place
here is two way:
configUSE_TICK_HOOK need to set 1
but I find the second way easy to aggravate cpu burden
BaseType_t val;
/* */
printf("FreeRTOS: %d \r\n",configTOTAL_HEAP_SIZE);//FreeRTOS
printf(": %d \r\n", xPortGetFreeHeapSize());//
printf(":%d \r\n\r\n",xPortGetMinimumEverFreeHeapSize());//
/* */
val = uxTaskGetStackHighWaterMark(SPITask_Handler);//SPI
printf("SPI:%d \r\n",(int)val*4);
printf("MQTT stack is %d\r\n", (int *)uxTaskGetStackHighWaterMark(G_xQueuePlatform));
/**
* @brief
* @param xus 0~233015
* @retval
*/
void Delay_us(uint32_t xus)
{
SysTick->LOAD = 72 * xus; //
SysTick->VAL = 0x00; //
SysTick->CTRL = 0x00000005; // HCLK
while (!(SysTick->CTRL & 0x00010000))
; //
SysTick->CTRL = 0x00000004; //
}
/**
* @brief
* @param xms 0~4294967295
* @retval
*/
void Delay_ms(uint32_t xms)
{
while (xms--)
{
Delay_us(1000);
}
}
/**
* @brief
* @param xs 0~4294967295
* @retval
*/
void Delay_s(uint32_t xs)
{
while (xs--)
{
Delay_ms(1000);
}
}
It will cause the messy time for rtos get
such as
program stuck in
if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > ( UBaseType_t ) 1 ) { taskYIELD(); }
it will never return the errQUEUE_EMPTY for stopping ,then enter prvildeTask
Using the basedtime and never to interrupt its running
void Delay_us(uint32_t xus)
{
extern TIM_HandleTypeDef TIME_BASE_DELAY;
TIM_HandleTypeDef *hHalTim = &TIME_BASE_DELAY;
uint32_t ticks;
uint32_t told, tnow, tcnt = 0;
uint32_t reload = __HAL_TIM_GET_AUTORELOAD(hHalTim);
ticks = xus * reload / (1000); /* reload1ms */
told = __HAL_TIM_GET_COUNTER(hHalTim);
while (1)
{
tnow = __HAL_TIM_GET_COUNTER(hHalTim);
if (tnow != told)
{
if (tnow > told)
{
tcnt += tnow - told;
}
else
{
tcnt += reload - told + tnow;
}
told = tnow;
if (tcnt >= ticks)
{
break;
}
}
}
}
void Delay_ms(uint32_t xms)
{
for (int i = 0; i < xms; i++)
Delay_us(1000);
}
void Delay_s(uint32_t xs)
{
while (xs--)
{
Delay_ms(1000);
}
}
When you rebuild the project by stm32cubemx,some place need to change,avoiding the errors occur.
set INCLUDE_xTaskGetCurrentTaskHandle 1 in F1-Hal-MQTT-LVGL\Core\Inc\FreeRTOSConfig.h
avoid redefine about Systick_Handler
#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 0
USART3_IRQHandler need to be commented when use yourself interrupt
put it in F1-Hal-MQTT-LVGL\Core\Inc\FreeRTOSConfig.h
#ifndef CMSIS device_ header
#define CMSIS device header "stm32f1xx.h"
#endif