/** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * This notice applies to any and all portions of this file * that are not between comment pairs USER CODE BEGIN and * USER CODE END. Other portions of this file, whether * inserted by the user or by software development tools * are owned by their respective copyright owners. * * Copyright (c) 2018 STMicroelectronics International N.V. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted, provided that the following conditions are met: * * 1. Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of other * contributors to this software may be used to endorse or promote products * derived from this software without specific written permission. * 4. This software, including modifications and/or derivative works of this * software, must execute solely and exclusively on microcontroller or * microprocessor devices manufactured by or for STMicroelectronics. * 5. Redistribution and use of this software other than as permitted under * this license is void and will automatically terminate your rights under * this license. * * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stm32f7xx_hal.h" #include "cmsis_os.h" #include "lwip.h" /* USER CODE BEGIN Includes */ #include #include #include "stm32746g_discovery_lcd.h" #include "Utilities/Fonts/fonts.h" #include "stm32746g_discovery_ts.h" #include "term_io.h" #include "dbgu.h" #include "ansi.h" #include "FreeRTOS.h" #include "task.h" #include "queue.h" #include "lwip/opt.h" #include "lwip/api.h" #include "lwip/apps/fs.h" #include "lwip/dhcp.h" #include "lwip/tcpip.h" #include "lwip/netdb.h" #include "lwip/sockets.h" #include "lwip.h" #include "wm8994/wm8994.h" // #include "lwip/apps/mqtt.h" /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ ADC_HandleTypeDef hadc3; CRC_HandleTypeDef hcrc; DCMI_HandleTypeDef hdcmi; DMA2D_HandleTypeDef hdma2d; I2C_HandleTypeDef hi2c1; I2C_HandleTypeDef hi2c3; LTDC_HandleTypeDef hltdc; QSPI_HandleTypeDef hqspi; RTC_HandleTypeDef hrtc; SAI_HandleTypeDef hsai_BlockA2; SAI_HandleTypeDef hsai_BlockB2; SD_HandleTypeDef hsd1; SPDIFRX_HandleTypeDef hspdif; SPI_HandleTypeDef hspi2; TIM_HandleTypeDef htim1; TIM_HandleTypeDef htim2; TIM_HandleTypeDef htim3; TIM_HandleTypeDef htim5; TIM_HandleTypeDef htim7; TIM_HandleTypeDef htim8; TIM_HandleTypeDef htim12; UART_HandleTypeDef huart1; UART_HandleTypeDef huart6; SDRAM_HandleTypeDef hsdram1; osThreadId defaultTaskHandle; /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_I2C1_Init(void); static void MX_USART1_UART_Init(void); static void MX_USART6_UART_Init(void); void StartDefaultTask(void const * argument); void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); /* USER CODE BEGIN PFP */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE END PFP */ /* USER CODE BEGIN 0 */ void mainTask(void* p); osThreadId netconn_thread_handle; #define LCD_X_SIZE RK043FN48H_WIDTH #define LCD_Y_SIZE RK043FN48H_HEIGHT #define PRINTF_USES_HAL_TX 0 int __io_putchar(int ch) { uint8_t data = ch; #if PRINTF_USES_HAL_TX HAL_StatusTypeDef status = HAL_UART_Transmit(&huart1, (uint8_t*)&data, len, 100); #else while(__HAL_UART_GET_FLAG(&huart1, UART_FLAG_TXE) == RESET) { ; } huart1.Instance->TDR = (uint16_t)data; #endif return 0; } char inkey(void) { uint32_t flags = huart1.Instance->ISR; if((flags & UART_FLAG_RXNE) || (flags & UART_FLAG_ORE)) { __HAL_UART_CLEAR_OREFLAG(&huart1); return (huart1.Instance->RDR); } else return 0; } //partially based on available code examples static void lcd_start(void) { /* LCD Initialization */ BSP_LCD_Init(); /* LCD Initialization */ BSP_LCD_LayerDefaultInit(0, (unsigned int)0xC0000000); //BSP_LCD_LayerDefaultInit(1, (unsigned int)lcd_image_bg+(LCD_X_SIZE*LCD_Y_SIZE*4)); BSP_LCD_LayerDefaultInit(1, (unsigned int)0xC0000000+(LCD_X_SIZE*LCD_Y_SIZE*4)); /* Enable the LCD */ BSP_LCD_DisplayOn(); /* Select the LCD Background Layer */ BSP_LCD_SelectLayer(0); /* Clear the Background Layer */ BSP_LCD_Clear(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetColorKeying(1,LCD_COLOR_WHITE); /* Select the LCD Foreground Layer */ BSP_LCD_SelectLayer(1); /* Clear the Foreground Layer */ BSP_LCD_Clear(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_WHITE); /* Configure the transparency for foreground and background : Increase the transparency */ BSP_LCD_SetTransparency(0, 255); BSP_LCD_SetTransparency(1, 255); } //[rmv] void draw_button(int xPos, int yPos, int width, int height, uint32_t color, uint8_t* text); void draw_background(void) { /* Select the LCD Background Layer */ BSP_LCD_SelectLayer(0); BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_FillRect(0,0,LCD_X_SIZE,LCD_Y_SIZE); //select Foreground Layer BSP_LCD_SelectLayer(1); char greeting[] = "Hello"; draw_button(50,50,100,100,LCD_COLOR_MAGENTA,&greeting); } void draw_button(int xPos, int yPos, int width, int height, uint32_t color, uint8_t* text){ BSP_LCD_SelectLayer(0); BSP_LCD_SetTextColor(color); BSP_LCD_FillRect(xPos,yPos,width,height); BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE); BSP_LCD_DisplayStringAt(xPos+5, yPos+5, text, 0); } void draw_chart(float* data){ int chart_height = 220; int chart_length = 450; int chart_y_pos = 20; int chart_x_pos = 20; //drawing coordinates system BSP_LCD_SelectLayer(0); BSP_LCD_Clear(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_DrawHLine(chart_x_pos,chart_y_pos,chart_length); BSP_LCD_DrawVLine(chart_x_pos,chart_y_pos,chart_height); // BSP_LCD_FillTriangle(chart_length-10,chart_length-10,chart_length,chart_y_pos+5,chart_y_pos-5,chart_y_pos); int n = 30; //sizeof(data)/sizeof(data[0]); float max = data[0]; float min = 0;//data[0]; for(int i=1; i max) max = data[i]; } int min_i = 0;//min; int max_i = max; float coordinates_scale = chart_height/(max_i - min_i); float amplitude = max - min; // ? float scale = chart_height/amplitude; // ? // draw scale int y = chart_y_pos; BSP_LCD_SetTextColor(LCD_COLOR_LIGHTGRAY); for(int i=1;i USB_OTG_HS_ULPI_D7 PH4 ------> USB_OTG_HS_ULPI_NXT PB13 ------> USB_OTG_HS_ULPI_D6 PB12 ------> USB_OTG_HS_ULPI_D5 PC0 ------> USB_OTG_HS_ULPI_STP PC2 ------> USB_OTG_HS_ULPI_DIR PA5 ------> USB_OTG_HS_ULPI_CK PB10 ------> USB_OTG_HS_ULPI_D3 PA3 ------> USB_OTG_HS_ULPI_D0 PB1 ------> USB_OTG_HS_ULPI_D2 PB0 ------> USB_OTG_HS_ULPI_D1 PB11 ------> USB_OTG_HS_ULPI_D4 */ static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOE_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOJ_CLK_ENABLE(); __HAL_RCC_GPIOI_CLK_ENABLE(); __HAL_RCC_GPIOK_CLK_ENABLE(); __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE(); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_SET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOI, ARDUINO_D7_Pin|ARDUINO_D8_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_Port, LCD_BL_CTRL_Pin, GPIO_PIN_SET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(LCD_DISP_GPIO_Port, LCD_DISP_Pin, GPIO_PIN_SET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(DCMI_PWR_EN_GPIO_Port, DCMI_PWR_EN_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOG, ARDUINO_D4_Pin|ARDUINO_D2_Pin|EXT_RST_Pin, GPIO_PIN_RESET); /*Configure GPIO pin : OTG_HS_OverCurrent_Pin */ GPIO_InitStruct.Pin = OTG_HS_OverCurrent_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(OTG_HS_OverCurrent_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pins : ULPI_D7_Pin ULPI_D6_Pin ULPI_D5_Pin ULPI_D3_Pin ULPI_D2_Pin ULPI_D1_Pin ULPI_D4_Pin */ GPIO_InitStruct.Pin = ULPI_D7_Pin|ULPI_D6_Pin|ULPI_D5_Pin|ULPI_D3_Pin |ULPI_D2_Pin|ULPI_D1_Pin|ULPI_D4_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /*Configure GPIO pin : OTG_FS_VBUS_Pin */ GPIO_InitStruct.Pin = OTG_FS_VBUS_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(OTG_FS_VBUS_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pin : Audio_INT_Pin */ /*Configure GPIO pin : OTG_FS_PowerSwitchOn_Pin */ GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(OTG_FS_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pins : ARDUINO_D7_Pin ARDUINO_D8_Pin LCD_DISP_Pin */ GPIO_InitStruct.Pin = ARDUINO_D7_Pin|ARDUINO_D8_Pin|LCD_DISP_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOI, &GPIO_InitStruct); /*Configure GPIO pin : uSD_Detect_Pin */ GPIO_InitStruct.Pin = uSD_Detect_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(uSD_Detect_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pin : LCD_BL_CTRL_Pin */ GPIO_InitStruct.Pin = LCD_BL_CTRL_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(LCD_BL_CTRL_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pin : OTG_FS_OverCurrent_Pin */ GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pins : TP3_Pin NC2_Pin */ GPIO_InitStruct.Pin = TP3_Pin|NC2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); /*Configure GPIO pin : DCMI_PWR_EN_Pin */ GPIO_InitStruct.Pin = DCMI_PWR_EN_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(DCMI_PWR_EN_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pin : LCD_INT_Pin */ GPIO_InitStruct.Pin = LCD_INT_Pin; GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(LCD_INT_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pin : ULPI_NXT_Pin */ GPIO_InitStruct.Pin = ULPI_NXT_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; HAL_GPIO_Init(ULPI_NXT_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pins : ARDUINO_D4_Pin ARDUINO_D2_Pin EXT_RST_Pin */ GPIO_InitStruct.Pin = ARDUINO_D4_Pin|ARDUINO_D2_Pin|EXT_RST_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); /*Configure GPIO pins : ULPI_STP_Pin ULPI_DIR_Pin */ GPIO_InitStruct.Pin = ULPI_STP_Pin|ULPI_DIR_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /*Configure GPIO pin : RMII_RXER_Pin */ GPIO_InitStruct.Pin = RMII_RXER_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(RMII_RXER_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pins : ULPI_CLK_Pin ULPI_D0_Pin */ GPIO_InitStruct.Pin = ULPI_CLK_Pin|ULPI_D0_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); } /* USER CODE END 4 */ /* USER CODE BEGIN Header_StartDefaultTask */ /** * @brief Function implementing the defaultTask thread. * @param argument: Not used * @retval None */ /* USER CODE END Header_StartDefaultTask */ static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status); static void mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len); static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t flags); static void mqtt_sub_request_cb(void *arg, err_t result); static void mqtt_pub_request_cb(void *arg, err_t result); int example_do_connect(mqtt_client_t *client) { struct mqtt_connect_client_info_t ci; err_t err; /* Setup an empty client info structure */ memset(&ci, 0, sizeof(ci)); /* Minimal amount of information required is client identifier, so set it here */ ci.client_id = "lwip_test"; /* Initiate client and connect to server, if this fails immediately an error code is returned otherwise mqtt_connection_cb will be called with connection result after attempting to establish a connection with the server. For now MQTT version 3.1.1 is always used */ ip_addr_t ip_addr; if(1 == ipaddr_aton( "192.168.0.101",&ip_addr)){ printf("Created ip"); } err = mqtt_client_connect(client, &ip_addr, 1883, mqtt_connection_cb, 0, &ci); /* For now just print the result code if something goes wrong */ if(err != ERR_OK) { printf("mqtt_connect return tutaj %d\n", err); return 1; } else{ printf("mqtt_connectbvgfdbgfdgfd\n"); return 0; } } static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status) { err_t err; err_t err2; if(status == MQTT_CONNECT_ACCEPTED) { printf("mqtt_connection_cb: Successfully connected\n"); /* Setup callback for incoming publish requests */ mqtt_set_inpub_callback(client, mqtt_incoming_publish_cb, mqtt_incoming_data_cb, arg); /* Subscribe to a topic named "subtopic" with QoS level 1, call mqtt_sub_request_cb with result */ err = mqtt_subscribe(client, "esp/temperature/client2", 1, mqtt_sub_request_cb, arg); err2 = mqtt_subscribe(client, "esp/temperature/client1", 1, mqtt_sub_request_cb, arg); if(err != ERR_OK || err2 != ERR_OK) { printf("mqtt_subscribe return: %d\n", err); } } else { printf("mqtt_connection_cb: Disconnected, reason: %d\n", status); /* Its more nice to be connected, so try to reconnect */ example_do_connect(client); } } static void mqtt_sub_request_cb(void *arg, err_t result) { /* Just print the result code here for simplicity, normal behaviour would be to take some action if subscribe fails like notifying user, retry subscribe or disconnect from server */ printf("Subscribe result: %d\n", result); if(result == ERR_OK){ printf("Subscribe result is OK!\n"); } } //----------------------------------------------------------------- //3. Implementing callbacks for incoming publish and data /* The idea is to demultiplex topic and create some reference to be used in data callbacks Example here uses a global variable, better would be to use a member in arg If RAM and CPU budget allows it, the easiest implementation might be to just take a copy of the topic string and use it in mqtt_incoming_data_cb */ static int inpub_id; static void mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len) // callback invoked when publish starts, contain topic and total length of payload { printf("Incoming publish at topic %s with total length %u\n", topic, (unsigned int)tot_len); /* Decode topic string into a user defined reference */ if(strcmp(topic, "print_payload") == 0) { inpub_id = 0; } else if(topic[0] == 'A') { /* All topics starting with 'A' might be handled at the same way */ inpub_id = 1; } else if(strcmp(topic,"esp/temperature/client1") == 0){ inpub_id = 2; } else { /* For all other topics */ inpub_id = 3; } } static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t flags) // callback for each fragment of payload that arrives { printf("Incoming publish payload with length %d, flags %u\n", len, (unsigned int)flags); if(flags & MQTT_DATA_FLAG_LAST) { /* Last fragment of payload received (or whole part if payload fits receive buffer See MQTT_VAR_HEADER_BUFFER_LEN) */ /* Call function or do action depending on reference, in this case inpub_id */ if(inpub_id == 0) { /* Don't trust the publisher, check zero termination */ if(data[len-1] == 0) { printf("mqtt_incoming_data_cb: %s\n", (const char *)data); } } else if(inpub_id == 1) { /* Call an 'A' function... */ xprintf("Call an A function ...\n"); } else if(inpub_id == 2){ print_data((const char *)data, 1,len); } else { //printf("mqtt_incoming_data_cb: Ignoring payload...\n"); printf("mqtt_incoming_data_cb: %s\n", (const char *)data); print_data((const char *)data,2,len); } } else { /* Handle fragmented payload, store in buffer, write to file or whatever */ } //data = NULL; } //----------------------------------------------------------------- //4. Using outgoing publish static void mqtt_pub_request_cb(void *arg, err_t result) { if(result != ERR_OK) { printf("Publish result: %d\n", result); } } void example_publish(mqtt_client_t *client, void *arg) { const char *pub_payload= "give_temperature"; err_t err; u8_t qos = 2; /* 0 1 or 2, see MQTT specification */ u8_t retain = 0; /* No don't retain such crappy payload... */ err = mqtt_publish(client, "esp/temperature", pub_payload, strlen(pub_payload), qos, retain, mqtt_pub_request_cb, arg); if(err != ERR_OK) { printf("Publish err: %d\n", err); } } void create_menu(){ } void StartDefaultTask(void const * argument) { MX_LWIP_Init(); /*MQTT */ int tmp = 1; mqtt_client_t static_client; while(tmp == 1){ xprintf("Trying to connect\n"); vTaskDelay(1000); tmp = example_do_connect(&static_client); vTaskDelay(1000); //xprintf("tutaj koniecx"); } for(;;) { BSP_TS_GetState(&TS_State); if(TS_State.touchDetected) { BSP_LCD_Clear(LCD_COLOR_WHITE); BSP_LCD_SelectLayer(0); BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_FillRect(0,0,LCD_X_SIZE,LCD_Y_SIZE); //select Foreground Layer BSP_LCD_SelectLayer(1); char greeting[] = "Hello"; draw_button(50,50,100,100,LCD_COLOR_MAGENTA,&greeting); } char key = inkey(); if(key == 'p'){ xprintf("Send message \n"); example_publish(&static_client,2); } vTaskDelay(2); } /* USER CODE END 5 */ } /** * @brief Period elapsed callback in non blocking mode * @note This function is called when TIM6 interrupt took place, inside * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment * a global variable "uwTick" used as application time base. * @param htim : TIM handle * @retval None */ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { /* USER CODE BEGIN Callback 0 */ /* USER CODE END Callback 0 */ if (htim->Instance == TIM6) { HAL_IncTick(); } /* USER CODE BEGIN Callback 1 */ /* USER CODE END Callback 1 */ } /** * @brief This function is executed in case of error occurrence. * @param file: The file name as string. * @param line: The line in file as a number. * @retval None */ void _Error_Handler(char *file, int line) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ while(1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ /** * @} */ /** * @} */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/