20260115:初步实现了MQTT协议发布指令的功能;完善了部分任务之间的运行逻辑。
This commit is contained in:
@@ -10,9 +10,9 @@ struct SerialFrame_t xSerialFrameRecord = { 0 };
|
||||
* @param <20><>
|
||||
* @retval <20><>
|
||||
*/
|
||||
static void vEsp8266GpioConfig ( void )
|
||||
void vEsp8266GpioConfig ( void )
|
||||
{
|
||||
/*<2A><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>GPIO_InitTypeDef<65><66><EFBFBD>͵Ľṹ<C4BD><E1B9B9>*/
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>GPIO_InitTypeDef<EFBFBD><EFBFBD><EFBFBD>͵Ľṹ<EFBFBD><EFBFBD> */
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
/* <20><><EFBFBD><EFBFBD> CH_PD <20><><EFBFBD><EFBFBD>*/
|
||||
RCC_APB2PeriphClockCmd ( macESP8266_CH_PD_CLK, ENABLE );
|
||||
@@ -26,20 +26,6 @@ static void vEsp8266GpioConfig ( void )
|
||||
GPIO_Init ( macESP8266_RST_PORT, & GPIO_InitStructure );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief vEsp8266Init
|
||||
* @note ESP8266ģ<36><C4A3><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD>á<EFBFBD>
|
||||
* @param <20><>
|
||||
* @retval <20><>
|
||||
*/
|
||||
void vEsp8266Init ( void )
|
||||
{
|
||||
vEsp8266GpioConfig ();
|
||||
macESP8266_RST_HIGH_LEVEL();
|
||||
macESP8266_CH_DISABLE();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief vEsp8266Rst
|
||||
* @note <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϳ<EFBFBD><CDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ESP8266ģ<36>飬<EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD>vEsp8266AtTest<73><74><EFBFBD>á<EFBFBD>
|
||||
@@ -157,26 +143,26 @@ bool bEsp8266MqttInit ( char * pcMqttUserName, char * pcMqttPassword, char * pcM
|
||||
{
|
||||
char cCmd[512] = {0};
|
||||
|
||||
// 1. <20><><EFBFBD><EFBFBD>MQTT<54>û<EFBFBD><C3BB><EFBFBD>Ϣ
|
||||
/* 1. <20><><EFBFBD><EFBFBD>MQTT<54>û<EFBFBD><C3BB><EFBFBD>Ϣ */
|
||||
snprintf(cCmd, sizeof(cCmd), "AT+MQTTUSERCFG=0,1,\"NULL\",\"%s\",\"%s\",0,0,\"\"",
|
||||
pcMqttUserName, pcMqttPassword);
|
||||
if (!bEsp8266Command(cCmd, "OK", NULL, 2000))
|
||||
return false;
|
||||
|
||||
// 2. <20><><EFBFBD>ÿͻ<C3BF><CDBB><EFBFBD>ID
|
||||
/* 2. <20><><EFBFBD>ÿͻ<C3BF><CDBB><EFBFBD>ID */
|
||||
memset(cCmd, 0, sizeof(cCmd));
|
||||
snprintf(cCmd, sizeof(cCmd), "AT+MQTTCLIENTID=0,\"%s\"", pcMqttClientId);
|
||||
if (!bEsp8266Command(cCmd, "OK", NULL, 2000))
|
||||
return false;
|
||||
|
||||
// 3. <20><><EFBFBD>ӵ<EFBFBD>MQTT<54><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/* 3. <20><><EFBFBD>ӵ<EFBFBD>MQTT<54><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
memset(cCmd, 0, sizeof(cCmd));
|
||||
snprintf(cCmd, sizeof(cCmd), "AT+MQTTCONN=0,\"%s\",%u,1",
|
||||
pcMqttServerIp, usMqttServerPort);
|
||||
if (!bEsp8266Command(cCmd, "OK", NULL, 5000))
|
||||
if (!bEsp8266Command(cCmd, "OK", NULL, 5000) && !bEsp8266Command(cCmd, "+MQTTCONN", NULL, 5000))
|
||||
return false;
|
||||
|
||||
// 4. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/* 4. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
memset(cCmd, 0, sizeof(cCmd));
|
||||
snprintf(cCmd, sizeof(cCmd), "AT+MQTTSUB=0,\"%s\",1", pcMqttSubscribeTopic);
|
||||
if (!bEsp8266Command(cCmd, "OK", NULL, 2000))
|
||||
@@ -216,17 +202,17 @@ bool bEsp8266EnableMultipleId ( FunctionalState xEnumEnUnvarnishTx )
|
||||
/**
|
||||
* @brief bEsp8266LinkServer
|
||||
* @note ESP8266ģ<36><C4A3><EFBFBD><EFBFBD><EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD>á<EFBFBD>
|
||||
* @param enumE<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param xNetProtocol<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param pcIp<49><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<49><50>ַ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
* @param pcComNum<75><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿ں<CBBF><DABA>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
* @param xId<49><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID<49><44>
|
||||
* @retval 1<><31><EFBFBD><EFBFBD><EFBFBD>ӳɹ<D3B3>
|
||||
* @retval 0<><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||||
*/
|
||||
bool bEsp8266LinkServer ( eNetPro_t enumE, char * pcIp, char * pcComNum, eIdNo_t xId)
|
||||
bool bEsp8266LinkServer ( eNetPro_t xNetProtocol, char * pcIp, char * pcComNum, eIdNo_t xId)
|
||||
{
|
||||
char cStr [100] = { 0 }, cCmd [120];
|
||||
switch ( enumE )
|
||||
switch ( xNetProtocol )
|
||||
{
|
||||
case enumTCP:
|
||||
sprintf ( cStr, "\"%s\",\"%s\",%s", "TCP", pcIp, pcComNum );
|
||||
@@ -241,7 +227,7 @@ bool bEsp8266LinkServer ( eNetPro_t enumE, char * pcIp, char * pcComNum, eIdNo_t
|
||||
sprintf ( cCmd, "AT+CIPSTART=%d,%s", xId, cStr);
|
||||
else
|
||||
sprintf ( cCmd, "AT+CIPSTART=%s", cStr );
|
||||
return bEsp8266Command ( cCmd, "OK", "ALREAY CONNECT", 4000 );
|
||||
return bEsp8266Command ( cCmd, "OK", "ALREADY CONNECT", 4000 );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -368,7 +354,7 @@ uint8_t ucEsp8266InquireApIp ( char * pcApIp, uint8_t ucArrayLength )
|
||||
*/
|
||||
bool bEsp8266UnvarnishSend ( void )
|
||||
{
|
||||
return ( bEsp8266Command ( "AT+CIPMODE=1", "OK", 0, 500 ) );
|
||||
return bEsp8266Command ( "AT+CIPMODE=1", "OK", 0, 500 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user