From 1a5ac749fc8bf6372107b0390c9330dc0981de01 Mon Sep 17 00:00:00 2001 From: chenwu Date: Tue, 12 Jun 2018 14:49:41 +0800 Subject: [PATCH] feat: add coap server --- examples/coap_server/Makefile | 126 ++++++++++++ examples/coap_server/gen_misc.sh | 192 ++++++++++++++++++ examples/coap_server/include/user_config.h | 32 +++ examples/coap_server/user/Makefile | 47 +++++ .../user/coap_server_example_main.c | 102 +++------- examples/coap_server/user/user_main.c | 122 +++++++++++ lib/libcoap.a | Bin 150858 -> 150814 bytes third_party/coap/library/Makefile | 1 + third_party/coap/library/address.c | 3 + third_party/coap/library/coap_time.c | 2 +- third_party/coap/library/debug.c | 6 +- third_party/coap/platform/Makefile | 1 + 12 files changed, 557 insertions(+), 77 deletions(-) create mode 100644 examples/coap_server/Makefile create mode 100755 examples/coap_server/gen_misc.sh create mode 100644 examples/coap_server/include/user_config.h create mode 100644 examples/coap_server/user/Makefile mode change 100644 => 100755 examples/coap_server/user/coap_server_example_main.c create mode 100644 examples/coap_server/user/user_main.c diff --git a/examples/coap_server/Makefile b/examples/coap_server/Makefile new file mode 100644 index 00000000..0051878b --- /dev/null +++ b/examples/coap_server/Makefile @@ -0,0 +1,126 @@ +############################################################# +# Required variables for each makefile +# Discard this section from all parent makefiles +# Expected variables (with automatic defaults): +# CSRCS (all "C" files in the dir) +# SUBDIRS (all subdirs with a Makefile) +# GEN_LIBS - list of libs to be generated () +# GEN_IMAGES - list of object file images to be generated () +# GEN_BINS - list of binaries to be generated () +# COMPONENTS_xxx - a list of libs/objs in the form +# subdir/lib to be extracted and rolled up into +# a generated lib/image xxx.a () +# +TARGET = eagle +#FLAVOR = release +FLAVOR = debug + +#EXTRA_CCFLAGS += -u + +ifndef PDIR # { +GEN_IMAGES= eagle.app.v6.out +GEN_BINS= eagle.app.v6.bin +SPECIAL_MKTARGETS=$(APP_MKTARGETS) +SUBDIRS= \ + user + +endif # } PDIR + +LDDIR = $(SDK_PATH)/ld + +CCFLAGS += -Os + +TARGET_LDFLAGS = \ + -nostdlib \ + -Wl,-EL \ + --longcalls \ + --text-section-literals + +ifeq ($(FLAVOR),debug) + TARGET_LDFLAGS += -g -O2 +endif + +ifeq ($(FLAVOR),release) + TARGET_LDFLAGS += -g -O0 +endif + +COMPONENTS_eagle.app.v6 = \ + user/libuser.a + +LINKFLAGS_eagle.app.v6 = \ + -L$(SDK_PATH)/lib \ + -Wl,--gc-sections \ + -nostdlib \ + -T$(LD_FILE) \ + -Wl,--no-check-sections \ + -u call_user_start \ + -Wl,-static \ + -Wl,--start-group \ + -lcirom \ + -lgcc \ + -lhal \ + -lcrypto \ + -lfreertos \ + -llwip \ + -lmain \ + -lnet80211 \ + -lphy \ + -lpp \ + -lmbedtls \ + -lopenssl \ + -lcoap \ + -lwpa \ + $(DEP_LIBS_eagle.app.v6)\ + -Wl,--end-group + +DEPENDS_eagle.app.v6 = \ + $(LD_FILE) \ + $(LDDIR)/eagle.rom.addr.v6.ld + +############################################################# +# Configuration i.e. compile options etc. +# Target specific stuff (defines etc.) goes in here! +# Generally values applying to a tree are captured in the +# makefile at its root level - these are then overridden +# for a subtree within the makefile rooted therein +# + +#UNIVERSAL_TARGET_DEFINES = \ + +# Other potential configuration flags include: +# -DTXRX_TXBUF_DEBUG +# -DTXRX_RXBUF_DEBUG +# -DWLAN_CONFIG_CCX +# -DMQTT_TASK: Define MQTT_TASK to enable MQTT start background +# thread for a client. +CONFIGURATION_DEFINES = -DICACHE_FLASH -DMQTT_TASK + +DEFINES += \ + $(UNIVERSAL_TARGET_DEFINES) \ + $(CONFIGURATION_DEFINES) + +DDEFINES += \ + $(UNIVERSAL_TARGET_DEFINES) \ + $(CONFIGURATION_DEFINES) + + +############################################################# +# Recursion Magic - Don't touch this!! +# +# Each subtree potentially has an include directory +# corresponding to the common APIs applicable to modules +# rooted at that subtree. Accordingly, the INCLUDE PATH +# of a module can only contain the include directories up +# its parent path, and not its siblings +# +# Required for each makefile to inherit from the parent +# +INCLUDES := $(INCLUDES) -I $(PDIR)include +INCLUDES += -I $(SDK_PATH)/third_party/coap/platform/include +INCLUDES += -I $(SDK_PATH)/third_party/coap/platform/include/coap +INCLUDES += -I $(SDK_PATH)/third_party/coap/library/include/coap +sinclude $(SDK_PATH)/Makefile + +.PHONY: FORCE +FORCE: + diff --git a/examples/coap_server/gen_misc.sh b/examples/coap_server/gen_misc.sh new file mode 100755 index 00000000..ced20a09 --- /dev/null +++ b/examples/coap_server/gen_misc.sh @@ -0,0 +1,192 @@ +#!/bin/bash + +:< + * + * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, + * it is free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef __USER_CONFIG_H__ +#define __USER_CONFIG_H__ + +#define SSID "BL_841R" /* Wi-Fi SSID */ +#define PASSWORD "1234567890" /* Wi-Fi Password */ + +#endif + diff --git a/examples/coap_server/user/Makefile b/examples/coap_server/user/Makefile new file mode 100644 index 00000000..244e135d --- /dev/null +++ b/examples/coap_server/user/Makefile @@ -0,0 +1,47 @@ + +############################################################# +# Required variables for each makefile +# Discard this section from all parent makefiles +# Expected variables (with automatic defaults): +# CSRCS (all "C" files in the dir) +# SUBDIRS (all subdirs with a Makefile) +# GEN_LIBS - list of libs to be generated () +# GEN_IMAGES - list of images to be generated () +# COMPONENTS_xxx - a list of libs/objs in the form +# subdir/lib to be extracted and rolled up into +# a generated lib/image xxx.a () +# +ifndef PDIR +GEN_LIBS = libuser.a +endif + + +############################################################# +# Configuration i.e. compile options etc. +# Target specific stuff (defines etc.) goes in here! +# Generally values applying to a tree are captured in the +# makefile at its root level - these are then overridden +# for a subtree within the makefile rooted therein +# +#DEFINES += +DEFINES += -DWITH_POSIX +############################################################# +# Recursion Magic - Don't touch this!! +# +# Each subtree potentially has an include directory +# corresponding to the common APIs applicable to modules +# rooted at that subtree. Accordingly, the INCLUDE PATH +# of a module can only contain the include directories up +# its parent path, and not its siblings +# +# Required for each makefile to inherit from the parent +# + +INCLUDES := $(INCLUDES) -I $(PDIR)include +INCLUDES += -I $(SDK_PATH)/third_party/coap/platform/include +INCLUDES += -I $(SDK_PATH)/third_party/coap/platform/include/coap +INCLUDES += -I $(SDK_PATH)/third_party/coap/library/include/coap +INCLUDES += -I ./ +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile + diff --git a/examples/coap_server/user/coap_server_example_main.c b/examples/coap_server/user/coap_server_example_main.c old mode 100644 new mode 100755 index d6b87cbe..65e47fd4 --- a/examples/coap_server/user/coap_server_example_main.c +++ b/examples/coap_server/user/coap_server_example_main.c @@ -12,37 +12,29 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "freertos/event_groups.h" -#include "esp_log.h" #include "esp_wifi.h" -#include "esp_event_loop.h" - -#include "nvs_flash.h" - #include "coap.h" -/* The examples use simple WiFi configuration that you can set via - 'make menuconfig'. +// for libcirom.a +int _getpid_r(struct _reent *r) +{ + return -1; + } +int _kill_r(struct _reent *r, int pid, int sig) +{ + return -1; + } - 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_SERVER_THREAD_NAME "coap_server_thread" +#define COAP_SERVER_THREAD_STACK_WORDS 2048 +#define COAP_SERVER_THREAD_PRIO 8 + +LOCAL xTaskHandle coap_server_handle; #define COAP_DEFAULT_TIME_SEC 5 #define COAP_DEFAULT_TIME_USEC 0 -static EventGroupHandle_t wifi_event_group; - -/* The event group allows multiple bits for each event, - but we only care about one event - are we connected - to the AP with an IP? */ -const static int CONNECTED_BIT = BIT0; - -const static char *TAG = "CoAP_server"; - static coap_async_state_t *async = NULL; static void @@ -50,7 +42,7 @@ send_async_response(coap_context_t *ctx, const coap_endpoint_t *local_if) { coap_pdu_t *response; unsigned char buf[3]; - const char* response_data = "Hello World WTF!"; + const char* response_data = "Hello esp8266!"; size_t size = sizeof(coap_hdr_t) + 20; response = coap_pdu_init(async->flags & COAP_MESSAGE_CON, COAP_RESPONSE_CODE(205), 0, size); response->hdr->id = coap_new_message_id(ctx); @@ -90,13 +82,6 @@ static void coap_example_thread(void *p) 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 */ coap_address_init(&serv_addr); serv_addr.addr.sin.sin_family = AF_INET; @@ -127,7 +112,7 @@ static void coap_example_thread(void *p) } else if (result < 0){ break; } else { - ESP_LOGE(TAG, "select timeout"); + printf("select timeout\n"); } if (async) { @@ -143,50 +128,17 @@ static void coap_example_thread(void *p) vTaskDelete(NULL); } -static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) +void user_conn_init(void) { - switch(event->event_id) { - case SYSTEM_EVENT_STA_START: - esp_wifi_connect(); - break; - case SYSTEM_EVENT_STA_GOT_IP: - xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); - break; - case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ - esp_wifi_connect(); - xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); - break; - default: - break; + int ret; + ret = xTaskCreate(coap_example_thread, + COAP_SERVER_THREAD_NAME, + COAP_SERVER_THREAD_STACK_WORDS, + NULL, + COAP_SERVER_THREAD_PRIO, + &coap_server_handle); + + if (ret != pdPASS) { + printf("create coap server thread %s failed\n", COAP_SERVER_THREAD_NAME); } - return ESP_OK; -} - -static void wifi_conn_init(void) -{ - tcpip_adapter_init(); - wifi_event_group = xEventGroupCreate(); - ESP_ERROR_CHECK( esp_event_loop_init(wifi_event_handler, NULL) ); - wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); - ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); - ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) ); - wifi_config_t wifi_config = { - .sta = { - .ssid = EXAMPLE_WIFI_SSID, - .password = EXAMPLE_WIFI_PASS, - }, - }; - 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_start() ); -} - -void app_main(void) -{ - ESP_ERROR_CHECK( nvs_flash_init() ); - wifi_conn_init(); - - xTaskCreate(coap_example_thread, "coap", 2048, NULL, 5, NULL); } diff --git a/examples/coap_server/user/user_main.c b/examples/coap_server/user/user_main.c new file mode 100644 index 00000000..3481bbc9 --- /dev/null +++ b/examples/coap_server/user/user_main.c @@ -0,0 +1,122 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2015 + * + * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, + * it is free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#include "esp_common.h" +#include "user_config.h" + +/****************************************************************************** + * FunctionName : user_rf_cal_sector_set + * Description : SDK just reversed 4 sectors, used for rf init data and paramters. + * We add this function to force users to set rf cal sector, since + * we don't know which sector is free in user's application. + * sector map for last several sectors : ABCCC + * A : rf cal + * B : rf init data + * C : sdk parameters + * Parameters : none + * Returns : rf cal sector +*******************************************************************************/ +uint32 user_rf_cal_sector_set(void) +{ + flash_size_map size_map = system_get_flash_size_map(); + uint32 rf_cal_sec = 0; + + switch (size_map) { + case FLASH_SIZE_4M_MAP_256_256: + rf_cal_sec = 128 - 5; + break; + + case FLASH_SIZE_8M_MAP_512_512: + rf_cal_sec = 256 - 5; + break; + + case FLASH_SIZE_16M_MAP_512_512: + case FLASH_SIZE_16M_MAP_1024_1024: + rf_cal_sec = 512 - 5; + break; + + case FLASH_SIZE_32M_MAP_512_512: + case FLASH_SIZE_32M_MAP_1024_1024: + rf_cal_sec = 1024 - 5; + break; + case FLASH_SIZE_64M_MAP_1024_1024: + rf_cal_sec = 2048 - 5; + break; + case FLASH_SIZE_128M_MAP_1024_1024: + rf_cal_sec = 4096 - 5; + break; + default: + rf_cal_sec = 0; + break; + } + + return rf_cal_sec; +} + +void wifi_event_handler_cb(System_Event_t *event) +{ + if (event == NULL) { + return; + } + + switch (event->event_id) { + case EVENT_STAMODE_GOT_IP: + os_printf("sta got ip ,create task and free heap size is %d\n", system_get_free_heap_size()); + user_conn_init(); + break; + + case EVENT_STAMODE_CONNECTED: + os_printf("sta connected\n"); + break; + + case EVENT_STAMODE_DISCONNECTED: + wifi_station_connect(); + break; + + default: + break; + } +} + +/****************************************************************************** + * FunctionName : user_init + * Description : entry of user application, init user function here + * Parameters : none + * Returns : none +*******************************************************************************/ +void user_init(void) +{ + os_printf("SDK version:%s %d\n", system_get_sdk_version(), system_get_free_heap_size()); + wifi_set_opmode(STATION_MODE); + + struct station_config config; + bzero(&config, sizeof(struct station_config)); + sprintf(config.ssid, SSID); + sprintf(config.password, PASSWORD); + wifi_station_set_config(&config); + + wifi_set_event_handler_cb(wifi_event_handler_cb); + + wifi_station_connect(); +} diff --git a/lib/libcoap.a b/lib/libcoap.a index 027a49ccde17e54e58d019e5ce41e953eb6b9970..a17da47d112351484afd348efb3179e8ae25157d 100644 GIT binary patch delta 2819 zcmcgueQZlJA zHP*(oe|Dtbxxe$fAMg5}`{6S$n-0Eg+M8#ryl3Ugm7W(=cX-K10Ljp*0FqJl7QpS$ z`VW8vf(-!w38M!A5;#%@aC}D$;TRe30Qf(FJ$ww35Kazm&j+3Y_P^lGtHAy%e7A4J za{>@U-e1&rl$%z$+JnyqirG7;FWRtlz3)c!u^Z9;Gypg|Uoao_ z%|{=*9?e^iIawVI_Fo!2+)(5+7U8OX8$hwz=V8i*XWTVP`Ik}m<8t2IE6DDxbg&kA7u zbS7T;Si)`6bCIU=Oe(j~Y&gL|V1!IU9-)Gu66y%Tgf6%}a{h-bcZujC&=xO6(+;%$ zp#q;b&qtoW%!*(8Z8l>q_&bY>b>Ni6X_znpbYaxuWDlWJ)_4PpR9|6s+ZpPbK}c91 z!#R%~hh&+*&LVRi%x;~cy7WXnmCNy@tg%!0S6MUGETYLVyzobrUBER~%^=ZW3g*Az zsk99B;-&|0#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`T`9S_W6Xo0H?7n;ksZ+C;g|W#RnJ zYXD^Dpr8P*~{3g1Fr2hSrPh2PBZ=g21^ zyPI0B?pDP4RNCtBooF+X>PzDnd$C{KfQw+7wAoXep;Kd%X`YvDto`T;x!!%rWg zmY&IO@4+>R8g2gmsDmZ>C*u4UZou!>Xq9^$8R}G2aGt;D&Cn z>0VZ!y$P>@vS}WAd@&N*ID&ei80l0s{yQ~J$LzeSspUKbFF``PjG(#{yBu~u`;j3u zSX*hi*TGjWZ)l*e4BA#4AWxgsdq^8*b&xboI$8(mj9Gn@v~gB9wd@S+YH|dY z$g@^j?y8*qi4Ap_#JuptK-;aKAiPDxjf2G+^-C1)8@`%!`>SLQpBP)*8}%`FQ-Qn=mZ;7l6T|Y5)KL diff --git a/third_party/coap/library/Makefile b/third_party/coap/library/Makefile index 10f4067c..3110901d 100644 --- a/third_party/coap/library/Makefile +++ b/third_party/coap/library/Makefile @@ -26,6 +26,7 @@ endif # for a subtree within the makefile rooted therein # #DEFINES += +DEFINES += -DWITH_POSIX ############################################################# # Recursion Magic - Don't touch this!! diff --git a/third_party/coap/library/address.c b/third_party/coap/library/address.c index bd72069b..15858537 100644 --- a/third_party/coap/library/address.c +++ b/third_party/coap/library/address.c @@ -12,6 +12,9 @@ #include "address.h" +#ifndef IN6_IS_ADDR_MULTICAST +#define IN6_IS_ADDR_MULTICAST(a) IN_MULTICAST(a) +#endif int coap_address_equals(const coap_address_t *a, const coap_address_t *b) { assert(a); assert(b); diff --git a/third_party/coap/library/coap_time.c b/third_party/coap/library/coap_time.c index 555a86e5..03bc1112 100644 --- a/third_party/coap/library/coap_time.c +++ b/third_party/coap/library/coap_time.c @@ -19,7 +19,7 @@ static coap_time_t coap_clock_offset = 0; /* _POSIX_TIMERS is > 0 when clock_gettime() is available */ /* Use real-time clock for correct timestamps in coap_log(). */ -#define COAP_CLOCK CLOCK_REALTIME +//#define COAP_CLOCK CLOCK_REALTIME #endif void diff --git a/third_party/coap/library/debug.c b/third_party/coap/library/debug.c index d60adb47..da7b8977 100644 --- a/third_party/coap/library/debug.c +++ b/third_party/coap/library/debug.c @@ -154,6 +154,10 @@ print_readable( const unsigned char *data, unsigned int len, #define min(a,b) ((a) < (b) ? (a) : (b)) #endif +#ifndef inet_ntop +#define inet_ntop(af,src,dst,size) (((af) == AF_INET) ? ipaddr_ntoa_r((const ip_addr_t *)(src),(dst),(size)) : NULL) +#endif + size_t coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t len) { #ifdef HAVE_ARPA_INET_H @@ -163,7 +167,7 @@ coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t le switch (addr->addr.sa.sa_family) { case AF_INET: - addrptr = &addr->addr.sin.sin_addr; + addrptr = &addr->addr.sin.sin_addr.s_addr; port = ntohs(addr->addr.sin.sin_port); break; case AF_INET6: diff --git a/third_party/coap/platform/Makefile b/third_party/coap/platform/Makefile index 749b4787..e6dbca29 100644 --- a/third_party/coap/platform/Makefile +++ b/third_party/coap/platform/Makefile @@ -26,6 +26,7 @@ endif # for a subtree within the makefile rooted therein # #DEFINES += +DEFINES += -DWITH_POSIX ############################################################# # Recursion Magic - Don't touch this!!