Dear All,
I am trying to integrate the simple_at example to my own application, in order to be able to configure the modem in the beginning and then run my code.
I can run the example on its own and run it without an issue. The same goes for my application. But when I try to combine the 2, then I get the following message:
Exception occurred in Secure State ***** HARD FAULT ***** Fault escalation (see below) ***** BUS FAULT ***** Precise data bus error BFAR Address: 0x50008120 ***** Hardware exception ***** Current thread ID = 0x200201b4 Faulting instruction address = 0x2fabc Fatal fault in ISR! Spinning...
I am using tag v 0.4.0 and the nRF9160 DK.
What I am actually doing is the following:
Use the void app_socket_start() from the example as is (adding a few more at commands that I need to add in the at_commands array).
void app_socket_start(void) { int at_socket_fd = socket(AF_LTE, 0, NPROTO_AT); printk("Starting simple AT socket application\n\r"); if (at_socket_fd < 0) { printk("Socket err: %d, errno: %d\r\n", at_socket_fd, errno); } for (int i = 0; i < ARRAY_SIZE(at_commands); i++) { wdt_feed(wdt, wdt_channel_id); int bytes_written = send(at_socket_fd, at_commands[i], strlen(at_commands[i]), 0); if (bytes_written > 0) { int r_bytes = blocking_recv(at_socket_fd, recv_buf, sizeof(recv_buf), MSG_DONTWAIT); if (r_bytes > 0) { printk("%s\n", at_commands[i]); printk("%s", recv_buf); } } } printk("Closing socket\n\r"); close(at_socket_fd); // int err; // int k = 0; // while (k < 10){ // err = close(at_socket_fd); // printk("Closing err: %d\n", err); // wdt_feed(wdt, wdt_channel_id); // k_sleep(1000); // k++; } } }
Then I am sending a UDP message like this:
void app_send_udp_message(u8_t *buffer, ssize_t size) { int err; struct addrinfo *dest_addr; err = getaddrinfo(HOST, NULL, NULL, &dest_addr); if (err < 0) { printk("getaddrinfo err: %d\n\r", err); } if (err != -1) { ((struct sockaddr_in *)dest_addr->ai_addr)->sin_port = htons(UDP_PORT); ((struct sockaddr_in *)dest_addr->ai_addr)->sin_family = AF_INET; int socket_sender_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); printk("Success until here\n\n\n\n"); if (socket_sender_fd < 0) { printk("socket_sender_fd: %d\n", socket_listener_fd); } printk("Sending UDP Message\n"); err = sendto(socket_sender_fd, buffer, size, MSG_DONTWAIT, (struct sockaddr *)dest_addr->ai_addr, sizeof((struct sockaddr *)dest_addr->ai_addr)); if (err < 0) { printk("Sending response err: %d errno: %d\n", err, errno); } ssize_t count = blocking_recv(socket_sender_fd, recv_buf, sizeof(recv_buf) - 1, 0); if (socket_sender_fd != -1) { (void)close(socket_sender_fd); } freeaddrinfo(dest_addr); } }
What I noticed is that if I add a long delay after closing the socket that I open in the app_socket_start() (un-commenting the last lines in the app_socket start()), then the program doesn't crush. But I haven't found a way to make my code wait until that socket is properly closed in order to allow my code to continue.
Any ideas on how to best tackle this issue?