Hello,
i work on nrf9160 dk
I would like to know if it is possible to use an AT firmware to be able to easily switch to LTE-M, NB-IOT, send sms, switch off the modem etc.... and also to make http post as on the example "http sample" which works very well.
I tried the firmware "simple_at" which works well too but by combining the two, nothing works anymore.
/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
*/
#include <zephyr.h>
#include <stdio.h>
#include <drivers/uart.h>
#include <string.h>
#include <zephyr.h>
#include <net/socket.h>
#define HTTP_HOST "google.com"
#define HTTP_PORT 80
#define RECV_BUF_SIZE 1024
char recv_buf[RECV_BUF_SIZE + 1];
/**@brief Recoverable BSD library error. */
void bsd_recoverable_error_handler(uint32_t err)
{
printk("bsdlib recoverable error: %u\n", err);
}
/**@brief HTTP function */
int blocking_recv(int fd, u8_t *buf, u32_t size, u32_t flags)
{
int err;
do {
err = recv(fd, buf, size, flags);
} while (err < 0 && errno == EAGAIN);
return err;
}
int blocking_send(int fd, u8_t *buf, u32_t size, u32_t flags)
{
int err;
do {
err = send(fd, buf, size, flags);
} while (err < 0 && errno == EAGAIN);
return err;
}
int blocking_connect(int fd, struct sockaddr *local_addr, socklen_t len)
{
int err;
do {
err = connect(fd, local_addr, len);
} while (err < 0 && errno == EAGAIN);
return err;
}
const char *at_commands[] = {
"AT+CFUN?", "AT+CFUN=1", "AT+CFUN?",
/* Add more here if needed */
};
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++) {
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", recv_buf);
}
}
}
printk("Closing socket\n\r");
(void)close(at_socket_fd);
}
void app_http_start(void)
{
struct sockaddr_in local_addr;
struct addrinfo *res;
local_addr.sin_family = AF_INET;
local_addr.sin_port = htons(0);
local_addr.sin_addr.s_addr = 0;
printk("HTTP example\n\r");
int err = getaddrinfo(HTTP_HOST, NULL, NULL, &res);
printk("getaddrinfo err: %d\n\r", err);
((struct sockaddr_in *)res->ai_addr)->sin_port = htons(HTTP_PORT);
char send_buf[] =
//"GET / HTTP/1.1\r\nHost: www.google.com:80\r\nConnection: close\r\n\r\n";
"POST / HTTP/1.0\r\nHost: www.google.com:80\r\nContent-Type: application/json\r\nContent-Length: 41\r\n\r\n\{\"payload\": \"trame NBIOT de nrf9160 v01\"\}\x1A";
int send_data_len = strlen(send_buf);
int client_fd = socket(AF_INET, SOCK_STREAM, 0);
printk("client_fd: %d\n\r", client_fd);
err = bind(client_fd, (struct sockaddr *)&local_addr,
sizeof(local_addr));
printk("bind err: %d\n\r", err);
err = blocking_connect(client_fd, (struct sockaddr *)res->ai_addr,
sizeof(struct sockaddr_in));
printk("connect err: %d\n\r", err);
int num_bytes = send(client_fd, send_buf, send_data_len, 0);
printk("send err: %d\n\r", num_bytes);
int tot_num_bytes = 0;
do {
/* TODO: make a proper timeout *
* Current solution will just hang
* until remote side closes connection */
num_bytes =
blocking_recv(client_fd, recv_buf, RECV_BUF_SIZE, 0);
tot_num_bytes += num_bytes;
if (num_bytes <= 0) {
break;
}
printk("%s", recv_buf);
} while (num_bytes > 0);
printk("\n\rFinished. Closing socket");
freeaddrinfo(res);
err = close(client_fd);
}
void main(void)
{
printk("The AT \n");
app_socket_start();
printk("The AT 1\n");
// app_http_start();
printk("The AT Maxime2\n");
}