forked from MaJerle/lwesp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add [undocumented] hostname command with esp ESP-AT firmware
- Loading branch information
Showing
8 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* \file esp_hostname.c | ||
* \brief Hostname API | ||
*/ | ||
|
||
/* | ||
* Copyright (c) 2019 Tilen MAJERLE | ||
* | ||
* 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]> | ||
*/ | ||
#include "esp/esp_private.h" | ||
#include "esp/esp_hostname.h" | ||
#include "esp/esp_mem.h" | ||
|
||
#if ESP_CFG_HOSTNAME || __DOXYGEN__ | ||
|
||
/** | ||
* \brief Set hostname of WiFi station | ||
* \param[in] hostname: Name of ESP host | ||
* \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_hostname_set(const char* hostname, | ||
const esp_api_cmd_evt_fn evt_fn, void* const evt_arg, const uint32_t blocking) { | ||
ESP_MSG_VAR_DEFINE(msg); | ||
|
||
ESP_ASSERT("hostname != NULL", hostname != NULL); | ||
|
||
ESP_MSG_VAR_ALLOC(msg, blocking); | ||
ESP_MSG_VAR_SET_EVT(msg, evt_fn, evt_arg); | ||
ESP_MSG_VAR_REF(msg).cmd_def = ESP_CMD_WIFI_CWHOSTNAME_SET; | ||
ESP_MSG_VAR_REF(msg).msg.wifi_hostname.hostname_set = hostname; | ||
|
||
return espi_send_msg_to_producer_mbox(&ESP_MSG_VAR_REF(msg), espi_initiate_cmd, 1000); | ||
} | ||
|
||
/** | ||
* \brief Get hostname of WiFi station | ||
* \param[in] hostname: Pointer to output variable holding memory to save hostname | ||
* \param[in] size: Size of buffer for hostname. Size includes memory for `NULL` termination | ||
* \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_hostname_get(char* hostname, size_t size, | ||
const esp_api_cmd_evt_fn evt_fn, void* const evt_arg, const uint32_t blocking) { | ||
ESP_MSG_VAR_DEFINE(msg); | ||
|
||
ESP_ASSERT("hostname != NULL", hostname != NULL); | ||
ESP_ASSERT("size > 0", size > 0); | ||
|
||
ESP_MSG_VAR_ALLOC(msg, blocking); | ||
ESP_MSG_VAR_SET_EVT(msg, evt_fn, evt_arg); | ||
ESP_MSG_VAR_REF(msg).cmd_def = ESP_CMD_WIFI_CWHOSTNAME_GET; | ||
ESP_MSG_VAR_REF(msg).msg.wifi_hostname.hostname_get = hostname; | ||
ESP_MSG_VAR_REF(msg).msg.wifi_hostname.length = size; | ||
|
||
return espi_send_msg_to_producer_mbox(&ESP_MSG_VAR_REF(msg), espi_initiate_cmd, 1000); | ||
} | ||
|
||
#endif /* ESP_CFG_HOSTNAME || __DOXYGEN__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* \file esp_hostname.h | ||
* \brief Hostname API | ||
*/ | ||
|
||
/* | ||
* Copyright (c) 2019 Tilen MAJERLE | ||
* | ||
* 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]> | ||
*/ | ||
#ifndef ESP_HDR_HOSTNAME_H | ||
#define ESP_HDR_HOSTNAME_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "esp/esp.h" | ||
|
||
/** | ||
* \ingroup ESP | ||
* \defgroup ESP_HOSTNAME Hostname API | ||
* \brief Hostname API | ||
* \{ | ||
*/ | ||
|
||
espr_t esp_hostname_set(const char* hostname, const esp_api_cmd_evt_fn evt_fn, void* const evt_arg, const uint32_t blocking); | ||
espr_t esp_hostname_get(char* hostname, size_t size, const esp_api_cmd_evt_fn evt_fn, void* const evt_arg, const uint32_t blocking); | ||
|
||
/** | ||
* \} | ||
*/ | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* ESP_HDR_HOSTNAME_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters