This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF9160 scripting AT commands

Hello,

I'm having an issue with scripting AT comands directly into the code of the nRF9160. I'm a novice at all this so I apologise if the mistake is an obvious one.

Inside the at_client.c, I have added another function that is called every ten seconds with the aim to change the status of the modem from on start-up CFUN=4 to CFUN=1. To do this I have looked at how the at_client code handles incoming UART messages and added a static const char with the value of "AT+CFUN=1* and altered the normal UART code to allow this function to run this char as if it was the incoming UART response. I'm aware that this only needs to be done once but it's just to get me started with a scripted command. Below is the function added to at_client.c

void at_test_handler(void)
{
  static const char check[] = "AT+CFUN=1";
	static int buff_size = strlen(check);
	at_rdy = true;
	static u8_t at_read_buff[UART_RX_BUF_SIZE];
	if (at_rdy) {
		uart_irq_rx_disable(uart_dev);
		at_rdy = false;
		at_host_at_socket_write(check, buff_size);
		printk("all ok\r\n");
		uart_irq_rx_enable(uart_dev);
	}
	/* Read AT socket in non-blocking mode. */
	int r_bytes = recv(at_socket_fd, at_read_buff, sizeof(at_read_buff),
				 MSG_DONTWAIT);
	/* Forward the data over UART if any. */
	/* If no data, errno is set to EGAIN and we will try again. */
	if (r_bytes > 0) {
		/* Poll out what is in the buffer gathered from the modem */
		for (size_t i = 0; i < r_bytes; i++) {
			uart_poll_out(uart_dev, at_read_buff[i]);
		}
	}
}

This function was then added to the at_client.h so it can be called and then attached to a Zephyr timer in the main.c code. Below is the timer code added into the main function of main.c.

	struct k_timer my_timer;

	void my_work_handler(struct k_timer *timer_1)
	{
		at_test_handler();
    printk("timer triggered!\r\n");
	}

	k_timer_init(&my_timer, my_work_handler, NULL);
	k_timer_start(&my_timer, K_SECONDS(5), K_SECONDS(5));

I can see the timer is calling the function as both printk lines are fired out to the UART (using minicom) as it calls the function but the actual AT command doesn't seem to trigger a UART response or a change in the modem status. Below is the UART output from reset. AT+CFUN? command entered by myself via minicom.

