当前位置:网站首页>第六天训练
第六天训练
2022-07-17 09:00:00 【Andrewjianlei】
// 1.启动串口2接收(中断方式)
USART2_StartRx();
//usart.c:
//void USART2_StartRx(void)
//{
// HAL_UART_Receive_IT(&huart2, (uint8_t*)&rx_data, 1);
//}
// 2.串口2发送AT指令,启动TCP服务
//USART2_Transmit(tx_data, sizeof(tx_data), 500);
ESP8266_SendCommand("AT+RST", "OK", 500);
HAL_Delay(1000);
ESP8266_SendCommand("AT+CWMODE=1", "OK", 500);
ESP8266_SendCommand("AT+CWJAP=\"100ask\",\"100ask100ask\"", "OK", 5000);
ESP8266_SendCommand("AT+CIPMUX=1", "OK", 500);
ESP8266_SendCommand("AT+CIPSERVER=1,9999", "OK", 500);
ESP8266_SendCommand("AT+CIFSR", "OK", 500);
//usart.c:
//uint8_t ESP8266_SendCommand(char *cmd, char *reply, uint16_t timeout)
//{
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
// 3.1 按键按下,发送门铃信号
if (Key_GetFlag() == 1)
//gpio.c:
//uint8_t Key_GetFlag(void)
//{
// if(key_flag)
// {
// key_flag = 0;
// return 1;
// }
// else
// return 0;
//}
{
ESP8266_Send_TCP("{\"data\":\"doorbell\",\"status\":\"1\"}");
}
//usart.c:
//uint8_t ESP8266_Send_TCP(char *data)
//{
// 3.2 收到数据,控制灯
if (USART2_Receive(rx_data)) //接收到数据
//usart.c
//uint16_t USART2_Receive(uint8_t *pdata)
//{
// memcpy(pdata, (uint8_t*)usart_rx_buf, rx_len);
// return rx_len;
//}
{
if (strstr((char *)rx_data, "\"dev\":\"led\",\"status\":\"0\""))
//比对rxdata 和发送数据
{
printf("led off\n\r");
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
USART2_ClearBuf();
memset(rx_data, 0, 200);
//让GPIOA输出高电平
//清空Buf
//清空rx_data
}
else if (strstr((char *)rx_data, "\"dev\":\"led\",\"status\":\"1\""))
{
printf("led on\n\r");
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
USART2_ClearBuf();
memset(rx_data, 0, 200);
}
}
}
边栏推荐
猜你喜欢
【AXI】解读AXI协议的额外信号(QOS信号,REGION信号,与USER信号)
MySQL读写分离
ARM计算新应用,违规垂钓“一网打尽”
BCG 使用之CBCGPEdit控件
Dynamic memory management
【无标题】
[face recognition] face recognition based on histogram histogram with matlab code
LabVIEW32位与64位的兼容性
【Port 3000 is already in use,3000端口被占用问题解决方法】
How to position the circle of friends? Three core steps to build a circle of friends selling popular products
随机推荐
How to position the circle of friends? Three core steps to build a circle of friends selling popular products
数据湖(二十):Flink兼容Iceberg目前不足和Iceberg与Hudi对比
LeetCode 0116.填充每个节点的下一个右侧节点指针
【Port 3000 is already in use,3000端口被占用问题解决方法】
Nacos new configuration management
一文,教你实现单点登录
小说里的编程 【连载之十四】元宇宙里月亮弯弯
Programming in the novel [serial 14] the moon bends in the yuan universe
Difference and connection between structure and Consortium
深度学习第四周Key Concepts on Deep Neural Networks习题整理
Matlab imports floating-point numbers with more than 9 digits after the decimal point
分布式事务-可靠消息最终一致性解决方案
Redis
软件测试需要学习多久?
49. MySQL usage
Magic Usage of mongodb $symbol +mongo data type
MySQL data type
小说里的编程 【连载之十三】元宇宙里月亮弯弯
【人脸识别】基于直方图Histogram实现人脸识别附matlab代码
2022t elevator repair examination question bank and answers