Skip to content

Commit

Permalink
Sat Dec 24 09:55:41 CST 2016
Browse files Browse the repository at this point in the history
  • Loading branch information
kolban committed Dec 24, 2016
1 parent 3670639 commit b232989
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 6 deletions.
57 changes: 52 additions & 5 deletions error handling/fragments/espToError.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <esp_err.h>
#include <nvs.h>
#include <esp_wifi.h>

char *espToString(esp_err_t value) {
switch(value) {
Expand All @@ -20,9 +22,54 @@ char *espToString(esp_err_t value) {
return "Not supported";
case ESP_ERR_TIMEOUT:
return "Timeout";
case ESP_ERR_NVS_NOT_INITIALIZED:
return "ESP_ERR_NVS_NOT_INITIALIZED";
case ESP_ERR_NVS_NOT_FOUND:
return "ESP_ERR_NVS_NOT_FOUND";
case ESP_ERR_NVS_TYPE_MISMATCH:
return "ESP_ERR_NVS_TYPE_MISMATCH";
case ESP_ERR_NVS_READ_ONLY:
return "ESP_ERR_NVS_READ_ONLY";
case ESP_ERR_NVS_NOT_ENOUGH_SPACE:
return "ESP_ERR_NVS_NOT_ENOUGH_SPACE";
case ESP_ERR_NVS_INVALID_NAME:
return "ESP_ERR_NVS_INVALID_NAME";
case ESP_ERR_NVS_INVALID_HANDLE:
return "ESP_ERR_NVS_INVALID_HANDLE";
case ESP_ERR_NVS_REMOVE_FAILED:
return "ESP_ERR_NVS_REMOVE_FAILED";
case ESP_ERR_NVS_KEY_TOO_LONG:
return "ESP_ERR_NVS_KEY_TOO_LONG";
case ESP_ERR_NVS_PAGE_FULL:
return "ESP_ERR_NVS_PAGE_FULL";
case ESP_ERR_NVS_INVALID_STATE:
return "ESP_ERR_NVS_INVALID_STATE";
case ESP_ERR_NVS_INVALID_LENGTH:
return "ESP_ERR_NVS_INVALID_LENGTH";
case ESP_ERR_WIFI_NOT_INIT:
return "ESP_ERR_WIFI_NOT_INIT";
case ESP_ERR_WIFI_NOT_START:
return "ESP_ERR_WIFI_NOT_START";
case ESP_ERR_WIFI_IF:
return "ESP_ERR_WIFI_IF";
case ESP_ERR_WIFI_MODE:
return "ESP_ERR_WIFI_MODE";
case ESP_ERR_WIFI_STATE:
return "ESP_ERR_WIFI_STATE";
case ESP_ERR_WIFI_CONN:
return "ESP_ERR_WIFI_CONN";
case ESP_ERR_WIFI_NVS:
return "ESP_ERR_WIFI_NVS";
case ESP_ERR_WIFI_MAC:
return "ESP_ERR_WIFI_MAC";
case ESP_ERR_WIFI_SSID:
return "ESP_ERR_WIFI_SSID";
case ESP_ERR_WIFI_PASSWORD:
return "ESP_ERR_WIFI_PASSWORD";
case ESP_ERR_WIFI_TIMEOUT:
return "ESP_ERR_WIFI_TIMEOUT";
case ESP_ERR_WIFI_WAKE_FAIL:
return "ESP_ERR_WIFI_WAKE_FAIL";
}
if (value >= ESP_ERR_WIFI_BASE) {
return "WiFi error";
}
return "Unknown error";
}
return "Unknown ESP_ERR error";
} // espToString
29 changes: 29 additions & 0 deletions filesystems/espfs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#The ESP FS
A fantastic project by Mr SpriteTM can be found here:

