Fork me on GitHub

一 知识点
1 AI指令后面一定要加 \n\r
2 注意AT指令里面待双引号的这种,要使用斜杠隔开。
二 源码:
void Set_Pdu_Mode(void)
{
    u8 a = 1;
    if(atKey == 1)//允许发送AT指令
    {
        atKey  = 0;
        UartSendStr("test start\r\n");//串口1输出开始提示
        while(a != 9)
        {   
            switch (a)
            {
                case 1:
            a = Second_AT_Command("AT","OK");//如果a =9则表明最后一条语句发送完毕,跳出循环,否则一直进行指定指令的发送
                delay2s();
              if(a == 0) //如果正常发送,则进行下一步
                    a = 2;
              break;
                case 2:
            a =Second_AT_Command("AT+CSTT=\"CMNET\"","OK");
                delay2s();
                
              if(a == 0) //如果正常发送,则进行下一步
                    a = 3;
              break;
                case 3:
            a = Second_AT_Command("AT+CIICR","OK");
                delay2s();
              if(a == 0) //如果正常发送,则进行下一步
                    a = 4;
              break;
                case 4:
            a = Second_AT_Command("AT+MCONFIG=\"test\",\"\",\"\"","OK");
                delay2s();
              if(a == 0) //如果正常发送,则进行下一步
                    a = 5;
              break;
                case 5:
                a = Second_AT_Command("AT+MIPSTART=\"47.111.138.129\",\"1883\"","OK");
                delay2s();
                if(a == 0) //如果正常发送,则进行下一步
                    a = 6;
              break;
                case 6:
                a = Second_AT_Command("AT+MCONNECT=1,60","OK");
                delay2s();
                if(a == 0) //如果正常发送,则进行下一步
                    a = 7;
              break;
                case 7:
                a =Second_AT_Command("AT+MSUB=\"mqtt/topic\",0","OK");
                delay2s();
                if(a == 0) //如果正常发送,则进行下一步
                    a = 8;
              break;
                case 8:
                a = Second_AT_Command("AT+MPUB=\"mqtt/topic\",0,0,\"strat\"","OK");
                delay2s();
                if(a == 0) //如果正常发送,则进行下一步
                    a = 9;
              break;
                defalut:
                  a = 1;
            }
        }
}

 

posted on 2023-09-18 19:01  虚生  阅读(418)  评论(0编辑  收藏  举报