Unverified Commit c7cab0ab authored by Philip Gladstone's avatar Philip Gladstone Committed by GitHub
Browse files

Adds support for settxpower (#3535)



* Adds support for settxpower

* Update docs/modules/wifi.md
Co-authored-by: default avatarMarcel Stör <marcelstoer@users.noreply.github.com>

* Update docs/modules/wifi.md
Co-authored-by: default avatarMarcel Stör <marcelstoer@users.noreply.github.com>
Co-authored-by: default avatarMarcel Stör <marcelstoer@users.noreply.github.com>
parent 99656356
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "nodemcu_esp_event.h" #include "nodemcu_esp_event.h"
#include <string.h> #include <string.h>
#include "esp_netif.h" #include "esp_netif.h"
#include <math.h>
static esp_netif_t *wifi_sta = NULL; static esp_netif_t *wifi_sta = NULL;
static int scan_cb_ref = LUA_NOREF; static int scan_cb_ref = LUA_NOREF;
...@@ -207,6 +208,20 @@ static int wifi_sta_setip(lua_State *L) ...@@ -207,6 +208,20 @@ static int wifi_sta_setip(lua_State *L)
return 0; 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) static int wifi_sta_sethostname(lua_State *L)
{ {
size_t l; size_t l;
...@@ -440,8 +455,9 @@ static int wifi_sta_scan (lua_State *L) ...@@ -440,8 +455,9 @@ static int wifi_sta_scan (lua_State *L)
LROT_BEGIN(wifi_sta, NULL, 0) LROT_BEGIN(wifi_sta, NULL, 0)
LROT_FUNCENTRY( setip, wifi_sta_setip ) LROT_FUNCENTRY( setip, wifi_sta_setip )
LROT_FUNCENTRY( sethostname, wifi_sta_sethostname ) LROT_FUNCENTRY( sethostname, wifi_sta_sethostname)
LROT_FUNCENTRY( config, wifi_sta_config ) LROT_FUNCENTRY( settxpower, wifi_sta_settxpower)
LROT_FUNCENTRY( config, wifi_sta_config)
LROT_FUNCENTRY( connect, wifi_sta_connect ) LROT_FUNCENTRY( connect, wifi_sta_connect )
LROT_FUNCENTRY( disconnect, wifi_sta_disconnect ) LROT_FUNCENTRY( disconnect, wifi_sta_disconnect )
LROT_FUNCENTRY( getconfig, wifi_sta_getconfig ) LROT_FUNCENTRY( getconfig, wifi_sta_getconfig )
......
...@@ -233,6 +233,27 @@ Disconnects from AP in station mode. ...@@ -233,6 +233,27 @@ Disconnects from AP in station mode.
- [`wifi.sta.connect()`](#wifistaconnect) - [`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() ## wifi.sta.on()
Registers callbacks for WiFi station status events. Registers callbacks for WiFi station status events.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment