RAK421做STA连接不上路由器,但是可以连接手机热点?



  • RAK421做STA连接手机热点可以,但是连接路由器程序执行connect可以正常连接,到动态分配IP就出错,分配不了,而且静态IP也不行!
    int init_wifi_module(void)
    {
    int i=0;
    int retval=0;

    rak_init_struct(&rak_strapi);      //³õʼ»¯È«¾Ö²ÎÊý½á¹¹
    
    while(!(HAL_GPIO_ReadPin(SPIx_INT_GPIO_PORT,SPIx_INT_PIN)));
    rak_sys_init(&uCmdRspFrame);      
    for(i = 0; i < 18; i++)
    {
      printf("%c",uCmdRspFrame.initResponse.strdata[i]);	
    } 
    

    delay_ms(200);
    retval= rak_get_version();
    if(retval!=RUN_OK)
    {
    return retval;
    }
    else
    {
    RAK_RESPONSE_TIMEOUT(RAK_GETVERSION_TIMEOUT);
    rak_read_packet(&uCmdRspFrame);
    printf(" version=%s\r\n",uCmdRspFrame.versionFrame.host_fw);
    rak_clearPktIrq();
    }
    rak_scan_t ScanFrame;
    do {
    ScanFrame.channel=0;
    // ScanFrame.ssid[0]= 0;
    strcpy((char *)&ScanFrame.ssid, RAK_SCAN_SSID);

    		retval=  rak_uscan(&ScanFrame);   
    		if(retval!=RUN_OK)
    		{
    			return retval;
    		}
    		else
    		{                    
    			RAK_RESPONSE_TIMEOUT(RAK_SCAN_IMEOUT);
    			rak_read_packet(&uCmdRspFrame);
    

    // printf("scan retval =%d\r\n",uCmdRspFrame.scanResponse.status);
    rak_clearPktIrq();
    if (uCmdRspFrame.scanResponse.status==0)
    {
    printf("Scan num =%d\r\n",uCmdRspFrame.scanResponse.ap_num);
    break;
    }else {
    delay_ms(100);
    }
    }
    }while(1);
    //4. ¶ÁÈ¡Ö¸¶¨¸öÊýµÄɨÃè½á¹û
    rak_getscan_t GetScanFrame;
    GetScanFrame.scan_num=uCmdRspFrame.scanResponse.ap_num;
    retval= rak_getscan(&GetScanFrame);
    if(retval!=RUN_OK)
    {
    return retval;
    }else{
    RAK_RESPONSE_TIMEOUT(RAK_GETSCAN_IMEOUT);
    rak_read_packet(&uCmdRspFrame);
    for (int i=0;i<GetScanFrame.scan_num;i++)
    {
    printf("%s ch=%d rssi=-%d security=0x%X\r\n",uCmdRspFrame.getscanResponse.strScanInfo[i].ssid,
    uCmdRspFrame.getscanResponse.strScanInfo[i].rfChannel,
    255-uCmdRspFrame.getscanResponse.strScanInfo[i].rssiVal,
    uCmdRspFrame.getscanResponse.strScanInfo[i].securityMode);
    }
    rak_clearPktIrq();
    }
    //5.ÉèÖÃÍøÂçÃÜÂë
    retval=rak_set_psk(&rak_strapi.uPskFrame);
    if(retval!=RUN_OK)
    {
    printf ("psk error!\r\n");
    return retval;
    }
    else
    {

        RAK_RESPONSE_TIMEOUT(RAK_SETPSK_TIMEOUT);
        rak_read_packet(&uCmdRspFrame);
    	  printf("PSK=%s,0X%X\r\n",rak_strapi.uPskFrame.psk,uCmdRspFrame.rspCode[0]) ;
    	  rak_clearPktIrq();
    

    }
    //6.¼ÓÈëÎÞÏßÍøÂç
    retval= rak_connect(&rak_strapi.uConnFrame);
    if(retval!=RUN_OK)
    {
    printf ("connect error !\r\n");
    return retval;
    }
    else
    {
    printf ("connect ok !\r\n");
    RAK_RESPONSE_TIMEOUT(RAK_CONNECT_TIMEOUT);
    rak_read_packet(&uCmdRspFrame);
    for(i = 0; i < 6; i++)
    {
    printf("%2X",uCmdRspFrame.CmdRspBuf[i]);
    }
    printf ("\r\n");
    rak_clearPktIrq();

    }  
    

    do
    {
    retval = rak_ipconfig_dhcp(RAK_DHCP_MODE) ;
    if (retval!=RUN_OK)
    {
    printf ("DHCP error!\r\n");
    return retval;
    }
    else
    {
    RAK_RESPONSE_TIMEOUT(RAK_CONNECT_TIMEOUT);
    rak_read_packet(&uCmdRspFrame);
    for(i = 0; i < 29; i++)
    {
    printf("%02X ",uCmdRspFrame.CmdRspBuf[i]);
    }
    printf("\r\n");
    if(uCmdRspFrame.ipparamFrameRcv.status==0){
    printf ("IP=");
    for (i=3;i>=0;i--)
    {
    printf ("%d",uCmdRspFrame.ipparamFrameRcv.ipaddr[i]);
    if (i<=3&&i>0)
    { printf ("."); }
    }
    printf ("\r\n") ;
    printf ("DHCP OK!\r\n");
    rak_clearPktIrq();
    break;
    }else{
    delay_ms(100);
    }
    }
    }while(1);
    }


  • administrators

    你好,可以connect连接说明已经连上路由器,在STA模式下连接路由器是需要设置DHCP模式的,你可以参照官网中给出的编程手册逐步的多调试几次脚试试 。


登录后回复
 

与 RAK支持中心 的连接断开,我们正在尝试重连,请耐心等待