Skip to content

Commit

Permalink
feat: add option to start connection regardless of IP status
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Sep 29, 2023
1 parent c5d331d commit 99c1ac3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
14 changes: 14 additions & 0 deletions lwesp/src/include/lwesp/lwesp_opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,20 @@
#define LWESP_CFG_CONN_POLL_INTERVAL 500
#endif

/**
* \brief Enables (`1`) or disabled (`1`) option to start connection event
* if station does not have valid IP address (is not connected to another access point)
*
* When enabled, starting a connection as a client can be successful even, if ESP-AT station isn't connected to another access point.
* This feature is only used if ESP is in access point mode and another station connects to it.
*
* \note Value is set to `0` to keep backward compatibility.
*
*/
#ifndef LWESP_CFG_CONN_ALLOW_START_STATION_NO_IP
#define LWESP_CFG_CONN_ALLOW_START_STATION_NO_IP 0
#endif

/**
* \}
*/
Expand Down
3 changes: 2 additions & 1 deletion lwesp/src/include/lwesp/lwesp_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ typedef enum {
lwespERRWIFINOTCONNECTED, /*!< Wifi not connected to access point */
lwespERRNODEVICE, /*!< Device is not present */
lwespERRBLOCKING, /*!< Blocking mode command is not allowed */
lwespERRCMDNOTSUPPORTED, /*!< Command is not supported error received by device */
lwespERRCMDNOTSUPPORTED, /*!< Command is not supported error received by device,
or when command is not supported in the stack itself */
} lwespr_t;

/**
Expand Down
14 changes: 8 additions & 6 deletions lwesp/src/lwesp/lwesp_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -2505,15 +2505,18 @@ lwespi_initiate_cmd(lwesp_msg_t* msg) {
AT_PORT_SEND_END_AT();
break;
}
#if LWESP_CFG_MODE_STATION
case LWESP_CMD_TCPIP_CIPSTART: { /* Start a new connection */
const char* conn_type_str;
case LWESP_CMD_TCPIP_CIPSTART: { /* Start a new connection */ const char* conn_type_str;

/* Do we have wifi connection? */
#if LWESP_CFG_CONN_ALLOW_START_STATION_NO_IP
/*
* Do not check IP status if starting a connection is allowed
* without being connected to access point.
* This allows ESP to act as a access point and get connected another station to it.
*/
if (!lwesp_sta_has_ip()) {
lwespi_send_conn_error_cb(msg, lwespERRNOIP);
return lwespERRNOIP;
}
#endif /* LWESP_CFG_CONN_ALLOW_START_STATION_NO_IP */

if (msg->msg.conn_start.type == LWESP_CONN_TYPE_TCP) {
conn_type_str = "TCP";
Expand Down Expand Up @@ -2558,7 +2561,6 @@ lwespi_initiate_cmd(lwesp_msg_t* msg) {
AT_PORT_SEND_END_AT();
break;
}
#endif /* LWESP_CFG_MODE_STATION */
case LWESP_CMD_TCPIP_CIPCLOSE: { /* Close the connection */
lwesp_conn_p c = msg->msg.conn_close.conn;
if (c != NULL &&
Expand Down

0 comments on commit 99c1ac3

Please sign in to comment.