From b232989d1a165fdf36c500b6427fd3c39dd44d19 Mon Sep 17 00:00:00 2001 From: kolban Date: Sat, 24 Dec 2016 09:55:41 -0600 Subject: [PATCH] Sat Dec 24 09:55:41 CST 2016 --- error handling/fragments/espToError.c | 57 +++++++++++++++++++-- filesystems/espfs/README.md | 29 +++++++++++ networking/bootwifi/README.md | 19 ++++++- nvs/fragments/errorToString.c | 0 vfs/spiffs/spiffs_vfs.c | 38 ++++++++++++++ vfs/vfs-skeleton/main/vfsTest.c | 6 +++ wifi/fragments/access-point.c | 72 +++++++++++++++++++++++++++ 7 files changed, 215 insertions(+), 6 deletions(-) create mode 100644 filesystems/espfs/README.md create mode 100644 nvs/fragments/errorToString.c create mode 100644 wifi/fragments/access-point.c diff --git a/error handling/fragments/espToError.c b/error handling/fragments/espToError.c index f851da40..66e90eb9 100644 --- a/error handling/fragments/espToError.c +++ b/error handling/fragments/espToError.c @@ -1,4 +1,6 @@ #include +#include +#include char *espToString(esp_err_t value) { switch(value) { @@ -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 diff --git a/filesystems/espfs/README.md b/filesystems/espfs/README.md new file mode 100644 index 00000000..9726dcd7 --- /dev/null +++ b/filesystems/espfs/README.md @@ -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) \ No newline at end of file diff --git a/networking/bootwifi/README.md b/networking/bootwifi/README.md index edc3a99f..b6c8bfc2 100644 --- a/networking/bootwifi/README.md +++ b/networking/bootwifi/README.md @@ -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). \ No newline at end of file + - 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 + \ No newline at end of file diff --git a/nvs/fragments/errorToString.c b/nvs/fragments/errorToString.c new file mode 100644 index 00000000..e69de29b diff --git a/vfs/spiffs/spiffs_vfs.c b/vfs/spiffs/spiffs_vfs.c index 8332cbac..668e4727 100644 --- a/vfs/spiffs/spiffs_vfs.c +++ b/vfs/spiffs/spiffs_vfs.c @@ -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); @@ -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); @@ -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); diff --git a/vfs/vfs-skeleton/main/vfsTest.c b/vfs/vfs-skeleton/main/vfsTest.c index 5fc95650..f47ebbc8 100644 --- a/vfs/vfs-skeleton/main/vfsTest.c +++ b/vfs/vfs-skeleton/main/vfsTest.c @@ -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); @@ -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); diff --git a/wifi/fragments/access-point.c b/wifi/fragments/access-point.c new file mode 100644 index 00000000..cc299a55 --- /dev/null +++ b/wifi/fragments/access-point.c @@ -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 +#include +#include +#include +#include +#include +#include + +//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); +}