找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

帖子
查看: 4773|回復(fù): 6
打印 上一主題 下一主題
收起左側(cè)

stm32控制WiFi模塊的程序有嗎? 求分享

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:459919 發(fā)表于 2019-1-22 17:48 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
我剛買了一塊板子,不清楚怎么stm32怎么控制WiFi模塊的

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

來自 6#
ID:208313 發(fā)表于 2019-3-12 21:17 | 只看該作者
后面自己看看吧,我要下班了,所以撤了,如果不懂的,可以說一下,如果有不對的,也說一下,我就昨天正好看關(guān)于WIFI的代碼啊啊,學(xué)習(xí)AT指令玩玩,如果理解不對,技術(shù)水平低,也請見諒。充實(shí)自己,加油,如果我的CSDN資料開放的話,也可以看到相關(guān)解說,還沒寫完,估計(jì)暫不開放

  1. void ESP8266_StaTcpClient_UnvarnishTest ( void )//客服端,采用TCP協(xié)議通信
  2. {
  3.         uint8_t ucId, ucLen;//定義ID號,數(shù)據(jù)長度
  4.         uint8_t ucLed1Status = 0, ucLed2Status = 0, ucLed3Status = 0, ucBuzzerStatus = 0;//控制模塊初始化,例如LED1,LED2.。。。

  5.         char cStr [ 100 ] = { 0 }, cCh;//定義數(shù)組以及變量,方便后面使用

  6.   char * pCh, * pCh1;//定義指針

  7.         DHT11_Data_TypeDef DHT11_Data;//DHT11溫濕度傳感器數(shù)據(jù)
  8.         

  9.   printf ( "\r\n正在配置 ESP8266 ......\r\n" );//打印正在配置WIFI信息(正常應(yīng)該是串口顯示)

  10.         macESP8266_CH_ENABLE();//wifi 模塊使能,應(yīng)該使其工作,代碼不全,我估計(jì)實(shí)際就是是CH_PD相應(yīng)引腳置高
  11.         
  12.         ESP8266_AT_Test ();//AT指令測試,正常是發(fā)送AT+空格,返回OK
  13.         
  14.         ESP8266_Net_Mode_Choose ( AP );//選擇工作模式(AP模式)這個(gè)模式相當(dāng)于WIFI熱點(diǎn)

  15.   while ( ! ESP8266_CIPAP ( macUser_ESP8266_TcpServer_IP ) );//檢測服務(wù)器IP(具體的能看一下代碼好說)

  16.   while ( ! ESP8266_BuildAP ( macUser_ESP8266_BulitApSsid, macUser_ESP8266_BulitApPwd, macUser_ESP8266_BulitApEcn ) ); //建立AP 并設(shè)置相關(guān)信息      
  17.         
  18.         ESP8266_Enable_MultipleId ( ENABLE );//允許多路通信
  19.         
  20.         while ( !        ESP8266_StartOrShutServer ( ENABLE, macUser_ESP8266_TcpServer_Port, macUser_ESP8266_TcpServer_OverTime ) );

  21.         ESP8266_Inquire_ApIp ( cStr, 20 );
  22.         printf ( "\r\n本模塊WIFI為%s,密碼開放\r\nAP IP 為:%s,開啟的端口為:%s\r\n手機(jī)網(wǎng)絡(luò)助手連接該 IP 和端口,最多可連接5個(gè)客戶端\r\n",
  23.            macUser_ESP8266_BulitApSsid, cStr, macUser_ESP8266_TcpServer_Port );//設(shè)定5個(gè)原因也好玩,自己看代碼
  24.         
  25.         
  26.         strEsp8266_Fram_Record .InfBit .FramLength = 0;//接收數(shù)據(jù)位初始化
  27.         strEsp8266_Fram_Record .InfBit .FramFinishFlag = 0;   //最后一位檢測為初始化     
  28.         
  29.         while ( 1 )
  30.         {               
  31.                 if ( strEsp8266_Fram_Record .InfBit .FramFinishFlag )//標(biāo)志位位1
  32.                 {
  33.                         USART_ITConfig ( macESP8266_USARTx, USART_IT_RXNE, DISABLE ); //禁用串口接收中斷
  34.                         strEsp8266_Fram_Record .Data_RX_BUF [ strEsp8266_Fram_Record .InfBit .FramLength ]  = '\0';//增加空格符
  35.                         
  36. //                        printf ( "\r\n%s\r\n", strEsp8266_Fram_Record .Data_RX_BUF );//
  37.                         if ( ( pCh = strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "CMD_LED_" ) ) != 0 ) //strstr字符串比較函數(shù),存在后者字符返回1
  38.                         {
  39.                                 cCh = * ( pCh + 8 );//為啥要加8呢?實(shí)際上是因?yàn)镃MD_LED_占8個(gè)字符,要用的數(shù)據(jù)在它后一位,起始位為0,所以加8后指針調(diào)用就是它要的數(shù)據(jù)
  40.                                 
  41.                                 switch ( cCh )
  42.                                 {
  43.                                         case '1':
  44.                                                 cCh = * ( pCh + 10 );//同理,
  45.                                           switch ( cCh )
  46.                                           {
  47.                                                         case '0':
  48.                                                                 macLED1_OFF ();
  49.                                                           ucLed1Status = 0;
  50.                                                     break;
  51.                                                         case '1':
  52.                                                                 macLED1_ON ();
  53.                                                           ucLed1Status = 1;
  54.                                                     break;
  55.                                                         default :
  56.                                                                 break;
  57.                                                 }
  58.                                                 break;
  59.                                                 
  60.                                         case '2':
  61.                                                 cCh = * ( pCh + 10 );
  62.                                           switch ( cCh )
  63.                                           {
  64.                                                         case '0':
  65.                                                                 macLED2_OFF ();
  66.                                                           ucLed2Status = 0;
  67.                                                     break;
  68.                                                         case '1':
  69.                                                                 macLED2_ON ();
  70.                                                           ucLed2Status = 1;
  71.                                                     break;
  72.                                                         default :
  73.                                                                 break;
  74.                                                 }
  75.                                                 break;

  76.                                         case '3':
  77.                                                 cCh = * ( pCh + 10 );
  78.                                           switch ( cCh )
  79.                                           {
  80.                                                         case '0':
  81.                                                                 macLED3_OFF ();
  82.                                                           ucLed3Status = 0;
  83.                                                     break;
  84.                                                         case '1':
  85.                                                                 macLED3_ON ();
  86.                                                           ucLed3Status = 1;
  87.                                                     break;
  88.                                                         default :
  89.                                                                 break;
  90.                                                 }
  91.                                                 break;
  92.                                                 
  93.                                   default :
  94.             break;                                       
  95.                                                 
  96.                                 }
  97.                                 
  98.                                 sprintf ( cStr, "CMD_LED_%d_%d_%d_ENDLED_END", ucLed1Status, ucLed2Status, ucLed3Status );
  99.                                 
  100.                         }
  101.                         
  102.                         else if ( ( pCh = strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "CMD_BUZZER_" ) ) != 0 )
  103.                         {
  104.                                 cCh = * ( pCh + 11 );
  105.                                 
  106.                                 switch ( cCh )
  107.                                 {
  108.                                         case '0':
  109.                                                 macBEEP_OFF ();
  110.                                           ucBuzzerStatus = 0;
  111.                                                 break;
  112.                                         case '1':
  113.                                                 macBEEP_ON ();
  114.                                           ucBuzzerStatus = 1;
  115.                                                 break;
  116.                                         default:
  117.                                                 break;
  118.                                 }
  119.                                 
  120.                                 sprintf ( cStr, "CMD_BUZZER_%d_ENDBUZZER_END", ucBuzzerStatus );
  121.                                 
  122.                         }
  123.                                 
  124.                         else if ( ( ( pCh  = strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "CMD_UART_" ) ) != 0 ) &&
  125.                                         ( ( pCh1 = strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "_ENDUART_END" ) )  != 0 ) )
  126.                         {
  127.                                 if ( pCh < pCh1)
  128.                                 {
  129.                                         ucLen = pCh1 - pCh + 12;
  130.                                         memcpy ( cStr, pCh, ucLen );
  131.                                         cStr [ ucLen ] = '\0';
  132.                                 }
  133.                         }

  134.                         else if ( strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "CMD_READ_ALL_END" ) != 0 )
  135.                         {
  136.                                 DHT11_Read_TempAndHumidity ( & DHT11_Data );
  137.                                 sprintf ( cStr, "CMD_LED_%d_%d_%d_ENDLED_DHT11_%d.%d_%d.%d_ENDDHT11_BUZZER_%d_ENDBUZZER_END",
  138.                                                                         ucLed1Status, ucLed2Status, ucLed3Status, DHT11_Data .temp_int,
  139.                                     DHT11_Data .temp_deci, DHT11_Data .humi_int, DHT11_Data .humi_deci,
  140.                   ucBuzzerStatus );
  141.                         }
  142.                         
  143.                                 
  144.                         if ( ( pCh = strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "+IPD," ) ) != 0 )
  145.                         {
  146.                                 ucId = * ( pCh + strlen ( "+IPD," ) ) - '0';
  147.                                 ESP8266_SendString ( DISABLE, cStr, strlen ( cStr ), ( ENUM_ID_NO_TypeDef ) ucId );
  148.                         }
  149.                         
  150.                   strEsp8266_Fram_Record .InfBit .FramLength = 0;
  151.             strEsp8266_Fram_Record .InfBit .FramFinishFlag = 0;        
  152.                         
  153.                         USART_ITConfig ( macESP8266_USARTx, USART_IT_RXNE, ENABLE ); //使能串口接收中斷
  154.                         
  155.                 }
  156.                
  157.         }
  158.         
  159.                
  160. }
