Skip to content

Commit

Permalink
add fallback network
Browse files Browse the repository at this point in the history
  • Loading branch information
kendallgoto committed Apr 17, 2022
1 parent 5ac52d7 commit eddc1ba
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions espressif/main/include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
#define WRITE_SIZE 0x171000

#define FALLBACK_URL "http://www.wohand.com/app.bin"
#define FALLBACK_SSID "switchbota"
#define FALLBACK_PASS "switchbota"
20 changes: 18 additions & 2 deletions espressif/main/wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <string.h>

#include "esp_system.h"
#include "esp_wifi.h"
Expand All @@ -26,6 +27,7 @@
#include "lwip/sys.h"

#include "wifi.h"
#include "config.h"

static const char *TAG = "wireless";

Expand Down Expand Up @@ -100,8 +102,22 @@ void wifi_connect()
{
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));

// get default config ...
wifi_config_t existing_config = { 0 };
esp_wifi_get_config(WIFI_IF_STA, &existing_config);
ESP_LOGI(TAG, "%s", existing_config.sta.ssid);
if(strlen((char *)existing_config.sta.ssid) == 0 || strcmp((char *)existing_config.sta.ssid, "wocao_factory_test") == 0) {
ESP_LOGI(TAG, "defaulting to fallback network ...");
wifi_config_t fallback_config = {
.sta = {
.ssid = FALLBACK_SSID,
.password = FALLBACK_PASS
}
};
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &fallback_config));
}

ESP_ERROR_CHECK(esp_wifi_start());
}

Expand Down
7 changes: 4 additions & 3 deletions espressif/sdkconfig.old
Original file line number Diff line number Diff line change
Expand Up @@ -1043,11 +1043,11 @@ CONFIG_PTHREAD_TASK_NAME_DEFAULT="pthread"
# SPI Flash driver
#
CONFIG_SPI_FLASH_VERIFY_WRITE=y
CONFIG_SPI_FLASH_LOG_FAILED_WRITE=y
CONFIG_SPI_FLASH_WARN_SETTING_ZERO_TO_ONE=y
# CONFIG_SPI_FLASH_LOG_FAILED_WRITE is not set
# CONFIG_SPI_FLASH_WARN_SETTING_ZERO_TO_ONE is not set
# CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set
CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y
CONFIG_SPI_FLASH_ROM_IMPL=y
# CONFIG_SPI_FLASH_ROM_IMPL is not set
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS is not set
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS is not set
CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED=y
Expand All @@ -1057,6 +1057,7 @@ CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED=y
CONFIG_SPI_FLASH_YIELD_DURING_ERASE=y
CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS=20
CONFIG_SPI_FLASH_ERASE_YIELD_TICKS=1
# CONFIG_SPI_FLASH_AUTO_SUSPEND is not set
CONFIG_SPI_FLASH_WRITE_CHUNK_SIZE=2048
# CONFIG_SPI_FLASH_SIZE_OVERRIDE is not set
# CONFIG_SPI_FLASH_CHECK_ERASE_TIMEOUT_DISABLED is not set
Expand Down

0 comments on commit eddc1ba

Please sign in to comment.