Adds support for settxpower (#3535)

* Adds support for settxpower

* Update docs/modules/wifi.md

Co-authored-by: Marcel Stör <marcelstoer@users.noreply.github.com>

* Update docs/modules/wifi.md

Co-authored-by: Marcel Stör <marcelstoer@users.noreply.github.com>

Co-authored-by: Marcel Stör <marcelstoer@users.noreply.github.com>
This commit is contained in:
Philip Gladstone 2022-09-29 21:38:32 -04:00 committed by GitHub
parent 9965635694
commit c7cab0aba4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 2 deletions

View File

@ -40,6 +40,7 @@
#include "nodemcu_esp_event.h"
#include <string.h>
#include "esp_netif.h"
#include <math.h>
static esp_netif_t *wifi_sta = NULL;
static int scan_cb_ref = LUA_NOREF;
@ -207,6 +208,20 @@ static int wifi_sta_setip(lua_State *L)
return 0;
}
static int wifi_sta_settxpower(lua_State *L)
{
lua_Number max_power = luaL_checknumber(L, 1);
esp_err_t err = esp_wifi_set_max_tx_power(floor(max_power * 4 + 0.5));
if (err != ESP_OK)
return luaL_error(L, "failed to set transmit power, code %d", err);
lua_pushboolean(L, err == ESP_OK);
return 1;
}
static int wifi_sta_sethostname(lua_State *L)
{
size_t l;
@ -440,8 +455,9 @@ static int wifi_sta_scan (lua_State *L)
LROT_BEGIN(wifi_sta, NULL, 0)
LROT_FUNCENTRY( setip, wifi_sta_setip )
LROT_FUNCENTRY( sethostname, wifi_sta_sethostname )
LROT_FUNCENTRY( config, wifi_sta_config )
LROT_FUNCENTRY( sethostname, wifi_sta_sethostname)
LROT_FUNCENTRY( settxpower, wifi_sta_settxpower)
LROT_FUNCENTRY( config, wifi_sta_config)
LROT_FUNCENTRY( connect, wifi_sta_connect )
LROT_FUNCENTRY( disconnect, wifi_sta_disconnect )
LROT_FUNCENTRY( getconfig, wifi_sta_getconfig )

View File

@ -233,6 +233,27 @@ Disconnects from AP in station mode.
- [`wifi.sta.connect()`](#wifistaconnect)
## wifi.sta.settxpower
Allows adjusting the maximum TX power for the WiFi. This is (unfortunately) needed for some boards which
have a badly matched antenna.
#### Syntax
`wifi.sta.settxpower(power)`
#### Parameters
- `power` The maximum transmit power in dBm. This must have the range 2dBm - 20dBm. This value is a float.
#### Returns
A `boolean` where `true` is OK.
#### Example
```
# Needed for the WEMOS C3 Mini
wifi.sta.settxpower(8.5)
```
## wifi.sta.on()
Registers callbacks for WiFi station status events.