Skip to content

Mem optimized #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion libraries/WiFi/library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=WiFi
version=2.0.0
version=2.0.1
author=Hristo Gochkov
maintainer=Hristo Gochkov <[email protected]>
sentence=Enables network connection (local and Internet) using the ESP32 built-in WiFi.
Expand Down
12 changes: 12 additions & 0 deletions libraries/WiFi/src/WiFiGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,18 @@ bool wifiLowLevelInit(bool persistent){
}

wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();

#if 1
// TWEAK to force Dynamic Buffer instead of Static ones
// This uses less heap space in Arduino and makes it similar to 1.0.6 configuration
cfg.static_tx_buf_num = 0;
cfg.dynamic_tx_buf_num = 32;
cfg.tx_buf_type = 1;
cfg.cache_tx_buf_num = 1; // it can't be zero for WPA/WPA2
cfg.static_rx_buf_num = 4;
cfg.dynamic_rx_buf_num = 32;
#endif

esp_err_t err = esp_wifi_init(&cfg);
if(err){
log_e("esp_wifi_init %d", err);
Expand Down
18 changes: 9 additions & 9 deletions platform.txt

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions tools/sdk/esp32/include/asio/port/include/esp_asio_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
# define ASIO_NO_TYPEID
# endif // CONFIG_COMPILER_RTTI

//
// Supress OpenSSL deprecation warning, when building ASIO
//
#define ESP_OPENSSL_SUPPRESS_LEGACY_WARNING

//
// LWIP compatibility inet and address macros/functions
//
Expand Down
177 changes: 177 additions & 0 deletions tools/sdk/esp32/include/coap/libcoap/include/coap2/address.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/*
* address.h -- representation of network addresses
*
* Copyright (C) 2010-2011,2015-2016 Olaf Bergmann <[email protected]>
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/

/**
* @file address.h
* @brief Representation of network addresses
*/

#ifndef COAP_ADDRESS_H_
#define COAP_ADDRESS_H_

#include <assert.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include "libcoap.h"

#if defined(WITH_LWIP)

#include <lwip/ip_addr.h>

typedef struct coap_address_t {
uint16_t port;
ip_addr_t addr;
} coap_address_t;

#define _coap_address_equals_impl(A, B) \
((A)->port == (B)->port \
&& (!!ip_addr_cmp(&(A)->addr,&(B)->addr)))

#define _coap_address_isany_impl(A) ip_addr_isany(&(A)->addr)

#define _coap_is_mcast_impl(Address) ip_addr_ismulticast(&(Address)->addr)

#elif defined(WITH_CONTIKI)

#include "uip.h"

typedef struct coap_address_t {
uip_ipaddr_t addr;
uint16_t port;
} coap_address_t;

#define _coap_address_equals_impl(A,B) \
((A)->port == (B)->port \
&& uip_ipaddr_cmp(&((A)->addr),&((B)->addr)))

/** @todo implementation of _coap_address_isany_impl() for Contiki */
#define _coap_address_isany_impl(A) 0

#define _coap_is_mcast_impl(Address) uip_is_addr_mcast(&((Address)->addr))

#else /* WITH_LWIP || WITH_CONTIKI */

/** multi-purpose address abstraction */
typedef struct coap_address_t {
socklen_t size; /**< size of addr */
union {
struct sockaddr sa;
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
} addr;
} coap_address_t;

/**
* Compares given address objects @p a and @p b. This function returns @c 1 if
* addresses are equal, @c 0 otherwise. The parameters @p a and @p b must not be
* @c NULL;
*/
int coap_address_equals(const coap_address_t *a, const coap_address_t *b);

COAP_STATIC_INLINE int
_coap_address_isany_impl(const coap_address_t *a) {
/* need to compare only relevant parts of sockaddr_in6 */
switch (a->addr.sa.sa_family) {
case AF_INET:
return a->addr.sin.sin_addr.s_addr == INADDR_ANY;
case AF_INET6:
return memcmp(&in6addr_any,
&a->addr.sin6.sin6_addr,
sizeof(in6addr_any)) == 0;
default:
;
}

return 0;
}
#endif /* WITH_LWIP || WITH_CONTIKI */

/**
* Resets the given coap_address_t object @p addr to its default values. In
* particular, the member size must be initialized to the available size for
* storing addresses.
*
* @param addr The coap_address_t object to initialize.
*/
COAP_STATIC_INLINE void
coap_address_init(coap_address_t *addr) {
assert(addr);
memset(addr, 0, sizeof(coap_address_t));
#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI)
/* lwip and Contiki have constant address sizes and doesn't need the .size part */
addr->size = sizeof(addr->addr);
#endif
}

/* Convenience function to copy IPv6 addresses without garbage. */

COAP_STATIC_INLINE void
coap_address_copy( coap_address_t *dst, const coap_address_t *src ) {
#if defined(WITH_LWIP) || defined(WITH_CONTIKI)
memcpy( dst, src, sizeof( coap_address_t ) );
#else
memset( dst, 0, sizeof( coap_address_t ) );
dst->size = src->size;
if ( src->addr.sa.sa_family == AF_INET6 ) {
dst->addr.sin6.sin6_family = src->addr.sin6.sin6_family;
dst->addr.sin6.sin6_addr = src->addr.sin6.sin6_addr;
dst->addr.sin6.sin6_port = src->addr.sin6.sin6_port;
dst->addr.sin6.sin6_scope_id = src->addr.sin6.sin6_scope_id;
} else if ( src->addr.sa.sa_family == AF_INET ) {
dst->addr.sin = src->addr.sin;
} else {
memcpy( &dst->addr, &src->addr, src->size );
}
#endif
}

#if defined(WITH_LWIP) || defined(WITH_CONTIKI)
/**
* Compares given address objects @p a and @p b. This function returns @c 1 if
* addresses are equal, @c 0 otherwise. The parameters @p a and @p b must not be
* @c NULL;
*/
COAP_STATIC_INLINE int
coap_address_equals(const coap_address_t *a, const coap_address_t *b) {
assert(a); assert(b);
return _coap_address_equals_impl(a, b);
}
#endif

/**
* Checks if given address object @p a denotes the wildcard address. This
* function returns @c 1 if this is the case, @c 0 otherwise. The parameters @p
* a must not be @c NULL;
*/
COAP_STATIC_INLINE int
coap_address_isany(const coap_address_t *a) {
assert(a);
return _coap_address_isany_impl(a);
}

#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI)

/**
* Checks if given address @p a denotes a multicast address. This function
* returns @c 1 if @p a is multicast, @c 0 otherwise.
*/
int coap_is_mcast(const coap_address_t *a);
#else /* !WITH_LWIP && !WITH_CONTIKI */
/**
* Checks if given address @p a denotes a multicast address. This function
* returns @c 1 if @p a is multicast, @c 0 otherwise.
*/
COAP_STATIC_INLINE int
coap_is_mcast(const coap_address_t *a) {
return a && _coap_is_mcast_impl(a);
}
#endif /* !WITH_LWIP && !WITH_CONTIKI */

#endif /* COAP_ADDRESS_H_ */
148 changes: 148 additions & 0 deletions tools/sdk/esp32/include/coap/libcoap/include/coap2/async.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* async.h -- state management for asynchronous messages
*
* Copyright (C) 2010-2011 Olaf Bergmann <[email protected]>
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/

/**
* @file async.h
* @brief State management for asynchronous messages
*/

#ifndef COAP_ASYNC_H_
#define COAP_ASYNC_H_

#include "net.h"

#ifndef WITHOUT_ASYNC

/**
* @defgroup coap_async Asynchronous Messaging
* @{
* Structure for managing asynchronous state of CoAP resources. A
* coap_resource_t object holds a list of coap_async_state_t objects that can be
* used to generate a separate response in case a result of an operation cannot
* be delivered in time, or the resource has been explicitly subscribed to with
* the option @c observe.
*/
typedef struct coap_async_state_t {
unsigned char flags; /**< holds the flags to control behaviour */

/**
* Holds the internal time when the object was registered with a
* resource. This field will be updated whenever
* coap_register_async() is called for a specific resource.
*/
coap_tick_t created;

/**
* This field can be used to register opaque application data with the
* asynchronous state object.
*/
void *appdata;
coap_session_t *session; /**< transaction session */
coap_tid_t id; /**< transaction id */
struct coap_async_state_t *next; /**< internally used for linking */
size_t tokenlen; /**< length of the token */
uint8_t token[8]; /**< the token to use in a response */
} coap_async_state_t;

/* Definitions for Async Status Flags These flags can be used to control the
* behaviour of asynchronous response generation.
*/
#define COAP_ASYNC_CONFIRM 0x01 /**< send confirmable response */
#define COAP_ASYNC_SEPARATE 0x02 /**< send separate response */
#define COAP_ASYNC_OBSERVED 0x04 /**< the resource is being observed */

/** release application data on destruction */
#define COAP_ASYNC_RELEASE_DATA 0x08

/**
* Allocates a new coap_async_state_t object and fills its fields according to
* the given @p request. The @p flags are used to control generation of empty
* ACK responses to stop retransmissions and to release registered @p data when
* the resource is deleted by coap_free_async(). This function returns a pointer
* to the registered coap_async_t object or @c NULL on error. Note that this
* function will return @c NULL in case that an object with the same identifier
* is already registered.
*
* @param context The context to use.
* @param session The session that is used for asynchronous transmissions.
* @param request The request that is handled asynchronously.
* @param flags Flags to control state management.
* @param data Opaque application data to register. Note that the
* storage occupied by @p data is released on destruction
* only if flag COAP_ASYNC_RELEASE_DATA is set.
*
* @return A pointer to the registered coap_async_state_t object or @c
* NULL in case of an error.
*/
coap_async_state_t *
coap_register_async(coap_context_t *context,
coap_session_t *session,
coap_pdu_t *request,
unsigned char flags,
void *data);

/**
* Removes the state object identified by @p id from @p context. The removed
* object is returned in @p s, if found. Otherwise, @p s is undefined. This
* function returns @c 1 if the object was removed, @c 0 otherwise. Note that
* the storage allocated for the stored object is not released by this
* functions. You will have to call coap_free_async() to do so.
*
* @param context The context where the async object is registered.
* @param session The session that is used for asynchronous transmissions.
* @param id The identifier of the asynchronous transaction.
* @param s Will be set to the object identified by @p id after removal.
*
* @return @c 1 if object was removed and @p s updated, or @c 0 if no
* object was found with the given id. @p s is valid only if the
* return value is @c 1.
*/
int coap_remove_async(coap_context_t *context,
coap_session_t *session,
coap_tid_t id,
coap_async_state_t **s);

/**
* Releases the memory that was allocated by coap_async_state_init() for the
* object @p s. The registered application data will be released automatically
* if COAP_ASYNC_RELEASE_DATA is set.
*
* @param state The object to delete.
*/
void
coap_free_async(coap_async_state_t *state);

/**
* Retrieves the object identified by @p id from the list of asynchronous
* transactions that are registered with @p context. This function returns a
* pointer to that object or @c NULL if not found.
*
* @param context The context where the asynchronous objects are registered
* with.
* @param session The session that is used for asynchronous transmissions.
* @param id The id of the object to retrieve.
*
* @return A pointer to the object identified by @p id or @c NULL if
* not found.
*/
coap_async_state_t *coap_find_async(coap_context_t *context, coap_session_t *session, coap_tid_t id);

/**
* Updates the time stamp of @p s.
*
* @param s The state object to update.
*/
COAP_STATIC_INLINE void
coap_touch_async(coap_async_state_t *s) { coap_ticks(&s->created); }

/** @} */

#endif /* WITHOUT_ASYNC */

#endif /* COAP_ASYNC_H_ */
Loading