系统功能:
手机开启2.4G WiFi热点后再给系统上电
系统操作说明:
上电后OLED显示 “欢迎使用气象监测系统请稍后”,两秒后显示Connecting...表示
正在连接阿里云,正常连接阿里云后显示第一页面,如长时间显示Connecting...请
检查WiFi网络是否正确。
第一页面第一行显示温湿度,第二行显示烟雾浓度和空气质量值,第三行显示光照和雨量值,
第四行显示火焰传感器状态(OK或NG)。
主要功能模块原理图:
电源时钟烧录接口:
单片机和按键输入电路:
传感器采集电路:
系统主要功能模块代码
初始化代码:
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
InitVar();
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
MX_ADC1_Init();
/* USER CODE BEGIN 2 */
//uart2打开接收中断
HAL_UART_Receive_IT(&huart2, (uint8_t*)&uart2RecBuff, 1);
InitOled();
InitOledDisp();
ResetDHT11();
//初始化ESP8266
ESP8266_Init();
HAL_Delay(100);
OledFill(0x00); //全屏熄灭
/* USER CODE END 2 */
ESP8266接入阿里云代码:
//硬件复位ESP8266
HAL_GPIO_WritePin(ESP8266RST_GPIO_Port, ESP8266RST_Pin, GPIO_PIN_RESET);
HAL_Delay(250);
HAL_GPIO_WritePin(ESP8266RST_GPIO_Port, ESP8266RST_Pin, GPIO_PIN_SET);
HAL_Delay(500);
//关闭板载LED
HAL_GPIO_WritePin(OnBoardLED_GPIO_Port, OnBoardLED_Pin, GPIO_PIN_SET);
ESP8266_Clear();
//测试AT指令
printf("AT Testing\r\n");
while(ESP8266_SendCmd("AT\r\n", "OK", 200))
{
HAL_Delay(1000);
}
HAL_GPIO_TogglePin(OnBoardLED_GPIO_Port, OnBoardLED_Pin);
HAL_Delay(500);
//设置为Station
printf("set CWMODE\r\n");
while(ESP8266_SendCmd("AT+CWMODE=1\r\n", "OK", 200))
{
HAL_Delay(1000);
}
HAL_GPIO_TogglePin(OnBoardLED_GPIO_Port, OnBoardLED_Pin);
HAL_Delay(500);
//上电不自动连接AP
printf("set CWAUTOCONN\r\n");
while(ESP8266_SendCmd("AT+CWAUTOCONN=0\r\n", "OK", 200))
{
HAL_Delay(1000);
}
HAL_GPIO_TogglePin(OnBoardLED_GPIO_Port, OnBoardLED_Pin);
HAL_Delay(500);
//关闭回显
printf("set ATE0\r\n");
while(ESP8266_SendCmd("ATE0\r\n", "OK", 200))
{
HAL_Delay(1000);
}
HAL_GPIO_TogglePin(OnBoardLED_GPIO_Port, OnBoardLED_Pin);
HAL_Delay(500);
//配置WIFI
printf("set Wifi\r\n");
while(ESP8266_SendCmd("AT+CWJAP=\""WIFI_SSID"\",\""WIFI_PASSWD"\"\r\n", "OK", 500))
{
HAL_Delay(1000);
}
HAL_GPIO_TogglePin(OnBoardLED_GPIO_Port, OnBoardLED_Pin);
HAL_Delay(500);
//MQTT USER CONFIG
printf("mqtt config\r\n");
while(ESP8266_SendCmd("AT+MQTTUSERCFG=0,1,\""MQTT_CLIENT_ID"\",\""MQTT_USER_NAME"\",\""MQTT_PASSWD"\",0,0,\"\"\r\n", "OK", 500))
{
HAL_Delay(1000);
}
HAL_GPIO_TogglePin(OnBoardLED_GPIO_Port, OnBoardLED_Pin);
HAL_Delay(1000);
//MQTT连接服务器
printf("mqtt broker\r\n");
while(ESP8266_SendCmd("AT+MQTTCONN=0,\""BROKER_ASDDRESS"\",1883,0\r\n", "OK", 500))
{
HAL_Delay(1000);
}
HAL_GPIO_TogglePin(OnBoardLED_GPIO_Port, OnBoardLED_Pin);
HAL_Delay(500);
系统控制代码:
//系统信息更新
void SystemControl(void)
{
static uint8_t updateCnt = 0;
updateCnt++;
if(updateCnt>=SYSTEM_UPDATE_INTER)
{
updateCnt = 0;
Aliyun_SendData();
}
//更新DHT11温湿度数据
UpdateTempData();
//读取传感器值
ReadSensorVal();
}
此设计提供的资料包含原理图PCB(包含PDF,AD,立创EDA三个版本),源代码,系统框图,主程序流程图,物料清单(包含使用到的器件手册),功能操作说明等。