復(fù)制代碼

回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:459919 發(fā)表于 2019-1-23 09:20 | 只看該作者
void ESP8266_StaTcpClient_UnvarnishTest ( void )
{
        uint8_t ucId, ucLen;
        uint8_t ucLed1Status = 0, ucLed2Status = 0, ucLed3Status = 0, ucBuzzerStatus = 0;

        char cStr [ 100 ] = { 0 }, cCh;

  char * pCh, * pCh1;

        DHT11_Data_TypeDef DHT11_Data;
       

  printf ( "\r\n正在配置 ESP8266 ......\r\n" );

        macESP8266_CH_ENABLE();
       
        ESP8266_AT_Test ();
       
        ESP8266_Net_Mode_Choose ( AP );

  while ( ! ESP8266_CIPAP ( macUser_ESP8266_TcpServer_IP ) );

  while ( ! ESP8266_BuildAP ( macUser_ESP8266_BulitApSsid, macUser_ESP8266_BulitApPwd, macUser_ESP8266_BulitApEcn ) );       
       
        ESP8266_Enable_MultipleId ( ENABLE );
       
        while ( !        ESP8266_StartOrShutServer ( ENABLE, macUser_ESP8266_TcpServer_Port, macUser_ESP8266_TcpServer_OverTime ) );

        ESP8266_Inquire_ApIp ( cStr, 20 );
        printf ( "\r\n本模塊WIFI為%s,密碼開放\r\nAP IP 為:%s,開啟的端口為:%s\r\n手機(jī)網(wǎng)絡(luò)助手連接該 IP 和端口,最多可連接5個(gè)客戶端\r\n",
           macUser_ESP8266_BulitApSsid, cStr, macUser_ESP8266_TcpServer_Port );
       
       
        strEsp8266_Fram_Record .InfBit .FramLength = 0;
        strEsp8266_Fram_Record .InfBit .FramFinishFlag = 0;       
       
        while ( 1 )
        {               
                if ( strEsp8266_Fram_Record .InfBit .FramFinishFlag )
                {
                        USART_ITConfig ( macESP8266_USARTx, USART_IT_RXNE, DISABLE ); //禁用串口接收中斷
                        strEsp8266_Fram_Record .Data_RX_BUF [ strEsp8266_Fram_Record .InfBit .FramLength ]  = '\0';
                       
//                        printf ( "\r\n%s\r\n", strEsp8266_Fram_Record .Data_RX_BUF );//
                        if ( ( pCh = strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "CMD_LED_" ) ) != 0 )
                        {
                                cCh = * ( pCh + 8 );
                               
                                switch ( cCh )
                                {
                                        case '1':
                                                cCh = * ( pCh + 10 );
                                          switch ( cCh )
                                          {
                                                        case '0':
                                                                macLED1_OFF ();
                                                          ucLed1Status = 0;
                                                    break;
                                                        case '1':
                                                                macLED1_ON ();
                                                          ucLed1Status = 1;
                                                    break;
                                                        default :
                                                                break;
                                                }
                                                break;
                                               
                                        case '2':
                                                cCh = * ( pCh + 10 );
                                          switch ( cCh )
                                          {
                                                        case '0':
                                                                macLED2_OFF ();
                                                          ucLed2Status = 0;
                                                    break;
                                                        case '1':
                                                                macLED2_ON ();
                                                          ucLed2Status = 1;
                                                    break;
                                                        default :
                                                                break;
                                                }
                                                break;

                                        case '3':
                                                cCh = * ( pCh + 10 );
                                          switch ( cCh )
                                          {
                                                        case '0':
                                                                macLED3_OFF ();
                                                          ucLed3Status = 0;
                                                    break;
                                                        case '1':
                                                                macLED3_ON ();
                                                          ucLed3Status = 1;
                                                    break;
                                                        default :
                                                                break;
                                                }
                                                break;
                                               
                                  default :
            break;                                       
                                               
                                }
                               
                                sprintf ( cStr, "CMD_LED_%d_%d_%d_ENDLED_END", ucLed1Status, ucLed2Status, ucLed3Status );
                               
                        }
                       
                        else if ( ( pCh = strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "CMD_BUZZER_" ) ) != 0 )
                        {
                                cCh = * ( pCh + 11 );
                               
                                switch ( cCh )
                                {
                                        case '0':
                                                macBEEP_OFF ();
                                          ucBuzzerStatus = 0;
                                                break;
                                        case '1':
                                                macBEEP_ON ();
                                          ucBuzzerStatus = 1;
                                                break;
                                        default:
                                                break;
                                }
                               
                                sprintf ( cStr, "CMD_BUZZER_%d_ENDBUZZER_END", ucBuzzerStatus );
                               
                        }
                               
                        else if ( ( ( pCh  = strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "CMD_UART_" ) ) != 0 ) &&
                                        ( ( pCh1 = strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "_ENDUART_END" ) )  != 0 ) )
                        {
                                if ( pCh < pCh1)
                                {
                                        ucLen = pCh1 - pCh + 12;
                                        memcpy ( cStr, pCh, ucLen );
                                        cStr [ ucLen ] = '\0';
                                }
                        }

                        else if ( strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "CMD_READ_ALL_END" ) != 0 )
                        {
                                DHT11_Read_TempAndHumidity ( & DHT11_Data );
                                sprintf ( cStr, "CMD_LED_%d_%d_%d_ENDLED_DHT11_%d.%d_%d.%d_ENDDHT11_BUZZER_%d_ENDBUZZER_END",
                                                                        ucLed1Status, ucLed2Status, ucLed3Status, DHT11_Data .temp_int,
                                    DHT11_Data .temp_deci, DHT11_Data .humi_int, DHT11_Data .humi_deci,
                  ucBuzzerStatus );
                        }
                       
                               
                        if ( ( pCh = strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "+IPD," ) ) != 0 )
                        {
                                ucId = * ( pCh + strlen ( "+IPD," ) ) - '0';
                                ESP8266_SendString ( DISABLE, cStr, strlen ( cStr ), ( ENUM_ID_NO_TypeDef ) ucId );
                        }
                       
                  strEsp8266_Fram_Record .InfBit .FramLength = 0;
            strEsp8266_Fram_Record .InfBit .FramFinishFlag = 0;       
                       
                        USART_ITConfig ( macESP8266_USARTx, USART_IT_RXNE, ENABLE ); //使能串口接收中斷
                       
                }
               
        }
       
               
}


這個(gè)程序主要說的是什么意思呀
回復(fù)

使用道具 舉報(bào)

板凳
ID:365274 發(fā)表于 2019-1-24 23:35 | 只看該作者
這個(gè)要看你使用的是哪一個(gè)wifi模塊
回復(fù)

使用道具 舉報(bào)

地板
ID:459919 發(fā)表于 2019-1-30 14:34 | 只看該作者
shihun 發(fā)表于 2019-1-24 23:35
這個(gè)要看你使用的是哪一個(gè)wifi模塊

esp8266這個(gè)WiFi模塊
回復(fù)

使用道具 舉報(bào)

5#
ID:474137 發(fā)表于 2019-1-30 14:54 | 只看該作者
仔細(xì)閱讀一下wifi模塊的手冊~
回復(fù)

使用道具 舉報(bào)

7#
ID:490347 發(fā)表于 2019-3-13 22:32 | 只看該作者
看下這個(gè)

ESP8266新手入門調(diào)試指導(dǎo)(補(bǔ)全).doc

621.12 KB, 下載次數(shù): 82

回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表