Debugging process of NB module based on removing BC26 and removing BL620

NB Module Connecting Network Sequence

Shiko NBL260 Module

NB Card: Unicom default baud rate 115200

// UDP link mode:

AT// Judging whether the module is powered on successfully

AT+CIMI//Read IMSI to determine whether SIM card initialization is successful

AT+CESQ Check Signal Quality

AT+CEREG?// Judges PS domain attachment status (whether registered network) and returns 1 or 5 to indicate normal attachment.

 

AT+CIPMUX=0 // / Switch to a single link

AT+CIPSTART= "UDP", "101.95.153.110", "60110// Configure Server and Upload Mode

AT+QLWOPEN=0 // Connect Network

AT+CIPSEND =5 // Fixed Send Data Length Bit 5 (Length and Size can be set freely)

12345 // Upload data directly

AT+CIPRXGET=1,100    // get data

 

Remote NB BC26 Module

Link Remote Platform (COAP Protocol)

NB Card: Unicom default baud rate 115200

Manual inspection:

AT // Synchronized baud rate until OK replies

AT+CIMI//Read IMSI to determine whether SIM card initialization is successful

AT+CESQ//Check Signal Quality Recommendation 15-31

AT+CFUN?//Return 1. Check UE's functional level 1 for all functions

AT+CEREG? Returns 0,1 to indicate successful access. 0,0,0,2 is looking for 300S.

AT+CGPADDR=1 Check IP

AT+CGSN=1//Get IMEI Number

Automatic inspection section:

URC:

+CPIN: READY

+IP:XXXXXXX 

// Network, Format Configuration

AT+NCDP=southbound.quectel.com,5683 // / Set up the server port and address

AT+QLWCONF="IMEI". For example: AT+QLWCONF="866971033147948".)

AT+QLWADDOBJ=19,1,1,"0" // Configuration: LWM2M

AT+QLWADDOBJ=19,0,1, "0"//Configuration 1:LWM2M

AT+QLWOPEN=0                //Register to the IoT platform in direct push mode

AT+QLWCFG="dataformat",1,1  //Configure hex string mode for sending and received data.

AT+QLWDATASEND=19,0,0,2,3132,0x0100. //send data 1 and 2 data length 2 CON data

 

AT+SM=LOCK instruction to prevent modules from entering PSM//debugging can be used

 

Description: The module will automatically connect to the network when it is powered on. If the module returns + CPIN: READY, the basic configuration of the module itself has been completed, and returns + IP:XXXXXXX, it means that the module has automatically connected to the network. If the network is connected automatically, it can enter the network configuration directly, and then send data. The concrete case is shown in the figure below.

 

 

Shift away from NB Guangzhou Unicom Platform

https://device1-portal.10646.cn

user = "dyson.zhang@whoareyou.live";

 password = "way123!@#";

 

coAP Access Mode LwM2M Link

AT

AT+CESQ

AT+CFUN?

AT+CEREG?

AT+CGPADDR=1

AT+QLWSERV="device1-api.10646.cn",5683 Equivalent AT+NCDP=device1-api.10646.cn,5683

AT+QLWCONF="866971033147948"

AT+QLWADDOBJ=19,1,1,"0"

AT+QLWADDOBJ=19,0,1,"0"

AT+QLWOPEN=0

AT+QLWCFG="dataformat",1,1

AT+QLWDATASEND=19,0,0,2,3132,0x0100//con data

Notes: The module will automatically adjust the working mode after booting, without additional intervention. If it does not operate for a period of time, the module will enter the PSM mode. If you want to operate again, you need to wake up from PSM.

Enter key is required when AT command is sent

include "App_Main.h"
#include "NBIot_BC26.h"
#include "Drv_Usart.h"
#include "fifo.h"

static void StartingUp(void);

