Why failed to set apn?

I used 9160 to develop a project for the customer. According to my design, an apn needs to be set before connecting to the NB-iot network. However, when I used at command to set it, the result was unsuccessful, but when I used at command to read it, the parameters were correct. so, what has happend?

static NB_APN_PARAMENT nb_apn_table[] = 
{
	//china mobile
	{	
		"46004",
		"cmnbiot2"
	},
	//arkessa
	{
		"90128", 
		"arkessalp.com",
	},
};

void SetNetWorkApn(u8_t *imsi_buf)
{
	u32_t i;
	u8_t tmpbuf[256] = {0};

	for(i=0;i<ARRAY_SIZE(nb_apn_table);i++)
	{
		if(strncmp(imsi_buf, nb_apn_table[i].plmn, strlen(nb_apn_table[i].plmn)) == 0)
		{
			u8_t cmdbuf[128] = {0};
			
			sprintf(cmdbuf, "AT+CGDCONT=0,\"IP\",\"%s\"", nb_apn_table[i].apn);
			LOGD("cmdbuf:%s", cmdbuf); 
			if(at_cmd_write(cmdbuf, tmpbuf, sizeof(tmpbuf), NULL) != 0)
			{
				LOGD("set apn fail!");
			}

			break;
		}
	}

	if(at_cmd_write(CMD_GET_APN, tmpbuf, sizeof(tmpbuf), NULL) == 0)
	{
		LOGD("apn:%s", tmpbuf); 
	}
}
  

Parents Reply Children
  • Hello, 

    Yes, this is true if successful but what about any error code returned from modem? From the Asset Tracker of nRF Connect SDK v1.2.0

    #if defined(CONFIG_AT_CMD)
    		err = at_cmd_write(modem_at_cmd_buff, modem_at_cmd_buff,
    				sizeof(modem_at_cmd_buff), &state);
    #else
    		/* Proper error msg has already been copied to buffer */
    		err = 0;
    #endif
    	}
    
    	/* Get response length; same buffer was used for the response. */
    	len = strlen(modem_at_cmd_buff);
    
    	if (err) {
    		len = snprintf(modem_at_cmd_buff, sizeof(modem_at_cmd_buff),
    				"AT CMD error: %d, state %d", err, state);
    	} else if (len == 0) {
    		len = snprintf(modem_at_cmd_buff, sizeof(modem_at_cmd_buff),
    				"OK\r\n");
    	} else if (len > MODEM_AT_CMD_MAX_RESPONSE_LEN) {
    		len = snprintf(modem_at_cmd_buff, sizeof(modem_at_cmd_buff),
    				MODEM_AT_CMD_RESP_TOO_BIG_STR);
    	}

    Please verify no error is received from modem.

    Kind regards,
    Øyvind

  • thanks for your reply!

    I tried to get the reason why the at function failed, the return is -8, it means:

    #define ENOEXEC 8       /* Exec format error */

    However, when I used another esIM card from another carrier that could not connect to the local network, I tried to set up apN and it showed success, which is very strange!  

  • Hi, 

    we will need to look at the modem trace. Please follow this guide.

    Kind regards,
    Øyvind

Related