***** Booting Zephyr OS v1.13.99-ncs2 *****                                     
Secure Boot: configure flash                                                    
Secure Boot: SPU: set region 0 as Secure                                        
Secure Boot: SPU: set region 1 as Secure                                        
Secure Boot: SPU: set region 2 as Secure                                        
Secure Boot: SPU: set region 3 as Secure                                        
Secure Boot: SPU: set region 4 as Secure                                        
Secure Boot: SPU: set region 5 as Secure                                        
Secure Boot: SPU: set region 6 as Secure                                        
Secure Boot: SPU: set region 7 as Secure                                        
Secure Boot: SPU: set Flash region 8 as Non-Secure                              
Secure Boot: SPU: set Flash region 9 as Non-Secure                              
Secure Boot: SPU: set Flash region 10 as Non-Secure                             
Secure Boot: SPU: set Flash region 11 as Non-Secure                             
Secure Boot: SPU: set Flash region 12 as Non-Secure                             
Secure Boot: SPU: set Flash region 13 as Non-Secure                             
Secure Boot: SPU: set Flash region 14 as Non-Secure                             
Secure Boot: SPU: set Flash region 15 as Non-Secure                             
Secure Boot: SPU: set Flash region 16 as Non-Secure                             
Secure Boot: SPU: set Flash region 17 as Non-Secure                             
Secure Boot: SPU: set Flash region 18 as Non-Secure                             
Secure Boot: SPU: set Flash region 19 as Non-Secure                             
Secure Boot: SPU: set Flash region 20 as Non-Secure                             
Secure Boot: SPU: set Flash region 21 as Non-Secure                             
Secure Boot: SPU: set Flash region 22 as Non-Secure                             
Secure Boot: SPU: set Flash region 23 as Non-Secure                             
Secure Boot: SPU: set Flash region 24 as Non-Secure                             
Secure Boot: SPU: set Flash region 25 as Non-Secure                             
Secure Boot: SPU: set Flash region 26 as Non-Secure                             
Secure Boot: SPU: set Flash region 27 as Non-Secure                             
Secure Boot: SPU: set Flash region 28 as Non-Secure                             
Secure Boot: SPU: set Flash region 29 as Non-Secure                             
Secure Boot: SPU: set Flash region 30 as Non-Secure                             
Secure Boot: SPU: set Flash region 31 as Non-Secure                             
Secure Boot: configure SRAM                                                     
Secure Boot: SPU: set SRAM region 0 as Secure                                   
Secure Boot: SPU: set SRAM region 1 as Secure                                   
Secure Boot: SPU: set SRAM region 2 as Secure                                   
Secure Boot: SPU: set SRAM region 3 as Secure                                   
Secure Boot: SPU: set SRAM region 4 as Secure                                   
Secure Boot: SPU: set SRAM region 5 as Secure                                   
Secure Boot: SPU: set SRAM region 6 as Secure                                   
Secure Boot: SPU: set SRAM region 7 as Secure                                   
Secure Boot: SPU: set SRAM region 8 as Non-Secure                               
Secure Boot: SPU: set SRAM region 9 as Non-Secure                               
Secure Boot: SPU: set SRAM region 10 as Non-Secure                              
Secure Boot: SPU: set SRAM region 11 as Non-Secure                              
Secure Boot: SPU: set SRAM region 12 as Non-Secure                              
Secure Boot: SPU: set SRAM region 13 as Non-Secure                              
Secure Boot: SPU: set SRAM region 14 as Non-Secure                              
Secure Boot: SPU: set SRAM region 15 as Non-Secure                              
Secure Boot: SPU: set SRAM region 16 as Non-Secure                              
Secure Boot: SPU: set SRAM region 17 as Non-Secure                              
Secure Boot: SPU: set SRAM region 18 as Non-Secure                              
Secure Boot: SPU: set SRAM region 19 as Non-Secure                              
Secure Boot: SPU: set SRAM region 20 as Non-Secure                              
Secure Boot: SPU: set SRAM region 21 as Non-Secure                              
Secure Boot: SPU: set SRAM region 22 as Non-Secure                              
Secure Boot: SPU: set SRAM region 23 as Non-Secure                              
Secure Boot: SPU: set SRAM region 24 as Non-Secure                              
Secure Boot: SPU: set SRAM region 25 as Non-Secure                              
Secure Boot: SPU: set SRAM region 26 as Non-Secure                              
Secure Boot: SPU: set SRAM region 27 as Non-Secure                              
Secure Boot: SPU: set SRAM region 28 as Non-Secure                              
Secure Boot: SPU: set SRAM region 29 as Non-Secure                              
Secure Boot: SPU: set SRAM region 30 as Non-Secure                              
Secure Boot: SPU: set SRAM region 31 as Non-Secure                              
Secure Boot: configure peripherals                                              
Secure Boot: MSP_NS 200275f0                                                    
Secure Boot: prepare to jump to Non-Secure image                                
***** Booting Zephyr OS v1.13.99-ncs2 *****                                     
The AT host sample started                                                      
AT+CFUN?                                                                        
+CFUN: 4                                                                        
OK                                                                              
all ok                                                                          
timer triggered!                                                                
AT+CFUN?                                                                        
+CFUN: 4                                                                        
OK                                                                              
all ok                                                                          
timer triggered!                                                                
all ok                                                                          
timer triggered!                                                                
a

I have tried something similar with the asset_tracker by attaching a timer to call a custom fucntion I embedded into the lte_lc.c code, this appears to crash/hang the application when the timer triggers. I even tried changing from the custom function to the lte_lc_normal function that does the same task and it also just collasped the application. The normal configuration lines of the asset_tracker were commented out to allow the timer to be the only function called for the modem instead of lte_lc_init_and _connect.

Many thanks for any help,

Michael

Related