extern char gaucUsart1Buff[RXBUFSIZE];
 char  *gcBC26CmdBuff=0 ; // Store status instructions returned by BN26 module
 void NB_BC26_init(void)
 {
    // NB  Vcc  
   GPIO_SetMode(NB_VCCPort, NB_VCCPin, GPIO_MODE_OUTPUT);
   GPIO_SetMode(PWRKEY_Port, PWRKEY_Pin, GPIO_MODE_OUTPUT);
   GPIO_SetMode(PSM_EINT_port, PSM_EINT_pin, GPIO_MODE_OUTPUT);
   GPIO_SetMode(Reset_Port, Reset_Pin, GPIO_MODE_OUTPUT);
	 
   NB_VCCEN;
	  Reset_Disable;
//   Reset_BC26();
   Drv_SysDelayMs(50);
   StartingUp();
	// PSM_wake();
 }
 // Wake up from psm
 static void PSM_wake(void)
 {
   PSM_EINT_Disable;
   Drv_SysDelayMs(10);
   PSM_EINT_EN;
   Drv_SysDelayMs(5);
   PSM_EINT_Disable;
 }
 //Power-on startup
 static void StartingUp(void)
 {
   PWRKEY_Disable;
   Drv_SysDelayMs(10);
   PWRKEY_EN; 
   Drv_SysDelayMs(800);
   PWRKEY_Disable;
 }
 //Turn off the power
  void Shutdown(void)
  {
    NB_VCCDisable;
  }
// reset 
 void Reset_BC26(void)
 {
    Reset_Disable;
    Drv_SysDelayMs(10);
    Reset_EN;
    Drv_SysDelayMs(100);
    Reset_Disable;
 }
 /*Send AT instructions to NBiot
  Return: 1 for success 0 for failure  
 */
 
 uint8_t Send_AT_CMD(UART_T* uart,uint8_t *cmdBuffer)
 {
	 uint8_t utReturn = 0;
	 
	 while(*cmdBuffer != '\0')
	 {
     utReturn = UART_Write(uart,cmdBuffer++,1);
	 }
	 return utReturn;
 }
 /* function : Determine the return data
    @param : 
    *String:  Contrastive orders received
    *InBuffer: Input Data Cache (IN)
    * OutBuffer : String intercepted in InBuffer and subsequent data
    ucLen The first address to appear after the comparison is the first address.
 */
extern volatile uint32_t gudComRFlag;
extern uint8_t guRX_num;
 
 
char *RX_BC26_CMD(char *InBuffer,char *String)
{
  char *INdex=0;
    INdex = strstr(InBuffer,String);
  return INdex;
}

 /* function : Send instructions
    @param : uart   Serial slogans
    cmd  dispatch orders
    *String:  Received predictive orders in contrast
    waittime : timeout
    Index_location The first address to appear after the comparison is the first address.
return : sucess  or  fail
 */
uint8_t BC26_send_cmd(UART_T* uart,uint8_t *cmd,char *String,char **Index_location,uint16_t waittime)
{
  uint8_t res = TA_FAIL; 
  guRX_num =0;
  memset(gaucUsart1Buff,0,sizeof(gaucUsart1Buff));
   Send_AT_CMD(uart,cmd);   //Send out commands
    Drv_SysDelayMs(300);
      while(waittime--)
      { 
        Drv_SysDelayMs(20);//The serial port receives one byte at a byte, and every byte it receives, it detects whether the whole data it receives meets the requirements.
        if(gudComRFlag) //Receive the data and check if the data is what you want
          {       
            *Index_location = RX_BC26_CMD(gaucUsart1Buff,String);
            if( RX_BC26_CMD(gaucUsart1Buff,String))
            {
              res = TA_SUCCESS;
				break;  //It's what you want, send it over, jump out
            }
            gudComRFlag=0;   
          } 
      }
  return res;
	}
 /*
    function: BC26 Module power-on self-test 
    return : sucess  or  fail
  */ 
