Skip to content

Commit

Permalink
Add: esp smart inteface APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
turmary committed Jan 22, 2020
1 parent 8e4939d commit c41d44e
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 0 deletions.
14 changes: 14 additions & 0 deletions esp_at_lib/src/esp/esp_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,20 @@ espi_initiate_cmd(esp_msg_t* msg) {
break;
}
#endif /* ESP_CFG_SNTP */
#if ESP_CFG_SMART
case ESP_CMD_WIFI_SMART_START: { /* Start smart config */
AT_PORT_SEND_BEGIN_AT();
AT_PORT_SEND_CONST_STR("+CWSTARTSMART");
AT_PORT_SEND_END_AT();
break;
}
case ESP_CMD_WIFI_SMART_STOP: { /* Stop smart config */
AT_PORT_SEND_BEGIN_AT();
AT_PORT_SEND_CONST_STR("+CWSTOPSMART");
AT_PORT_SEND_END_AT();
break;
}
#endif /* ESP_CFG_SMART */
#if ESP_CFG_ESP32
case ESP_CMD_BLEINIT_GET: {
AT_PORT_SEND_BEGIN_AT();
Expand Down
61 changes: 61 additions & 0 deletions esp_at_lib/src/esp/esp_smart.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* \file esp_smart.c
* \brief SMART API
*/

/*
* Copyright (c) 2020 Tilen MAJERLE
* Copyright (c) 2020 Seeed Technology
*
* Permission is hereby granted, 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.
*
* This file is part of ESP-AT library.
*
* Author: Tilen MAJERLE <[email protected]>
* Version: $_version_$
*/
#include "esp/esp_private.h"
#include "esp/esp_smart.h"
#include "esp/esp_mem.h"

#if ESP_CFG_SMART || __DOXYGEN__

/**
* \brief Configure SMART function on ESP device
* \param[in] en: Set to `1` to start SMART or `0` to stop SMART
* \param[in] evt_fn: Callback function called when command has finished. Set to `NULL` when not used
* \param[in] evt_arg: Custom argument for event callback function
* \param[in] blocking: Status whether command should be blocking or not
* \return \ref espOK on success, member of \ref espr_t enumeration otherwise
*/
espr_t
esp_smart_configure(uint8_t en,
const esp_api_cmd_evt_fn evt_fn, void* const evt_arg, const uint32_t blocking) {
ESP_MSG_VAR_DEFINE(msg);

ESP_MSG_VAR_ALLOC(msg, blocking);
ESP_MSG_VAR_SET_EVT(msg, evt_fn, evt_arg);
ESP_MSG_VAR_REF(msg).cmd_def = en? ESP_CMD_WIFI_SMART_START: ESP_CMD_WIFI_SMART_STOP;

return espi_send_msg_to_producer_mbox(&ESP_MSG_VAR_REF(msg), espi_initiate_cmd, 10000);
}

#endif /* ESP_CFG_SMART || __DOXYGEN__ */
3 changes: 3 additions & 0 deletions esp_at_lib/src/include/esp/esp_includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
#if ESP_CFG_DNS || __DOXYGEN__
#include "esp/esp_dns.h"
#endif /* ESP_CFG_DNS || __DOXYGEN__ */
#if ESP_CFG_SMART || __DOXYGEN__
#include "esp/esp_smart.h"
#endif /* ESP_CFG_SMART || __DOXYGEN__ */
#include "esp/esp_dhcp.h"

#ifdef __cplusplus
Expand Down
4 changes: 4 additions & 0 deletions esp_at_lib/src/include/esp/esp_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ typedef enum {
#if ESP_CFG_PING || __DOXYGEN__
ESP_CMD_TCPIP_PING, /*!< Ping domain */
#endif /* ESP_CFG_PING || __DOXYGEN__ */
#if ESP_CFG_SMART || __DOXYGEN__
ESP_CMD_WIFI_SMART_START, /*!< Start smart config */
ESP_CMD_WIFI_SMART_STOP, /*!< Stop smart config */
#endif /* ESP_CFG_SMART || __DOXYGEN__ */

/* BLE commands, ESP32 only */
#if ESP_CFG_ESP32 || __DOXYGEN__
Expand Down
61 changes: 61 additions & 0 deletions esp_at_lib/src/include/esp/esp_smart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* \file esp_smart.h
* \brief Smart API
*/

/*
* Copyright (c) 2020 Tilen MAJERLE
* Copyright (c) 2020 Seeed Technology
*
* Permission is hereby granted, 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.
*
* This file is part of ESP-AT library.
*
* Author: Tilen MAJERLE <[email protected]>
* Version: $_version_$
*/
#ifndef ESP_HDR_SMART_H
#define ESP_HDR_SMART_H

#ifdef __cplusplus
extern "C" {
#endif

#include "esp/esp.h"

/**
* \ingroup ESP
* \defgroup ESP_SMART
* \brief SMART function on ESP device
* \{
*/

espr_t esp_smart_configure(uint8_t en, const esp_api_cmd_evt_fn evt_fn, void* const evt_arg, const uint32_t blocking);

/**
* \}
*/

#ifdef __cplusplus
}
#endif

#endif /* ESP_HDR_SMART_H */

0 comments on commit c41d44e

Please sign in to comment.