<environment>
- Windows10
- modem fw v1.2.0
- nrf v1.3.0
I try to receive "OK" message after sending an AT command "AT+CFUN=1" using at_cmd.c functions but can't receive it.
How can I do that?
This doesn't work
#include <modem/at_cmd.h> #define RX_BUF_LEN 256 char buf[RX_BUF_LEN]; void main() { int ret = 0; enum at_cmd_state state; if (at_cmd_init() != 0) { printk("Error: ret = %d\n", ret); } ret = at_cmd_write("AT+CFUN=1", buf, RX_BUF_LEN, &state); printk("---------\n%s\n%s", "AT+CFUN=1", buf); if (ret != 0) { printk("Error: ret = %d\n", ret); } . . . }
Then I used semaphore and and at_notif.c referring to lte_lc.c but at_handler doesn't receive a message.
What's the difference between at_cmd_write_with_callback and at_notif_register_handler?
#include <zephyr.h> #include <string.h> #include <stdio.h> #include <modem/lte_lc.h> #include <modem/at_cmd.h> #define RX_BUF_LEN 256 char buf[RX_BUF_LEN]; static struct k_sem link; static void at_handler(void *context, const char *response) static void at_handler(void *context, const char *response) { ARG_UNUSED(context); if (response == NULL) { printk("Response buffer is NULL-pointer\n"); return; } printk("%s\n",response); k_sem_give(&link); } void main() { int ret = 0; enum at_cmd_state state; k_sem_init(&link, 0, 1); at_notif_init(); if (at_cmd_init() != 0) { printk("Error: ret = %d\n", ret); } ret = at_notif_register_handler(NULL, at_handler); if (ret) { printk("Can't register AT handler, error: %d\n", ret); return; } ret = at_cmd_write("AT+CFUN=1", NULL, 0, NULL); printk("%s\n", "AT+CFUN=1"); if (ret < 0) { printk("Error: ret = %d\n", ret); return; } ret = k_sem_take(&link, K_SECONDS(60)); if (ret == -EAGAIN) { printk("Network connection attempt timed out\n"); return; }
Any tip?