Static IP parameters for STA mode
This commit is contained in:
@@ -38,11 +38,18 @@ There are the supported parameters:
|
||||
| reboot | 0 | Reboot the WiFi Bridge | http://192.168.4.1/setparameters?reboot=1 |
|
||||
| ssid | PixRacer | WiFi AP SSID | http://192.168.4.1/setparameters?ssid=PixRacer |
|
||||
| ssidsta | PixRacer | WiFi STA SSID | http://192.168.4.1/setparameters?ssidsta=PixRacer |
|
||||
| ipsta | 0.0.0.0 | Wifi STA Static IP | http://192.168.4.1/setparameters?ipsta=192.168.4.2 |
|
||||
| gatewaysta | 0.0.0.0 | Wifi STA Gateway | http://192.168.4.1/setparameters?gatewaysta=192.168.4.1 |
|
||||
| subnetsta | 0.0.0.0 | Wifi STA Subnet | http://192.168.4.1/setparameters?subnetsta=255.255.255.0 |
|
||||
|
||||
You can combine any number of parameters into one request. For example:
|
||||
|
||||
http://192.168.4.1/setparameters?baud=921600&channel=9&reboot=1
|
||||
|
||||
To connect to a typical existing network with a static ip:
|
||||
|
||||
http://192.168.4.1/setparameters?mode=1&ssidsta=networkname&pwdsta=thepassword&ipsta=192.168.1.123&gatewaysta=192.168.1.1&subnetsta=255.255.255.0
|
||||
|
||||
##### Upload New Firmware
|
||||
|
||||
http://192.168.4.1/update
|
||||
|
||||
+5
-1
@@ -43,6 +43,9 @@ If this message is sent specifically to the MavESP8266 component ID, it will set
|
||||
| WIFI_SSIDSTA2 | MAV_PARAM_TYPE_UINT32 | |
|
||||
| WIFI_SSIDSTA3 | MAV_PARAM_TYPE_UINT32 | |
|
||||
| WIFI_SSIDSTA4 | MAV_PARAM_TYPE_UINT32 | |
|
||||
| WIFI_IPSTA | MAV_PARAM_TYPE_UINT32 | Wifi STA Static IP Address (4) |
|
||||
| WIFI_GATEWAYSTA | MAV_PARAM_TYPE_UINT32 | Wifi STA Gateway Address (4) |
|
||||
| WIFI_SUBNETSTA | MAV_PARAM_TYPE_UINT32 | Wifi STA Subnet Address (4) |
|
||||
| WIFI_UDP_CPORT | MAV_PARAM_TYPE_UINT16 | Local UDP Port (default to 14555) |
|
||||
| WIFI_UDP_HPORT | MAV_PARAM_TYPE_UINT16 | GCS UDP Port (default to 14550) |
|
||||
|
||||
@@ -51,6 +54,7 @@ If this message is sent specifically to the MavESP8266 component ID, it will set
|
||||
* (1) If debug is enabled, debug messages are sent using ```MAVLINK_MSG_ID_STATUSTEXT``` with a proper ```MAV_SEVERITY_DEBUG``` type. Other messages types, ```MAV_SEVERITY_NOTICE``` for example, are sent regardless.
|
||||
* (2) MavLink parameter messages only support a 32-Bit parameter (be it a float, an uint32_t, etc.) In other to fit a 16-character SSID and a 16-character Password, 4 paramaters are used for each. The 32-Bit storage is used to contain 4 bytes for the string.
|
||||
* (3) The mode defaults to 0. Set to 0 to act as an Access Point. Set to 1 to connect to an existing WiFi network using the STA (Station Mode) SSID and password. When in *Station Mode*, the module will attempt to connect for up to one minute. If after that it cannot connect, it reverts to AP mode.
|
||||
* (4) Defaults to 0 for an unset address. If either the STA IP, Gateway, or Subnet are set, then all three need to be set for it to work properly.
|
||||
|
||||
#### MAVLINK_MSG_ID_COMMAND_LONG
|
||||
|
||||
@@ -59,7 +63,7 @@ In addition to parameters, MavESP8266 also supports a few commands, which will b
|
||||
##### MAV_CMD_PREFLIGHT_STORAGE
|
||||
|
||||
* If ```param1``` == 0 It will load all parameters from EEPROM overwriting any changes.
|
||||
* If ```param1``` == 1 It will save all current parameters to EEPROM.
|
||||
* If ```param1``` == 1 It will save all current parameters to EEPROM.
|
||||
* If ```param1``` == 2 It will reset all parameters to the original default values. Note that it will not store them to EEPROM. You must request that separately if that's what you want to do.
|
||||
|
||||
##### MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN
|
||||
|
||||
@@ -154,7 +154,9 @@ void setup() {
|
||||
if(Parameters.getWifiMode() == WIFI_MODE_STA){
|
||||
//-- Connect to an existing network
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.config(Parameters.getWifiStaIP(), Parameters.getWifiStaGateway(), Parameters.getWifiStaSubnet(), 0U, 0U);
|
||||
WiFi.begin(Parameters.getWifiStaSsid(), Parameters.getWifiStaPassword());
|
||||
|
||||
//-- Wait a minute to connect
|
||||
for(int i = 0; i < 120 && WiFi.status() != WL_CONNECTED; i++) {
|
||||
#ifdef ENABLE_DEBUG
|
||||
@@ -198,6 +200,8 @@ void setup() {
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
//-- Initialize Comm Links
|
||||
DEBUG_LOG("Start WiFi Bridge\n");
|
||||
DEBUG_LOG("Local IP: %s\n", localIP.toString().c_str());
|
||||
|
||||
Parameters.setLocalIPAddress(localIP);
|
||||
IPAddress gcs_ip(localIP);
|
||||
//-- I'm getting bogus IP from the DHCP server. Broadcasting for now.
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ class MavESP8266GCS;
|
||||
//-- TODO: This needs to come from the build system
|
||||
#define MAVESP8266_VERSION_MAJOR 1
|
||||
#define MAVESP8266_VERSION_MINOR 0
|
||||
#define MAVESP8266_VERSION_BUILD 10
|
||||
#define MAVESP8266_VERSION_BUILD 11
|
||||
#define MAVESP8266_VERSION ((MAVESP8266_VERSION_MAJOR << 24) & 0xFF00000) | ((MAVESP8266_VERSION_MINOR << 16) & 0x00FF0000) | (MAVESP8266_VERSION_BUILD & 0xFFFF)
|
||||
|
||||
//-- Debug sent out to Serial1 (GPIO02), which is TX only (no RX).
|
||||
|
||||
@@ -56,6 +56,9 @@ const char* kPWD = "pwd";
|
||||
const char* kSSID = "ssid";
|
||||
const char* kPWDSTA = "pwdsta";
|
||||
const char* kSSIDSTA = "ssidsta";
|
||||
const char* kIPSTA = "ipsta";
|
||||
const char* kGATESTA = "gatewaysta";
|
||||
const char* kSUBSTA = "subnetsta";
|
||||
const char* kCPORT = "cport";
|
||||
const char* kHPORT = "hport";
|
||||
const char* kCHANNEL = "channel";
|
||||
@@ -345,6 +348,21 @@ void handle_setParameters()
|
||||
ok = true;
|
||||
getWorld()->getParameters()->setWifiStaSsid(webServer.arg(kSSIDSTA).c_str());
|
||||
}
|
||||
if(webServer.hasArg(kIPSTA)) {
|
||||
IPAddress ip;
|
||||
ip.fromString(webServer.arg(kIPSTA).c_str());
|
||||
getWorld()->getParameters()->setWifiStaIP(ip);
|
||||
}
|
||||
if(webServer.hasArg(kGATESTA)) {
|
||||
IPAddress ip;
|
||||
ip.fromString(webServer.arg(kGATESTA).c_str());
|
||||
getWorld()->getParameters()->setWifiStaGateway(ip);
|
||||
}
|
||||
if(webServer.hasArg(kSUBSTA)) {
|
||||
IPAddress ip;
|
||||
ip.fromString(webServer.arg(kSUBSTA).c_str());
|
||||
getWorld()->getParameters()->setWifiStaSubnet(ip);
|
||||
}
|
||||
if(webServer.hasArg(kCPORT)) {
|
||||
ok = true;
|
||||
getWorld()->getParameters()->setWifiUdpCport(webServer.arg(kCPORT).toInt());
|
||||
|
||||
@@ -59,6 +59,9 @@ char _wifi_ssid[16];
|
||||
char _wifi_password[16];
|
||||
char _wifi_ssidsta[16];
|
||||
char _wifi_passwordsta[16];
|
||||
uint32_t _wifi_ipsta;
|
||||
uint32_t _wifi_gatewaysta;
|
||||
uint32_t _wifi_subnetsta;
|
||||
uint32_t _uart_baud_rate;
|
||||
uint32_t _flash_left;
|
||||
|
||||
@@ -88,6 +91,9 @@ uint32_t _flash_left;
|
||||
{"WIFI_PWDSTA2", &_wifi_passwordsta[4], MavESP8266Parameters::ID_PASSSTA2, sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
|
||||
{"WIFI_PWDSTA3", &_wifi_passwordsta[8], MavESP8266Parameters::ID_PASSSTA3, sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
|
||||
{"WIFI_PWDSTA4", &_wifi_passwordsta[12], MavESP8266Parameters::ID_PASSSTA4, sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
|
||||
{"WIFI_IPSTA", &_wifi_ipsta, MavESP8266Parameters::ID_IPSTA, sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
|
||||
{"WIFI_GATEWAYSTA", &_wifi_gatewaysta, MavESP8266Parameters::ID_GATEWAYSTA,sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
|
||||
{"WIFI_SUBNET_STA", &_wifi_subnetsta, MavESP8266Parameters::ID_SUBNETSTA, sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false},
|
||||
{"UART_BAUDRATE", &_uart_baud_rate, MavESP8266Parameters::ID_UART, sizeof(uint32_t), MAV_PARAM_TYPE_UINT32, false}
|
||||
};
|
||||
|
||||
@@ -141,6 +147,9 @@ char* MavESP8266Parameters::getWifiSsid () { return _wifi_ssid;
|
||||
char* MavESP8266Parameters::getWifiPassword () { return _wifi_password; }
|
||||
char* MavESP8266Parameters::getWifiStaSsid () { return _wifi_ssidsta; }
|
||||
char* MavESP8266Parameters::getWifiStaPassword() { return _wifi_passwordsta; }
|
||||
uint32_t MavESP8266Parameters::getWifiStaIP () { return _wifi_ipsta; }
|
||||
uint32_t MavESP8266Parameters::getWifiStaGateway () { return _wifi_gatewaysta; }
|
||||
uint32_t MavESP8266Parameters::getWifiStaSubnet () { return _wifi_subnetsta; }
|
||||
uint32_t MavESP8266Parameters::getUartBaudRate () { return _uart_baud_rate; }
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
@@ -155,6 +164,9 @@ MavESP8266Parameters::resetToDefaults()
|
||||
_wifi_udp_hport = DEFAULT_UDP_HPORT;
|
||||
_wifi_udp_cport = DEFAULT_UDP_CPORT;
|
||||
_uart_baud_rate = DEFAULT_UART_SPEED;
|
||||
_wifi_ipsta = 0;
|
||||
_wifi_gatewaysta = 0;
|
||||
_wifi_subnetsta = 0;
|
||||
strncpy(_wifi_ssid, kDEFAULT_SSID, sizeof(_wifi_ssid));
|
||||
strncpy(_wifi_password, kDEFAULT_PASSWORD, sizeof(_wifi_password));
|
||||
strncpy(_wifi_ssidsta, kDEFAULT_SSID, sizeof(_wifi_ssidsta));
|
||||
@@ -370,6 +382,27 @@ MavESP8266Parameters::setWifiStaPassword(const char* pwd)
|
||||
strncpy(_wifi_passwordsta, pwd, sizeof(_wifi_passwordsta));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void
|
||||
MavESP8266Parameters::setWifiStaIP(uint32_t addr)
|
||||
{
|
||||
_wifi_ipsta = addr;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void
|
||||
MavESP8266Parameters::setWifiStaGateway(uint32_t addr)
|
||||
{
|
||||
_wifi_gatewaysta = addr;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void
|
||||
MavESP8266Parameters::setWifiStaSubnet(uint32_t addr)
|
||||
{
|
||||
_wifi_subnetsta = addr;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void
|
||||
MavESP8266Parameters::setUartBaudRate(uint32_t baud)
|
||||
|
||||
@@ -85,6 +85,9 @@ public:
|
||||
ID_PASSSTA2,
|
||||
ID_PASSSTA3,
|
||||
ID_PASSSTA4,
|
||||
ID_IPSTA,
|
||||
ID_GATEWAYSTA,
|
||||
ID_SUBNETSTA,
|
||||
ID_UART,
|
||||
ID_COUNT
|
||||
};
|
||||
@@ -105,6 +108,9 @@ public:
|
||||
char* getWifiPassword ();
|
||||
char* getWifiStaSsid ();
|
||||
char* getWifiStaPassword ();
|
||||
uint32_t getWifiStaIP ();
|
||||
uint32_t getWifiStaGateway ();
|
||||
uint32_t getWifiStaSubnet ();
|
||||
uint32_t getUartBaudRate ();
|
||||
|
||||
void setDebugEnabled (int8_t enabled);
|
||||
@@ -116,6 +122,9 @@ public:
|
||||
void setWifiPassword (const char* pwd);
|
||||
void setWifiStaSsid (const char* ssid);
|
||||
void setWifiStaPassword (const char* pwd);
|
||||
void setWifiStaIP (uint32_t addr);
|
||||
void setWifiStaGateway (uint32_t addr);
|
||||
void setWifiStaSubnet (uint32_t addr);
|
||||
void setUartBaudRate (uint32_t baud);
|
||||
void setLocalIPAddress (uint32_t ipAddress);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user