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

How to use socket?

<Environment>
- Windows10
- nrf v1.3.0
- modem fw 1.2.0

I'm attempting to make a socket and communicate with the modem using it.

However, sending data doesn't work out. It was working in v1.2.0. Any tip?

I don't want to use at_cmd.c becuase I need a exclusive  socket for SMS notification.

<main.c>

#include <zephyr.h>
#include <stdio.h>
#include <net/socket.h>
#include <modem/lte_lc.h>

#define BUF_LEN 128

int fd;

void main(){
    int ret;
    char at_cmd[] = "AT\n";
    char buf[BUF_LEN];
    
	/* Configure LTE-M */
    printk("LTE Link Connecting ...\n");
    ret = lte_lc_init_and_connect();
    printk("LTE Link Connected!\n");
	if (ret) {
		printk("Error: modem_configure\n");
		return;
	}

	/* SMS socket set up*/
	fd = socket(AF_LTE, 0, NPROTO_AT); /* init fd */
	if (fd == -1) {
		return;
	}

	// Send AT command => ERROR !!
	if (send(fd, at_cmd, strlen(at_cmd), 0) <= 0) {
        printk("Error: send\n");
        return;
    }

	// blocking receive
	if (recv(fd, buf, BUF_LEN, MSG_DONTWAIT) <= 0) {
        printk("Error: send\n");
        return;
    }

    printk("Socket works out!\n");
    
    return;
}

Parents Reply
  • in sms.h

    /**
     * @brief Register a new listener.
     *
     * A listener is identified by a unique handle value. This handle should be used
     * to unregister the listener. A listener can be registered multiple times with
     * the same or a different context.
     *
     * @param listener Callback function. Cannot be null.
     * @param context User context. Can be null if not used.
     *
     * @retval -EINVAL Invalid parameter.
     * @retval -ENOMEM No memory to register new observers.
     * @return Handle identifying the listener,
     *         or a negative value if an error occurred.
     */
    int sms_register_listener(sms_callback_t listener, void *context);

    *The handle should be used to unregister the listener

    => what does this mean?

    I would like to keep registering SMS notification. In this case, do you have to unregister it every time the handler is called?

Children
No Data
Related