Merge branch 'master' into feature/lwip_sntp_max_servers

This commit is contained in:
David Cermak
2021-08-24 18:16:07 +02:00
1400 changed files with 134414 additions and 65245 deletions
+14 -18
View File
@@ -59,33 +59,29 @@ See the Getting Started Guide for full steps to configure and use ESP-IDF to bui
## Example Output
Prerequisite: we startup a CoAP server on coap server example,
or use the default of coap://californium.eclipse.org.
or use the default of coaps://californium.eclipseprojects.io.
and you could receive data from CoAP server if succeed,
such as the following log:
```
...
I (332) wifi: mode : sta (30:ae:a4:04:1b:7c)
I (1672) wifi: n:11 0, o:1 0, ap:255 255, sta:11 0, prof:1
I (1672) wifi: state: init -> auth (b0)
I (1682) wifi: state: auth -> assoc (0)
I (1692) wifi: state: assoc -> run (10)
I (1692) wifi: connected with huawei_cw, channel 11
I (1692) wifi: pm start, type: 1
I (2582) event: sta ip: 192.168.3.89, mask: 255.255.255.0, gw: 192.168.3.1
I (2582) CoAP_client: Connected to AP
I (2582) CoAP_client: DNS lookup succeeded. IP=104.196.15.150
I (5104) esp_netif_handlers: example_connect: sta ip: 192.168.0.103, mask: 255.255.255.0, gw: 192.168.0.1
I (5104) example_connect: Got IPv4 event: Interface "example_connect: sta" address: 192.168.0.103
I (5604) example_connect: Got IPv6 event: Interface "example_connect: sta" address: fe80:0000:0000:0000:32ae:a4ff:fec5:3234, type: ESP_IP6_ADDR_IS_LINK_LOCAL
I (5604) example_connect: Connected to example_connect: sta
I (5614) example_connect: - IPv4 address: 192.168.0.103
I (5614) example_connect: - IPv6 address: fe80:0000:0000:0000:32ae:a4ff:fec5:3234, type: ESP_IP6_ADDR_IS_LINK_LOCAL
I (6004) CoAP_client: DNS lookup succeeded. IP=35.185.40.182
Received:
************************************************************
CoAP RFC 7252 Cf 2.0.0-SNAPSHOT
************************************************************
****************************************************************
CoAP RFC 7252 Cf 3.0.0-SNAPSHOT
****************************************************************
This server is using the Eclipse Californium (Cf) CoAP framework
published under EPL+EDL: http://www.eclipse.org/californium/
(c) 2014, 2015, 2016 Institute for Pervasive Computing, ETH Zurich and others
************************************************************
(c) 2014-2020 Institute for Pervasive Computing, ETH Zurich and others
****************************************************************
...
```
@@ -96,6 +92,6 @@ This can be found at https://libcoap.net/doc/reference/4.2.0/
* Please make sure Target Url includes valid `host`, optional `port`,
optional `path`, and begins with `coap://`, `coaps://` or `coap+tcp://`
for a coap server that supports TCP
(not all do including coap+tcp://californium.eclipse.org).
(not all do including coap+tcp://californium.eclipseprojects.io).
* CoAP logging can be enabled by running 'idf.py menuconfig -> Component config -> CoAP Configuration' and setting appropriate log level
@@ -2,7 +2,7 @@ menu "Example CoAP Client Configuration"
config EXAMPLE_TARGET_DOMAIN_URI
string "Target Uri"
default "coaps://californium.eclipse.org"
default "coaps://californium.eclipseprojects.io"
help
Target uri for the example to use. Use coaps:// prefix for encrypted traffic
using Pre-Shared Key (PSK) or Public Key Infrastructure (PKI).
@@ -85,29 +85,30 @@ static const char * if_str[] = {"STA", "AP", "ETH", "MAX"};
/* these strings match mdns_ip_protocol_t enumeration */
static const char * ip_protocol_str[] = {"V4", "V6", "MAX"};
static void mdns_print_results(mdns_result_t * results){
mdns_result_t * r = results;
mdns_ip_addr_t * a = NULL;
static void mdns_print_results(mdns_result_t *results)
{
mdns_result_t *r = results;
mdns_ip_addr_t *a = NULL;
int i = 1, t;
while(r){
printf("%d: Interface: %s, Type: %s\n", i++, if_str[r->tcpip_if], ip_protocol_str[r->ip_protocol]);
if(r->instance_name){
printf(" PTR : %s\n", r->instance_name);
while (r) {
printf("%d: Interface: %s, Type: %s, TTL: %u\n", i++, if_str[r->tcpip_if], ip_protocol_str[r->ip_protocol],
r->ttl);
if (r->instance_name) {
printf(" PTR : %s.%s.%s\n", r->instance_name, r->service_type, r->proto);
}
if(r->hostname){
if (r->hostname) {
printf(" SRV : %s.local:%u\n", r->hostname, r->port);
}
if(r->txt_count){
if (r->txt_count) {
printf(" TXT : [%zu] ", r->txt_count);
for(t=0; t<r->txt_count; t++){
printf("%s=%s(%d); ", r->txt[t].key, r->txt[t].value?r->txt[t].value:"NULL",
r->txt_value_len[t]);
for (t = 0; t < r->txt_count; t++) {
printf("%s=%s(%d); ", r->txt[t].key, r->txt[t].value ? r->txt[t].value : "NULL", r->txt_value_len[t]);
}
printf("\n");
}
a = r->addr;
while(a){
if(a->addr.type == ESP_IPADDR_TYPE_V6){
while (a) {
if (a->addr.type == ESP_IPADDR_TYPE_V6) {
printf(" AAAA: " IPV6STR "\n", IPV62STR(a->addr.u_addr.ip6));
} else {
printf(" A : " IPSTR "\n", IP2STR(&(a->addr.u_addr.ip4)));
@@ -116,7 +117,6 @@ static void mdns_print_results(mdns_result_t * results){
}
r = r->next;
}
}
static void query_mdns_service(const char * service_name, const char * proto)
+1 -1
View File
@@ -14,7 +14,7 @@ When PPP connection has been established, the IP packet flow from application si
### Hardware Required
To run this example, you need an ESP32 dev board (e.g. ESP32-WROVER Kit) or ESP32 core board (e.g. ESP32-DevKitC).
For test purpose, you also need a cellular modem module. Here we take the [SIM800L](https://www.simcom.com/product/SIM800.html) and [BG96](https://www.quectel.com/product/bg96.htm) as an example.
For test purpose, you also need a cellular modem module. Here we take the [SIM800L](https://www.simcom.com/product/SIM800.html) and [BG96](https://www.quectel.com/product/lpwa-bg96-cat-m1-nb1-egprs/) as an example.
You can also try other modules as long as they embedded PPP protocol.
**Note:** Since SIM800L only support **2G** which will **not** work in some countries. And also keep in mind that in some other countries it will stop working soon (many remaining 2G networks will be switched off in the next 2-3 years). So you should **check with your local providers for further details** if you try this example with any 2G modules.
@@ -61,28 +61,6 @@ static inline void strip_cr_lf_tail(char *str, uint32_t len)
*/
esp_err_t esp_modem_dce_handle_response_default(modem_dce_t *dce, const char *line);
/**
* @brief Handle response from AT+CSQ (Get signal quality)
*
* @param dce Modem DCE object
* @param line line string
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_dce_handle_csq(modem_dce_t *dce, const char *line);
/**
* @brief Handle response from AT+CBC (Get battery status)
*
* @param dce Modem DCE object
* @param line line string
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_dce_handle_cbc(modem_dce_t *dce, const char *line);
/**
* @brief Handle response from +++ (Set Working Mode)
*
@@ -105,50 +83,6 @@ esp_err_t esp_modem_dce_handle_exit_data_mode(modem_dce_t *dce, const char *line
*/
esp_err_t esp_modem_dce_handle_atd_ppp(modem_dce_t *dce, const char *line);
/**
* @brief Handle response from AT+CGMM (Get DCE module name)
*
* @param dce Modem DCE object
* @param line line string
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_dce_handle_cgmm(modem_dce_t *dce, const char *line);
/**
* @brief Handle response from AT+CGSN (Get DCE module IMEI number)
*
* @param dce Modem DCE object
* @param line line string
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_dce_handle_cgsn(modem_dce_t *dce, const char *line);
/**
* @brief Handle response from AT+CIMI (Get DCE module IMSI number)
*
* @param dce Modem DCE object
* @param line line string
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_dce_handle_cimi(modem_dce_t *dce, const char *line);
/**
* @brief Handle response from AT+COPS? (Get Operator's name)
*
* @param dce Modem DCE object
* @param line line string
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_dce_handle_cops(modem_dce_t *dce, const char *line);
/**
* @brief Syncronization
*
@@ -42,7 +42,11 @@ esp_err_t esp_modem_dce_handle_response_default(modem_dce_t *dce, const char *li
return err;
}
esp_err_t esp_modem_dce_handle_csq(modem_dce_t *dce, const char *line)
/**
* @brief Handle response from AT+CSQ (Get signal quality)
*
*/
static esp_err_t esp_modem_dce_handle_csq(modem_dce_t *dce, const char *line)
{
esp_err_t err = ESP_FAIL;
esp_modem_dce_t *esp_dce = __containerof(dce, esp_modem_dce_t, parent);
@@ -60,7 +64,11 @@ esp_err_t esp_modem_dce_handle_csq(modem_dce_t *dce, const char *line)
return err;
}
esp_err_t esp_modem_dce_handle_cbc(modem_dce_t *dce, const char *line)
/**
* @brief Handle response from AT+CBC (Get battery status)
*
*/
static esp_err_t esp_modem_dce_handle_cbc(modem_dce_t *dce, const char *line)
{
esp_err_t err = ESP_FAIL;
esp_modem_dce_t *esp_dce = __containerof(dce, esp_modem_dce_t, parent);
@@ -102,7 +110,11 @@ esp_err_t esp_modem_dce_handle_atd_ppp(modem_dce_t *dce, const char *line)
return err;
}
esp_err_t esp_modem_dce_handle_cgmm(modem_dce_t *dce, const char *line)
/**
* @brief Handle response from AT+CGMM (Get DCE module name)
*
*/
static esp_err_t esp_modem_dce_handle_cgmm(modem_dce_t *dce, const char *line)
{
esp_err_t err = ESP_FAIL;
if (strstr(line, MODEM_RESULT_CODE_SUCCESS)) {
@@ -120,7 +132,11 @@ esp_err_t esp_modem_dce_handle_cgmm(modem_dce_t *dce, const char *line)
return err;
}
esp_err_t esp_modem_dce_handle_cgsn(modem_dce_t *dce, const char *line)
/**
* @brief Handle response from AT+CGSN (Get DCE module IMEI number)
*
*/
static esp_err_t esp_modem_dce_handle_cgsn(modem_dce_t *dce, const char *line)
{
esp_err_t err = ESP_FAIL;
if (strstr(line, MODEM_RESULT_CODE_SUCCESS)) {
@@ -138,7 +154,11 @@ esp_err_t esp_modem_dce_handle_cgsn(modem_dce_t *dce, const char *line)
return err;
}
esp_err_t esp_modem_dce_handle_cimi(modem_dce_t *dce, const char *line)
/**
* @brief Handle response from AT+CIMI (Get DCE module IMSI number)
*
*/
static esp_err_t esp_modem_dce_handle_cimi(modem_dce_t *dce, const char *line)
{
esp_err_t err = ESP_FAIL;
if (strstr(line, MODEM_RESULT_CODE_SUCCESS)) {
@@ -156,7 +176,11 @@ esp_err_t esp_modem_dce_handle_cimi(modem_dce_t *dce, const char *line)
return err;
}
esp_err_t esp_modem_dce_handle_cops(modem_dce_t *dce, const char *line)
/**
* @brief Handle response from AT+COPS? (Get Operator's name)
*
*/
static esp_err_t esp_modem_dce_handle_cops(modem_dce_t *dce, const char *line)
{
esp_err_t err = ESP_FAIL;
if (strstr(line, MODEM_RESULT_CODE_SUCCESS)) {
+7
View File
@@ -21,6 +21,12 @@ Set following parameters under Example Configuration Options:
* Set `Static gateway address` of your device static gateway address.
* Set `Choose DNS server` with `Set manual value as DNS server` or `Use gateway address as DNS server` to configure your DNS server.
* Choose `Set manual value as DNS server` to configure manual DNS server with `Main DNS server address` and `Backup DNS server address`.
* Set `Enable DNS resolve test` to resolve your host which input in `Domain name to resolve`.
### Build and Flash
Build the project and flash it to the board, then run monitor tool to view serial output:
@@ -82,4 +88,5 @@ I (3253) static_ip: connected to ap SSID:myssid password:mypassword
W (3273) wifi:<ba-add>idx:0 (ifx:0, 34:29:12:43:c5:40), tid:5, ssn:2, winSize:64
I (3303) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (3303) wifi:new:<11,0>, old:<11,2>, ap:<255,255>, sta:<11,0>, prof:1
I (5203) static_ip: Resolved IPv4 address: 119.9.92.99
```
@@ -35,4 +35,47 @@ menu "Example Configuration"
default "192.168.4.1"
help
Set static gateway address.
choice EXAMPLE_STATIC_DNS_SERVER
prompt "Choose DNS server"
default EXAMPLE_STATIC_DNS_AUTO
help
Select auto to make gateway address as DNS server or manual to input your DNS server
config EXAMPLE_STATIC_DNS_AUTO
bool "Use gateway address as DNS server"
help
Set DNS server the same as gateway address
config EXAMPLE_STATIC_DNS_MANUAL
bool "Set manual value as DNS server"
help
Set DNS server with you want
endchoice
config EXAMPLE_STATIC_DNS_SERVER_MAIN
string "Main DNS server address"
default "192.168.4.1"
depends on EXAMPLE_STATIC_DNS_MANUAL
help
Set main DNS server address.
config EXAMPLE_STATIC_DNS_SERVER_BACKUP
string "Backup DNS server address"
default "192.168.4.1"
depends on EXAMPLE_STATIC_DNS_MANUAL
help
Set backup DNS server address. It can be same with the main DNS server address or leave empty.
config EXAMPLE_STATIC_DNS_RESOLVE_TEST
bool "Enable DNS resolve test"
default n
help
Enable it and configure EXAMPLE_STATIC_RESOLVE_DOMAIN to resolve DNS domain name
config EXAMPLE_STATIC_RESOLVE_DOMAIN
string "Domain name to resolve"
default "www.espressif.com"
depends on EXAMPLE_STATIC_DNS_RESOLVE_TEST
help
Set domain name for DNS test
endmenu
@@ -14,6 +14,7 @@
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include <netdb.h>
#include "nvs_flash.h"
/* The examples use configuration that you can set via project configuration menu
@@ -27,7 +28,16 @@
#define EXAMPLE_STATIC_IP_ADDR CONFIG_EXAMPLE_STATIC_IP_ADDR
#define EXAMPLE_STATIC_NETMASK_ADDR CONFIG_EXAMPLE_STATIC_NETMASK_ADDR
#define EXAMPLE_STATIC_GW_ADDR CONFIG_EXAMPLE_STATIC_GW_ADDR
#ifdef CONFIG_EXAMPLE_STATIC_DNS_AUTO
#define EXAMPLE_MAIN_DNS_SERVER EXAMPLE_STATIC_GW_ADDR
#define EXAMPLE_BACKUP_DNS_SERVER "0.0.0.0"
#else
#define EXAMPLE_MAIN_DNS_SERVER CONFIG_EXAMPLE_STATIC_DNS_SERVER_MAIN
#define EXAMPLE_BACKUP_DNS_SERVER CONFIG_EXAMPLE_STATIC_DNS_SERVER_BACKUP
#endif
#ifdef CONFIG_EXAMPLE_STATIC_DNS_RESOLVE_TEST
#define EXAMPLE_RESOLVE_DOMAIN CONFIG_EXAMPLE_STATIC_RESOLVE_DOMAIN
#endif
/* FreeRTOS event group to signal when we are connected*/
static EventGroupHandle_t s_wifi_event_group;
@@ -41,6 +51,17 @@ static const char *TAG = "static_ip";
static int s_retry_num = 0;
static esp_err_t example_set_dns_server(esp_netif_t *netif, uint32_t addr, esp_netif_dns_type_t type)
{
if (addr && (addr != IPADDR_NONE)) {
esp_netif_dns_info_t dns;
dns.ip.u_addr.ip4.addr = addr;
dns.ip.type = IPADDR_TYPE_V4;
ESP_ERROR_CHECK(esp_netif_set_dns_info(netif, type, &dns));
}
return ESP_OK;
}
static void example_set_static_ip(esp_netif_t *netif)
{
if (esp_netif_dhcpc_stop(netif) != ESP_OK) {
@@ -57,6 +78,8 @@ static void example_set_static_ip(esp_netif_t *netif)
return;
}
ESP_LOGD(TAG, "Success to set static ip: %s, netmask: %s, gw: %s", EXAMPLE_STATIC_IP_ADDR, EXAMPLE_STATIC_NETMASK_ADDR, EXAMPLE_STATIC_GW_ADDR);
ESP_ERROR_CHECK(example_set_dns_server(netif, ipaddr_addr(EXAMPLE_MAIN_DNS_SERVER), ESP_NETIF_DNS_MAIN));
ESP_ERROR_CHECK(example_set_dns_server(netif, ipaddr_addr(EXAMPLE_BACKUP_DNS_SERVER), ESP_NETIF_DNS_BACKUP));
}
static void event_handler(void* arg, esp_event_base_t event_base,
@@ -150,7 +173,30 @@ void wifi_init_sta(void)
} else {
ESP_LOGE(TAG, "UNEXPECTED EVENT");
}
#ifdef CONFIG_EXAMPLE_STATIC_DNS_RESOLVE_TEST
struct addrinfo *address_info;
struct addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
int res = getaddrinfo(EXAMPLE_RESOLVE_DOMAIN, NULL, &hints, &address_info);
if (res != 0 || address_info == NULL) {
ESP_LOGE(TAG, "couldn't get hostname for :%s: "
"getaddrinfo() returns %d, addrinfo=%p", EXAMPLE_RESOLVE_DOMAIN, res, address_info);
} else {
if (address_info->ai_family == AF_INET) {
struct sockaddr_in *p = (struct sockaddr_in *)address_info->ai_addr;
ESP_LOGI(TAG, "Resolved IPv4 address: %s", ipaddr_ntoa((const ip_addr_t*)&p->sin_addr.s_addr));
}
#if CONFIG_LWIP_IPV6
else if (address_info->ai_family == AF_INET6) {
struct sockaddr_in6 *p = (struct sockaddr_in6 *)address_info->ai_addr;
ESP_LOGI(TAG, "Resolved IPv6 address: %s", ip6addr_ntoa((const ip6_addr_t*)&p->sin6_addr));
}
#endif
}
#endif
/* The event will not be processed after unregister */
ESP_ERROR_CHECK(esp_event_handler_instance_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, instance_got_ip));
ESP_ERROR_CHECK(esp_event_handler_instance_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, instance_any_id));