mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-08 07:04:32 +02:00
example: fix CI error of coap server demo
This commit is contained in:
@@ -1,12 +1,5 @@
|
|||||||
menu "Example Configuration"
|
menu "Example Configuration"
|
||||||
|
|
||||||
config LOCAL_PORT_NUMBER
|
|
||||||
int "Local port number"
|
|
||||||
range 0 65535
|
|
||||||
default 5683
|
|
||||||
help
|
|
||||||
Local port number for the example to use.
|
|
||||||
|
|
||||||
config WIFI_SSID
|
config WIFI_SSID
|
||||||
string "WiFi SSID"
|
string "WiFi SSID"
|
||||||
default "myssid"
|
default "myssid"
|
||||||
|
@@ -6,9 +6,9 @@
|
|||||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
CONDITIONS OF ANY KIND, either express or implied.
|
CONDITIONS OF ANY KIND, either express or implied.
|
||||||
*/
|
*/
|
||||||
#include "coap_server.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
@@ -19,12 +19,20 @@
|
|||||||
#include "esp_event_loop.h"
|
#include "esp_event_loop.h"
|
||||||
|
|
||||||
#include "nvs_flash.h"
|
#include "nvs_flash.h"
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#include "coap_config.h"
|
|
||||||
#include "resource.h"
|
|
||||||
#include "coap.h"
|
#include "coap.h"
|
||||||
|
|
||||||
|
/* The examples use simple WiFi configuration that you can set via
|
||||||
|
'make menuconfig'.
|
||||||
|
|
||||||
|
If you'd rather not, just change the below entries to strings with
|
||||||
|
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
|
||||||
|
*/
|
||||||
|
#define EXAMPLE_WIFI_SSID CONFIG_WIFI_SSID
|
||||||
|
#define EXAMPLE_WIFI_PASS CONFIG_WIFI_PASSWORD
|
||||||
|
|
||||||
|
#define COAP_DEFAULT_TIME_SEC 5
|
||||||
|
#define COAP_DEFAULT_TIME_USEC 0
|
||||||
|
|
||||||
static EventGroupHandle_t wifi_event_group;
|
static EventGroupHandle_t wifi_event_group;
|
||||||
|
|
||||||
@@ -33,7 +41,7 @@ static EventGroupHandle_t wifi_event_group;
|
|||||||
to the AP with an IP? */
|
to the AP with an IP? */
|
||||||
const static int CONNECTED_BIT = BIT0;
|
const static int CONNECTED_BIT = BIT0;
|
||||||
|
|
||||||
const static char *TAG = "CoAP_demo";
|
const static char *TAG = "CoAP_server";
|
||||||
|
|
||||||
static coap_async_state_t *async = NULL;
|
static coap_async_state_t *async = NULL;
|
||||||
|
|
||||||
@@ -80,6 +88,15 @@ static void coap_demo_thread(void *p)
|
|||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
/* Wait for the callback to set the CONNECTED_BIT in the
|
||||||
|
event group.
|
||||||
|
*/
|
||||||
|
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,
|
||||||
|
false, true, portMAX_DELAY);
|
||||||
|
ESP_LOGI(TAG, "Connected to AP");
|
||||||
|
|
||||||
/* Prepare the CoAP server socket */
|
/* Prepare the CoAP server socket */
|
||||||
coap_address_init(&serv_addr);
|
coap_address_init(&serv_addr);
|
||||||
serv_addr.addr.sin.sin_family = AF_INET;
|
serv_addr.addr.sin.sin_family = AF_INET;
|
||||||
@@ -110,37 +127,22 @@ static void coap_demo_thread(void *p)
|
|||||||
} else if (result < 0){
|
} else if (result < 0){
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
printf("select timeout\n");
|
ESP_LOGE(TAG, "select timeout");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (async)
|
if (async) {
|
||||||
send_async_response(ctx, ctx->endpoint);
|
send_async_response(ctx, ctx->endpoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
coap_free_context(ctx);
|
coap_free_context(ctx);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void coap_server_init(void)
|
|
||||||
{
|
|
||||||
int ret = pdPASS;
|
|
||||||
xTaskHandle coap_handle = NULL;
|
|
||||||
|
|
||||||
ret = xTaskCreate(coap_demo_thread,
|
|
||||||
COAP_DEMO_THREAD_NAME,
|
|
||||||
COAP_DEMO_THREAD_STACK_WORDS,
|
|
||||||
NULL,
|
|
||||||
COAP_DEMO_THREAD_PRORIOTY,
|
|
||||||
&coap_handle);
|
|
||||||
|
|
||||||
if (ret != pdPASS) {
|
|
||||||
ESP_LOGI(TAG, "create thread %s failed", COAP_DEMO_THREAD_NAME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static esp_err_t wifi_event_handler(void *ctx, system_event_t *event)
|
static esp_err_t wifi_event_handler(void *ctx, system_event_t *event)
|
||||||
{
|
{
|
||||||
switch(event->event_id) {
|
switch(event->event_id) {
|
||||||
@@ -149,7 +151,6 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event)
|
|||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_STA_GOT_IP:
|
case SYSTEM_EVENT_STA_GOT_IP:
|
||||||
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
|
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
|
||||||
coap_server_init();
|
|
||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||||
/* This is a workaround as ESP32 WiFi libs don't currently
|
/* This is a workaround as ESP32 WiFi libs don't currently
|
||||||
@@ -179,7 +180,6 @@ static void wifi_conn_init(void)
|
|||||||
};
|
};
|
||||||
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
|
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
|
||||||
ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
|
ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
|
||||||
|
|
||||||
ESP_ERROR_CHECK( esp_wifi_start() );
|
ESP_ERROR_CHECK( esp_wifi_start() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,4 +187,6 @@ void app_main(void)
|
|||||||
{
|
{
|
||||||
nvs_flash_init();
|
nvs_flash_init();
|
||||||
wifi_conn_init();
|
wifi_conn_init();
|
||||||
|
|
||||||
|
xTaskCreate(coap_demo_thread, "coap", 2048, NULL, 5, NULL);
|
||||||
}
|
}
|
||||||
|
@@ -1,38 +0,0 @@
|
|||||||
/* CoAP server Example
|
|
||||||
|
|
||||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, this
|
|
||||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
||||||
CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _COAP_SERVER_H_
|
|
||||||
#define _COAP_SERVER_H_
|
|
||||||
|
|
||||||
#include <sdkconfig.h>
|
|
||||||
|
|
||||||
/* The examples use simple WiFi configuration that you can set via
|
|
||||||
'make menuconfig'.
|
|
||||||
|
|
||||||
If you'd rather not, just change the below entries to strings with
|
|
||||||
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
|
|
||||||
*/
|
|
||||||
#define EXAMPLE_WIFI_SSID CONFIG_WIFI_SSID
|
|
||||||
#define EXAMPLE_WIFI_PASS CONFIG_WIFI_PASSWORD
|
|
||||||
|
|
||||||
#define COAP_DEMO_THREAD_NAME "CoAP_demo"
|
|
||||||
#define COAP_DEMO_THREAD_STACK_WORDS 10240
|
|
||||||
#define COAP_DEMO_THREAD_PRORIOTY 8
|
|
||||||
|
|
||||||
/* The examples use local port number of 5683 that you can set via 'make menuconfig'.
|
|
||||||
|
|
||||||
If you'd rather not, just change the below entries to strings with
|
|
||||||
the config you want - ie #define OPENSSL_DEMO_TARGET_TCP_PORT 5683
|
|
||||||
*/
|
|
||||||
#define COAP_DEFAULT_PORT CONFIG_LOCAL_PORT_NUMBER
|
|
||||||
#define COAP_DEFAULT_TIME_SEC 5
|
|
||||||
#define COAP_DEFAULT_TIME_USEC 0
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
Reference in New Issue
Block a user