一、硬件組成如下圖所示:
硬件全家福:
二、下載通用APP DEMO:
1.在應(yīng)用商店,搜索“機(jī)智云”APP。
通用APP Demo 又稱“機(jī)智云”APP
2.安裝、注冊(cè)、登陸后如下圖所示:
三、調(diào)試過(guò)程詳解:
創(chuàng)建數(shù)據(jù)點(diǎn)
生成MCU工程
下載MCU工程并根據(jù)開(kāi)發(fā)板原理圖修改工程,修改的地方如程序中紅色加注釋的部分
main.c 中加入紅色標(biāo)出的GPIO初始化代碼
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE(); //GPIOF CLK Enable:Used to Ctrol LED
/*Configure GPIO pins : KEY2_Pin KEY1_Pin */
GPIO_InitStruct.Pin = KEY2_Pin|KEY1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOE, LED1_Pin|LED0_Pin, GPIO_PIN_SET);
/*Configure GPIO pins : LED1_Pin LED0_Pin */
GPIO_InitStruct.Pin = LED1_Pin|LED0_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
}
main.h頭文件中增加以下內(nèi)容
/* USER CODE BEGIN Private defines */
#define LED1_Pin GPIO_PIN_9
#define LED1_GPIO_Port GPIOF
#define LED0_Pin GPIO_PIN_10
#define LED0_GPIO_Port GPIOF
/* USER CODE END Private defines */
gizwits_product.c中需要用戶添設(shè)備上電狀態(tài)代碼如下圖所示
void userInit(void)
{
memset((uint8_t*)¤tDataPoint, 0, sizeof(dataPoint_t));
/** Warning !!! DataPoint Variables Init , Must Within The Data Range **/
currentDataPoint.valueValve = 0;
currentDataPoint.valueLED0 = 1;
currentDataPoint.valueLED1 = 1;
currentDataPoint.valueState = 1;
currentDataPoint.valueValue = 5;
}
gizwits_product.c中需要用戶添加的代碼如下圖所示
int8_t gizwitsEventProcess(eventInfo_t *info, uint8_t *gizdata, uint32_t len)
{
uint8_t i = 0;
dataPoint_t *dataPointPtr = (dataPoint_t *)gizdata;
moduleStatusInfo_t *wifiData = (moduleStatusInfo_t *)gizdata;
protocolTime_t *ptime = (protocolTime_t *)gizdata;
#if MODULE_TYPE
gprsInfo_t *gprsInfoData = (gprsInfo_t *)gizdata;
#else
moduleInfo_t *ptModuleInfo = (moduleInfo_t *)gizdata;
#endif
if((NULL == info) || (NULL == gizdata))
{
return -1;
}
for(i=0; i
{
switch(info->event[i])
{
case EVENT_Valve:
currentDataPoint.valueValve = dataPointPtr->valueValve;
GIZWITS_LOG("Evt: EVENT_Valve %d ", currentDataPoint.valueValve);
if(0x01 == currentDataPoint.valueValve)
{
//user handle
HAL_GPIO_TogglePin(LED1_GPIO_Port,LED1_Pin); //led1閃爍 ,沒(méi)有閥,用燈替代
HAL_Delay(500);
HAL_GPIO_TogglePin(LED0_GPIO_Port,LED0_Pin); //led0閃爍 沒(méi)有閥,用燈替代
HAL_Delay(500);
}
else
{
//user handle
HAL_GPIO_WritePin(LED1_GPIO_Port,LED1_Pin,GPIO_PIN_SET); //熄滅led1
HAL_GPIO_WritePin(LED0_GPIO_Port,LED0_Pin,GPIO_PIN_SET); //熄滅led0
}
break;
case EVENT_LED0:
currentDataPoint.valueLED0 = dataPointPtr->valueLED0;
GIZWITS_LOG("Evt: EVENT_LED0 %d ", currentDataPoint.valueLED0);
if(0x01 == currentDataPoint.valueLED0)
{
//user handle
HAL_GPIO_WritePin(GPIOF,GPIO_PIN_10,GPIO_PIN_RESET); //點(diǎn)亮led0
}
else
{
//user handle
HAL_GPIO_WritePin(GPIOF,GPIO_PIN_10,GPIO_PIN_SET); //熄滅led0
}
break;
case EVENT_LED1:
currentDataPoint.valueLED1 = dataPointPtr->valueLED1;
GIZWITS_LOG("Evt: EVENT_LED1 %d ", currentDataPoint.valueLED1);
if(0x01 == currentDataPoint.valueLED1)
{
//user handle
HAL_GPIO_WritePin(GPIOF,GPIO_PIN_9,GPIO_PIN_RESET); //點(diǎn)亮led1
}
else
{
//user handle
HAL_GPIO_WritePin(GPIOF,GPIO_PIN_9,GPIO_PIN_SET); //滅掉led1
}
break;
case WIFI_SOFTAP:
break;
case WIFI_AIRLINK:
break;
case WIFI_STATION:
break;
case WIFI_CON_ROUTER:
break;
case WIFI_DISCON_ROUTER:
break;
case WIFI_CON_M2M:
break;
case WIFI_DISCON_M2M:
break;
case WIFI_RSSI:
GIZWITS_LOG("RSSI %d ", wifiData->rssi);
break;
case TRANSPARENT_DATA:
GIZWITS_LOG("TRANSPARENT_DATA ");
//user handle , Fetch data from [data] , size is [len]
break;
case WIFI_NTP:
GIZWITS_LOG("WIFI_NTP : [%d-%d-%d %02d:%02d:%02d][%d] ",ptime->year,ptime->month,ptime->day,ptime->hour,ptime->minute,ptime->second,ptime->ntp);
break;
case MODULE_INFO:
GIZWITS_LOG("MODULE INFO ... ");
#if MODULE_TYPE
GIZWITS_LOG("GPRS MODULE ... ");
//Format By gprsInfo_t
#else
GIZWITS_LOG("WIF MODULE ... ");
//Format By moduleInfo_t
GIZWITS_LOG("moduleType : [%d] ",ptModuleInfo->moduleType);
#endif
break;
default:
break;
}
}
return 0;
}
4.程序燒錄:使用FlyMCU進(jìn)行程序燒寫, 5.打開(kāi)APP操控體驗(yàn)6.打開(kāi)Xcom查看調(diào)試信息
四、注意事項(xiàng):
1.正確找出開(kāi)發(fā)板的UART2接口:本開(kāi)發(fā)板中對(duì)應(yīng)關(guān)系如下:
UART2_TX:PA2,
UART2_RX:PA3,
2.保證與ESP8266模塊的管腳接線正確:
V3.3(接開(kāi)發(fā)板3.3V);
GND(接開(kāi)發(fā)板GND);
TX (接開(kāi)發(fā)板的PA3管腳);
RX (接開(kāi)發(fā)板的PA2管腳);
3.由于本次使用的ESP8266是原來(lái)機(jī)智云二代產(chǎn)品上的,可能正常聯(lián)上機(jī)智云,故沒(méi)有給ESP8266燒寫固件,關(guān)于固件燒寫的內(nèi)容,請(qǐng)參閱論壇的相關(guān)文檔。
-
STM32F407
+關(guān)注
關(guān)注
15文章
187瀏覽量
29436 -
機(jī)智云
+關(guān)注
關(guān)注
2文章
587瀏覽量
26392 -
ESP8266
+關(guān)注
關(guān)注
50文章
962瀏覽量
44956
原文標(biāo)題:【詳解】STM32F407+ESP8266連接機(jī)智云過(guò)程
文章出處:【微信號(hào):IoTMaker,微信公眾號(hào):機(jī)智云開(kāi)發(fā)者】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論