[https://github.com/Spritetm/libesphttpd/tree/master/espfs](https://github.com/Spritetm/libesphttpd/tree/master/espfs)

This provides an ESP File System that is read only and stored on flash.

Here, you will find a copy of those core files that have been massaged to utilize ESP32 technologies.
Primarily, we use flash memory mapping to access the data as opposed to individual flash reads. In addition,
and the primary intent, a new method was added with the signature:

```
int espFsAccess(EspFsFile *fh, char *buf, size_t *len)
```

This function returns a pointer to the whole content of the file which is stored in buf. The
length of the file is stored in len and also returned from the function as a whole.
The data is accessed directly from flash without any RAM copies.
In addition, the function called:

```
EspFsInitResult espFsInit(void *flashAddress, size_t size)
```

was augmented to include the size of the flash storage to map.

For full details and background, see the following thread on the ESP32 forum:

[http://esp32.com/viewtopic.php?f=13&t=698](http://esp32.com/viewtopic.php?f=13&t=698)
19 changes: 18 additions & 1 deletion networking/bootwifi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,21 @@ dramatically improved. Features to be added include
* mDNS support when available.
* Component configuration options including:
- Network SSID to use when being an access point.
- Network password to use when being an access point (if any).
- Network password to use when being an access point (if any).

##Design and implementation notes
The parameters for Bootwifi are stored in Non-Volatile Storage (NVS). The name space in NVS
is "bootwifi". The keys are:

* version - The version of the protocol.
* connectionInfo - The details for connection.

The form shown to the end user sends back a response as an HTTP POST to "/ssidSelected".
which contains the following form fields:

* ssid
* password
* ip
* gw
* netmask

Empty file added nvs/fragments/errorToString.c
Empty file.
38 changes: 38 additions & 0 deletions vfs/spiffs/spiffs_vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,36 @@

static char tag[] = "spiffs_vfs";

static char *spiffsErrorToString(int code) {
static char msg[10];
switch(code) {
case SPIFFS_OK:
return "SPIFFS_OK";
case SPIFFS_ERR_NOT_MOUNTED:
return "SPIFFS_ERR_NOT_MOUNTED";
case SPIFFS_ERR_FULL:
return "SPIFFS_ERR_FULL";
case SPIFFS_ERR_NOT_FOUND:
return "SPIFFS_ERR_NOT_FOUND";
case SPIFFS_ERR_END_OF_OBJECT:
return "SPIFFS_ERR_END_OF_OBJECT";
case SPIFFS_ERR_DELETED:
return "SPIFFS_ERR_DELETED";
case SPIFFS_ERR_FILE_CLOSED:
return "SPIFFS_ERR_FILE_CLOSED";
case SPIFFS_ERR_FILE_DELETED:
return "SPIFFS_ERR_FILE_DELETED";
case SPIFFS_ERR_BAD_DESCRIPTOR:
return "SPIFFS_ERR_BAD_DESCRIPTOR";
case SPIFFS_ERR_NOT_A_FS:
return "SPIFFS_ERR_NOT_A_FS";
case SPIFFS_ERR_FILE_EXISTS:
return "SPIFFS_ERR_FILE_EXISTS";
}
sprintf(msg, "%d", code);
return msg;
}

/*
static int spiffsErrMap(spiffs *fs) {
int errorCode = SPIFFS_errno(fs);
Expand Down Expand Up @@ -145,6 +175,13 @@ static int vfs_link(void *ctx, const char *oldPath, const char *newPath) {
return 0;
} // vfs_link

static int vfs_unlink(void *ctx, const char *path, ) {
ESP_LOGI(tag, ">> unlink path=%s", path);
spiffs *fs = (spiffs *)ctx;
SPIFFS_remove(fs, path);
return 0;
} // vfs_unlink


static int vfs_rename(void *ctx, const char *oldPath, const char *newPath) {
ESP_LOGI(tag, ">> rename oldPath=%s, newPath=%s", oldPath, newPath);
Expand Down Expand Up @@ -174,6 +211,7 @@ void spiffs_registerVFS(char *mountPoint, spiffs *fs) {
vfs.fstat_p = vfs_fstat;
vfs.stat_p = vfs_stat;
vfs.link_p = vfs_link;
vfs.ulink_p = vfs_ulink;
vfs.rename_p = vfs_rename;

err = esp_vfs_register(mountPoint, &vfs, (void *)fs);
Expand Down
6 changes: 6 additions & 0 deletions vfs/vfs-skeleton/main/vfsTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ static int vfs_link(const char *oldPath, const char *newPath) {
return 0;
}

static int vfs_unlink(const char *path) {
ESP_LOGI(tag, ">> unlink path=%s", path);
return 0;
}


static int vfs_rename(const char *oldPath, const char *newPath) {
ESP_LOGI(tag, ">> rename oldPath=%s, newPath=%s", oldPath, newPath);
Expand Down Expand Up @@ -133,6 +138,7 @@ void registerTestVFS(char *mountPoint) {
vfs.fstat = vfs_fstat;
vfs.stat = vfs_stat;
vfs.link = vfs_link;
vfs.unlink = vfs_unlink;
vfs.rename = vfs_rename;

err = esp_vfs_register(mountPoint, &vfs, NULL);
Expand Down
72 changes: 72 additions & 0 deletions wifi/fragments/access-point.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Test being an access point. When we run this app, watch the console and look
* for a message of the form:
*
* event: SYSTEM_EVENT_AP_START
*
* This means that we have started being an access point.
*
* Now connect your WiFi client device (phone/PC) and we should see a message:
*
* event: SYSTEM_EVENT_AP_STACONNECTED, mac:7c:dd:90:9e:b5:62, aid:1
*
* This says that we have now connected.
*
*/
#include <esp_event.h>
#include <esp_event_loop.h>
#include <esp_log.h>
#include <esp_system.h>
#include <esp_wifi.h>
#include <freertos/FreeRTOS.h>
#include <nvs_flash.h>

//static char tag[] = "access-point";

/**
* An ESP32 WiFi event handler.
* The types of events that can be received here are:
*
* SYSTEM_EVENT_AP_PROBEREQRECVED
* SYSTEM_EVENT_AP_STACONNECTED
* SYSTEM_EVENT_AP_STADISCONNECTED
* SYSTEM_EVENT_AP_START
* SYSTEM_EVENT_AP_STOP
* SYSTEM_EVENT_SCAN_DONE
* SYSTEM_EVENT_STA_AUTHMODE_CHANGE
* SYSTEM_EVENT_STA_CONNECTED
* SYSTEM_EVENT_STA_DISCONNECTED
* SYSTEM_EVENT_STA_GOT_IP
* SYSTEM_EVENT_STA_START
* SYSTEM_EVENT_STA_STOP
* SYSTEM_EVENT_WIFI_READY
*/
esp_err_t esp32_wifi_eventHandler(void *ctx, system_event_t *event) {
// Your event handling code here...
return ESP_OK;
}

void access_point_task(void *ignore) {
nvs_flash_init();
tcpip_adapter_init();
ESP_ERROR_CHECK( esp_event_loop_init(esp32_wifi_eventHandler, NULL) );
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) );
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_AP) );
wifi_config_t apConfig = {
.ap = {
.ssid="ESP32_TESTAP",
.ssid_len=0,
.password="",
.channel=0,
.authmode=WIFI_AUTH_OPEN,
.ssid_hidden=0,
.max_connection=4,
.beacon_interval=100
}
};
ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_AP, &apConfig) );
ESP_ERROR_CHECK( esp_wifi_start() );
vTaskDelete(NULL);
}

0 comments on commit b232989

Please sign in to comment.