//uint8_t Power_ONCheckself(void)
//{
//	uint32_t Time_out = 0;
//   //NB_BC26_init();
// while(RX_BC26_CMD(gaucUsart1Buff,"Leaving"))
//  {
//   memset(gaucUsart1Buff,0,sizeof(gaucUsart1Buff));
//   return TA_SUCCESS;
//  }
//  else
//  {
//    Shutdown();
//    Drv_SysDelayMs(10);
//    NB_BC26_init();
//   if(TA_SUCCESS == RX_BC26_CMD(gaucUsart1Buff,"Leaving"))
//   {
//     memset(gaucUsart1Buff,0,sizeof(gaucUsart1Buff));
//    return TA_SUCCESS;
//   }
//   else
//   {
//     return TA_FAIL;
//   }
//  }
//  
//}
//Converting a regular string to a Hex string
uint8_t str2hex(char* str, char* hex)
{

    const char* cHex = "0123456789ABCDEF";
    int i=0,j=0;
    for( j =0; j < strlen(str); j++)
    {
        unsigned int a =  (unsigned int) str[j];
        hex[i++] = cHex[(a & 0xf0) >> 4];
        hex[i++] = cHex[(a & 0x0f)];
    }
    hex[i] ='\0';
		return i;
}
//Network Flow of NBiot Module
uint8_t BC26_DataProcess(uint8_t *NB_buffer,uint8_t NB_Length)
{ 
	uint32_t time_out = 5; 
	uint8_t Signal_Strength = 0;
	uint8_t Statue = NB_Start;
	uint16_t Hex_Data_Length = 0;
	uint8_t New_Satrt_count = 3 ; //Number of startups
	uint8_t Hex_buffer[100]={0};  // Store data converted to hex
	char *Data_Location =0;
	char *AT_cmd1= 0;    // Storage AD-cmd
	char *AT_cmd2= 0;

// If (TA_SUCCESS!= Power_ONCheckself()// Self-check failed, exit directly
//	{
//		 return TA_FAIL;
//	}
	while(1)
	{	
		if(0 == New_Satrt_count)
					return TA_FAIL;
		
		 switch(Statue)
		 {
			 case NB_Start:
				    time_out = 40;
			  //    NB_VCCDisable;
			      Drv_SysDelayMs(1000);
						NB_BC26_init();
			      while(time_out--)
						{
						  if( RX_BC26_CMD(gaucUsart1Buff,"Leaving"))
									break;
							 Drv_SysDelayMs(10);
						}
						Statue = AT;
						break;
			 case AT:    //Synchronized baud rate
				    time_out=4;
						while(time_out--)   
							{
								if(TA_SUCCESS == BC26_send_cmd(UART1,"AT\r\n","OK",&Data_Location,100)) // Timeout 2S
								{
									break;
								}
							  if( RX_BC26_CMD(gaucUsart1Buff,"+CPIN: READY"))
									break;
								if(time_out<2) // If it fails twice, restart the module
								{
									Statue = NB_Start;
									New_Satrt_count--;
									break;
								}
							}
						  if(RX_BC26_CMD(gaucUsart1Buff,"+IP:"))
							{
								Statue = AT_NCDP;
								 break;
							}
							else
							{
							  Statue = AT_CESQ;
							 break;
							}
			 case AT_CESQ:  // Check signal strength
							time_out =50;
							while(time_out--)
							{	      
								if( RX_BC26_CMD(gaucUsart1Buff,"+CPIN: READY"))
								{
	                  break;
								 }
									Drv_SysDelayMs(100);
							 } 					
							time_out = 3;
							while(time_out--) 
							{	
								if(RX_BC26_CMD(gaucUsart1Buff,"+IP:"))
								 {
										Statue = AT_NCDP;
									 break;
								 }								
								if(TA_SUCCESS == BC26_send_cmd(UART1,"AT+CESQ\r\n","+CESQ: ",&Data_Location,100)) // Timeout 2S
								{
									Signal_Strength = 10*(*(Data_Location+7) - 48)	+ (*(Data_Location+8) - 48);
									if(((*(Data_Location+7) - 48) == 0) || ((*(Data_Location+7) - 48) == 9))
									 {
											 New_Satrt_count--;
											 Statue = NB_Start;
											 break;
										}
										else
										{
										 Statue = AT_CFUN;
										 break;
										}
									}
								if(time_out<2)
								{
									Statue = NB_Start;
									New_Satrt_count--;
									break;
								}
							}
					break;
				case AT_CFUN:  // Check UE function level up to 15S 
							time_out = 2; 
							while(time_out--)    
							{
						    if(RX_BC26_CMD(gaucUsart1Buff,"+IP:"))
							  {
							  	Statue = AT_NCDP;
							 	   break;
						   	 }
								if(TA_SUCCESS == BC26_send_cmd(UART1,"AT+CFUN?\r\n","+CFUN: ",&Data_Location,750)) // Timeout 15S
								{
									Signal_Strength = (*(Data_Location+7) - 48);
									if((Signal_Strength != 1))
									{
										continue;
									 }
										else
										{
										 Statue = AT_CEREG;
										 break;
										}
									}
									else
									{
									 PSM_wake();
									}

								if(time_out<1)
								{
									Statue = NB_Start;
									New_Satrt_count--;
									break;;
								}
							}
							break;
					case  AT_CEREG: // Check whether the access is successful
							 time_out = 3;
							while(time_out--)    
							{
								 if(RX_BC26_CMD(gaucUsart1Buff,"+IP: "))
							  {
							  	Statue = AT_NCDP;
							 	   break;
						   	 }
								if(TA_SUCCESS == BC26_send_cmd(UART1,"AT+CEREG?\r\n","+CEREG: ",&Data_Location,400)) // Timeout 2S
								{   
									if(*(Data_Location+10) == '1')// join in internet sucess
									{
										 Statue = AT_CGPADDR;
										break;
									}
									else if((*(Data_Location+10) == '2') || (*(Data_Location+10) == '0') ) //looking for internet
									{
										Drv_SysDelayMs(500);
									}
								}
								if(time_out<2)
								{
									Statue = NB_Start;
									New_Satrt_count--;
									break;
								}
							}
						
							break;
					case  AT_CGPADDR:  // Get IP adress
							 time_out = 3;
							while(time_out--)    
							{
								if(TA_SUCCESS == BC26_send_cmd(UART1,"AT+CGPADDR=1\r\n","+CGPADDR: 1",&Data_Location,100)) // Timeout 2S
								{
							     Statue = AT_NCDP;									
										break;
								}
								if(time_out<2)
								{
									Statue = NB_Start;
									New_Satrt_count--;
									break;
								}
							}
							break;
				// case  AT_CGSN:  // get IMEI 
						case AT_NCDP:  //  configure network adress
						//	 Drv_SysDelayMs(7000);		
							 time_out = 2;
							 while(time_out--)
							 {    				
									if (TA_SUCCESS == BC26_send_cmd(UART1,"AT+NCDP=southbound.quectel.com,5683\r\n","OK",&Data_Location,100)) // Timeout 2S
									{
							       Statue = AT_QLWCONF;										
											break;
									}
									else
									{
										 if(time_out<1)
											{
												Statue = NB_Start;
												New_Satrt_count--;
												break;
											}
									}
							 }

							break;
						case AT_QLWCONF: // IMEI for equipment configuration
									time_out = 2;
									AT_cmd1 = "AT+QLWCONF=";
									AT_cmd2 = "866971033234043";
									memset(Hex_buffer,0,sizeof(Hex_buffer));
									Hex_Data_Length = Cmd_connect(AT_cmd1,AT_cmd2,Hex_buffer,11,15);
									 Hex_buffer[Hex_Data_Length] = 0x0D;
									 Hex_buffer[Hex_Data_Length+1] = 0x0A;
								//  UART_Write (UART1, QLWCONF_buffer, sizeof (QLWCONF_buffer); //Send out commands
								while(time_out--)
								{    				
										if (TA_SUCCESS == BC26_send_cmd(UART1,Hex_buffer,"OK",&Data_Location,100)) // Timeout 2S
										{
										   	Statue = AT_QLWADDOBJ;
													break;
										}
										else
										{
											if(time_out<1)
												{
													Statue = NB_Start;
													New_Satrt_count--;
													break;
												}
										}
								} 
							break;
							case AT_QLWADDOBJ: // Configuration 1
									time_out = 2;
									AT_cmd1 = "AT+QLWADDOBJ=19,1,1,";
									AT_cmd2 = "0";
									memset(Hex_buffer,0,sizeof(Hex_buffer));
									Hex_Data_Length = Cmd_connect(AT_cmd1,AT_cmd2,Hex_buffer,20,1);
									Hex_buffer[Hex_Data_Length]= 0x0D; //Enter            
									Hex_buffer[Hex_Data_Length+1] = 0x0A;
								while(time_out--)
								{    				
										if (TA_SUCCESS == BC26_send_cmd(UART1,Hex_buffer,"OK",&Data_Location,100)) // Timeout 2S
										{
									   	Statue = AT_QLWADDOBJ1;
												break;
										}
										else
										{
											if(time_out<1)
												{
													Statue = NB_Start;
													New_Satrt_count--;
													break;
												}
										}
								}

							break;
							case AT_QLWADDOBJ1: // Configuration 2
									
										time_out = 2;
										AT_cmd1 = "AT+QLWADDOBJ=19,0,1,";
										AT_cmd2 = "0";
										memset(Hex_buffer,0,sizeof(Hex_buffer));
										Hex_Data_Length = Cmd_connect(AT_cmd1,AT_cmd2,Hex_buffer,20,1);
										Hex_buffer[Hex_Data_Length]= 0x0D; //Enter
									while(time_out--)
									{    				
											if (TA_SUCCESS == BC26_send_cmd(UART1,Hex_buffer,"OK",&Data_Location,100)) // Timeout 2S
											{
												Statue = AT_QLWOPEN;
												break;
											}
											else
											{
												if(time_out<1)
													{
														Statue = NB_Start;
														New_Satrt_count--;
														break;
													}
											}
									}
							break;
							 case AT_QLWOPEN: //  Register to the IoT platform in direct push mode
										time_out = 2;
									while(time_out--)
									{    				
										if (TA_SUCCESS == BC26_send_cmd(UART1,"AT+QLWOPEN=0\r\n","+QLWOBSERVE:",&Data_Location,300)) // Timeout 6S
											{
												 
														break;
											}
											else
											{
												if(time_out<1)
													{
															return TA_FAIL;
													}
											}
									}
							Statue = AT_QLWCFG; // Hexadecimal system
							break;
							case AT_QLWCFG:
										time_out = 2;
										AT_cmd1 = "AT+QLWCFG=";
										AT_cmd2 = "dataformat";
										memset(Hex_buffer,0,sizeof(Hex_buffer));
										Hex_Data_Length = Cmd_connect(AT_cmd1,AT_cmd2,Hex_buffer,10,10);
										Hex_buffer[Hex_Data_Length] = 0x2c; //,
										Hex_buffer[Hex_Data_Length+1] = 0x31; //1
										Hex_buffer[Hex_Data_Length+2] = 0x2c;//,
										Hex_buffer[Hex_Data_Length+3] = 0x31; //1
										Hex_buffer[Hex_Data_Length+4]= 0x0D; //Enter
									while(time_out--)
									{    				
											if (TA_SUCCESS == BC26_send_cmd(UART1,Hex_buffer,"OK",&Data_Location,100)) // Timeout 2S
											{
												  Statue = AT_QLWDATASEND;
														break;
											}
											else
											{
												if(time_out<1)
													{
															return TA_FAIL;
													}
											}
									}
							break;
						 case AT_QLWDATASEND:  // updata
							  time_out = 3;
						 	  memset(Hex_buffer,0,sizeof(Hex_buffer)); 
						 
						    Hex_Data_Length = NB_Settle_Data(Hex_buffer,NB_buffer,NB_Length);//Data Integration
                Hex_buffer[Hex_Data_Length++] = 0x2c;//,
						    Hex_buffer[Hex_Data_Length++] = 0x30;//0
			          Hex_buffer[Hex_Data_Length++] = 0x78;//x
						    Hex_buffer[Hex_Data_Length++] = 0x30;//0
						    Hex_buffer[Hex_Data_Length++] = 0x31;//1
						    Hex_buffer[Hex_Data_Length++] = 0x30;//0
						    Hex_buffer[Hex_Data_Length++] = 0x30;//0
						 	  Hex_buffer[Hex_Data_Length++]= 0x0D; //Enter
						    Hex_buffer[Hex_Data_Length++] = 0x0A;
							   while(time_out--)
								 {    		
                     //Drv_SysDelayMs(2000);									 
										if (TA_SUCCESS == BC26_send_cmd(UART1,Hex_buffer,"SEND OK",&Data_Location,200)) // Timeout 4S
											{
													 return TA_SUCCESS;
											}
											else
											{
												if(time_out<1)
													{
															return TA_FAIL;
													}
											}
									}

			 }
	 }  
}
/*
   Function, collate data into NB recognizable normal data
   Outbuffer  [OUT] output data
   INbuf  :   Input Open Door Information
   Len :    Open Door Information Data Length
*/
uint8_t  NB_Settle_Data(uint8_t *Outbuffer,uint8_t *INbuf,uint8_t Len)
{
	uint16_t length0=0,i=0;
	char *AT_P = "AT+QLWDATASEND=19,0,0,";
	length0 = AT_Conversion_HEX(AT_P,Outbuffer,22);
	if(2*Len >9)
	{
	 Outbuffer[length0++] = (2*Len)/10 + 0x30;
	 Outbuffer[length0++] = (2*Len)%10 + 0x30;
	}
	else
	{
    Outbuffer[length0++] = Len + 0x30;
	}
	Outbuffer[length0++] = 0x2c; //,
	// data
	for(i=0;i<Len;i++)
	{
	  Outbuffer[length0++] = 0x33;
//	  if(INbuf[i]>9)
//	  {
	  Outbuffer[length0++] = INbuf[i]/10+0x30;
	  Outbuffer[length0++] = 0x33;
		Outbuffer[length0++] = INbuf[i]%10+0x30;
//	  }
//	 else
//	  Outbuffer[length0++] = INbuf[i]%10+0x30;
	}
	return length0;
}

