电子说
一、硬件组成如下图所示:
硬件全家福:
STM32F407ZGT6+ESP8266
二、下载通用APP DEMO:
1.在应用商店,搜索“机智云”APP。
通用APP Demo 又称“机智云”APP
2.安装、注册、登陆后如下图所示:
三、调试过程详解:
创建数据点
生成MCU工程
下载MCU工程并根据开发板原理图修改工程,修改的地方如程序中红色加注释的部分
main.c 中加入红色标出的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头文件中增加以下内容
/* 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中需要用户添设备上电状态代码如下图所示
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闪烁 ,没有阀,用灯替代
HAL_Delay(500);
HAL_GPIO_TogglePin(LED0_GPIO_Port,LED0_Pin); //led0闪烁 没有阀,用灯替代
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); //点亮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); //点亮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进行程序烧写, 5.打开APP操控体验6.打开Xcom查看调试信息
四、注意事项:
1.正确找出开发板的UART2接口:本开发板中对应关系如下:
UART2_TX:PA2,
UART2_RX:PA3,
2.保证与ESP8266模块的管脚接线正确:
V3.3(接开发板3.3V);
GND(接开发板GND);
TX (接开发板的PA3管脚);
RX (接开发板的PA2管脚);
3.由于本次使用的ESP8266是原来机智云二代产品上的,可能正常联上机智云,故没有给ESP8266烧写固件,关于固件烧写的内容,请参阅论坛的相关文档。
全部0条评论
快来发表一下你的评论吧 !