/* function: AT TO Hex
   @param IN_buffer  AT_cmd (IN)
           length    the length of IN_buffer
           Outbuffer  Hex (out)

*/
uint16_t AT_Conversion_HEX(char *IN_buffer,uint8_t *Outbuffer,uint16_t length)
{
  char temp=0;
	uint16_t i=0;
	uint16_t Cmd_length = 0;
	Cmd_length = length ;
	
	while(Cmd_length--)
	{
      Outbuffer[i]= IN_buffer[i];
	   i++;
	}
	return i;
}
/*Link two CMD s
@param: *IN_buffer1 [IN]   cmd 1
          *IN_buffer2  [IN] cmd 2
          *Outbuffer    [out] Output hex 
          length1  [IN]     IN_buffer1 length
          length2    [IN]   IN_buffer2 length
 */
uint16_t Cmd_connect(char *IN_buffer1,char *IN_buffer2,uint8_t *Outbuffer,uint16_t length1,uint16_t lengt2)
{
	uint16_t len1 = 0;
   uint16_t len2 = 0;

    len1 = AT_Conversion_HEX(IN_buffer1,Outbuffer,length1);
    len2 = AT_Conversion_HEX(IN_buffer2, Outbuffer + len1+1 ,lengt2);
	  Outbuffer[len1] =0x22;
    Outbuffer[len1+len2+1] = 0x22;
	return (len1+len2+2);
}

 

Keywords: network

Added by bubblewrapped on Fri, 16 Aug 2019 12:21:31 +0300