Skip to content

Commit b232989

Browse files
author
kolban
committed
Sat Dec 24 09:55:41 CST 2016
1 parent 3670639 commit b232989

File tree

7 files changed

+215
-6
lines changed

7 files changed

+215
-6
lines changed

error handling/fragments/espToError.c

+52-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include <esp_err.h>
2+
#include <nvs.h>
3+
#include <esp_wifi.h>
24

35
char *espToString(esp_err_t value) {
46
switch(value) {
@@ -20,9 +22,54 @@ char *espToString(esp_err_t value) {
2022
return "Not supported";
2123
case ESP_ERR_TIMEOUT:
2224
return "Timeout";
25+
case ESP_ERR_NVS_NOT_INITIALIZED:
26+
return "ESP_ERR_NVS_NOT_INITIALIZED";
27+
case ESP_ERR_NVS_NOT_FOUND:
28+
return "ESP_ERR_NVS_NOT_FOUND";
29+
case ESP_ERR_NVS_TYPE_MISMATCH:
30+
return "ESP_ERR_NVS_TYPE_MISMATCH";
31+
case ESP_ERR_NVS_READ_ONLY:
32+
return "ESP_ERR_NVS_READ_ONLY";
33+
case ESP_ERR_NVS_NOT_ENOUGH_SPACE:
34+
return "ESP_ERR_NVS_NOT_ENOUGH_SPACE";
35+
case ESP_ERR_NVS_INVALID_NAME:
36+
return "ESP_ERR_NVS_INVALID_NAME";
37+
case ESP_ERR_NVS_INVALID_HANDLE:
38+
return "ESP_ERR_NVS_INVALID_HANDLE";
39+
case ESP_ERR_NVS_REMOVE_FAILED:
40+
return "ESP_ERR_NVS_REMOVE_FAILED";
41+
case ESP_ERR_NVS_KEY_TOO_LONG:
42+
return "ESP_ERR_NVS_KEY_TOO_LONG";
43+
case ESP_ERR_NVS_PAGE_FULL:
44+
return "ESP_ERR_NVS_PAGE_FULL";
45+
case ESP_ERR_NVS_INVALID_STATE:
46+
return "ESP_ERR_NVS_INVALID_STATE";
47+
case ESP_ERR_NVS_INVALID_LENGTH:
48+
return "ESP_ERR_NVS_INVALID_LENGTH";
49+
case ESP_ERR_WIFI_NOT_INIT:
50+
return "ESP_ERR_WIFI_NOT_INIT";
51+
case ESP_ERR_WIFI_NOT_START:
52+
return "ESP_ERR_WIFI_NOT_START";
53+
case ESP_ERR_WIFI_IF:
54+
return "ESP_ERR_WIFI_IF";
55+
case ESP_ERR_WIFI_MODE:
56+
return "ESP_ERR_WIFI_MODE";
57+
case ESP_ERR_WIFI_STATE:
58+
return "ESP_ERR_WIFI_STATE";
59+
case ESP_ERR_WIFI_CONN:
60+
return "ESP_ERR_WIFI_CONN";
61+
case ESP_ERR_WIFI_NVS:
62+
return "ESP_ERR_WIFI_NVS";
63+
case ESP_ERR_WIFI_MAC:
64+
return "ESP_ERR_WIFI_MAC";
65+
case ESP_ERR_WIFI_SSID:
66+
return "ESP_ERR_WIFI_SSID";
67+
case ESP_ERR_WIFI_PASSWORD:
68+
return "ESP_ERR_WIFI_PASSWORD";
69+
case ESP_ERR_WIFI_TIMEOUT:
70+
return "ESP_ERR_WIFI_TIMEOUT";
71+
case ESP_ERR_WIFI_WAKE_FAIL:
72+
return "ESP_ERR_WIFI_WAKE_FAIL";
2373
}
24-
if (value >= ESP_ERR_WIFI_BASE) {
25-
return "WiFi error";
26-
}
27-
return "Unknown error";
28-
}
74+
return "Unknown ESP_ERR error";
75+
} // espToString

filesystems/espfs/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#The ESP FS
2+
A fantastic project by Mr SpriteTM can be found here:
3+
4+
[https://github.com/Spritetm/libesphttpd/tree/master/espfs](https://github.com/Spritetm/libesphttpd/tree/master/espfs)
5+
6+
This provides an ESP File System that is read only and stored on flash.
7+
8+
Here, you will find a copy of those core files that have been massaged to utilize ESP32 technologies.
9+
Primarily, we use flash memory mapping to access the data as opposed to individual flash reads. In addition,
10+
and the primary intent, a new method was added with the signature:
11+
12+
```
13+
int espFsAccess(EspFsFile *fh, char *buf, size_t *len)
14+
```
15+
16+
This function returns a pointer to the whole content of the file which is stored in buf. The
17+
length of the file is stored in len and also returned from the function as a whole.
18+
The data is accessed directly from flash without any RAM copies.
19+
In addition, the function called:
20+
21+
```
22+
EspFsInitResult espFsInit(void *flashAddress, size_t size)
23+
```
24+
25+
was augmented to include the size of the flash storage to map.
26+
27+
For full details and background, see the following thread on the ESP32 forum:
28+
29+
[http://esp32.com/viewtopic.php?f=13&t=698](http://esp32.com/viewtopic.php?f=13&t=698)

networking/bootwifi/README.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,21 @@ dramatically improved. Features to be added include
5353
* mDNS support when available.
5454
* Component configuration options including:
5555
- Network SSID to use when being an access point.
56-
- Network password to use when being an access point (if any).
56+
- Network password to use when being an access point (if any).
57+
58+
##Design and implementation notes
59+
The parameters for Bootwifi are stored in Non-Volatile Storage (NVS). The name space in NVS
60+
is "bootwifi". The keys are:
61+
62+
* version - The version of the protocol.
63+
* connectionInfo - The details for connection.
64+
65+
The form shown to the end user sends back a response as an HTTP POST to "/ssidSelected".
66+
which contains the following form fields:
67+
68+
* ssid
69+
* password
70+
* ip
71+
* gw
72+
* netmask
73+

nvs/fragments/errorToString.c

Whitespace-only changes.

vfs/spiffs/spiffs_vfs.c

+38
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,36 @@
88

99
static char tag[] = "spiffs_vfs";
1010

11+
static char *spiffsErrorToString(int code) {
12+
static char msg[10];
13+
switch(code) {
14+
case SPIFFS_OK:
15+
return "SPIFFS_OK";
16+
case SPIFFS_ERR_NOT_MOUNTED:
17+
return "SPIFFS_ERR_NOT_MOUNTED";
18+
case SPIFFS_ERR_FULL:
19+
return "SPIFFS_ERR_FULL";
20+
case SPIFFS_ERR_NOT_FOUND:
21+
return "SPIFFS_ERR_NOT_FOUND";
22+
case SPIFFS_ERR_END_OF_OBJECT:
23+
return "SPIFFS_ERR_END_OF_OBJECT";
24+
case SPIFFS_ERR_DELETED:
25+
return "SPIFFS_ERR_DELETED";
26+
case SPIFFS_ERR_FILE_CLOSED:
27+
return "SPIFFS_ERR_FILE_CLOSED";
28+
case SPIFFS_ERR_FILE_DELETED:
29+
return "SPIFFS_ERR_FILE_DELETED";
30+
case SPIFFS_ERR_BAD_DESCRIPTOR:
31+
return "SPIFFS_ERR_BAD_DESCRIPTOR";
32+
case SPIFFS_ERR_NOT_A_FS:
33+
return "SPIFFS_ERR_NOT_A_FS";
34+
case SPIFFS_ERR_FILE_EXISTS:
35+
return "SPIFFS_ERR_FILE_EXISTS";
36+
}
37+
sprintf(msg, "%d", code);
38+
return msg;
39+
}
40+
1141
/*
1242
static int spiffsErrMap(spiffs *fs) {
1343
int errorCode = SPIFFS_errno(fs);
@@ -145,6 +175,13 @@ static int vfs_link(void *ctx, const char *oldPath, const char *newPath) {
145175
return 0;
146176
} // vfs_link
147177

178+
static int vfs_unlink(void *ctx, const char *path, ) {
179+
ESP_LOGI(tag, ">> unlink path=%s", path);
180+
spiffs *fs = (spiffs *)ctx;
181+
SPIFFS_remove(fs, path);
182+
return 0;
183+
} // vfs_unlink
184+
148185

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

179217
err = esp_vfs_register(mountPoint, &vfs, (void *)fs);

vfs/vfs-skeleton/main/vfsTest.c

+6
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ static int vfs_link(const char *oldPath, const char *newPath) {
106106
return 0;
107107
}
108108

109+
static int vfs_unlink(const char *path) {
110+
ESP_LOGI(tag, ">> unlink path=%s", path);
111+
return 0;
112+
}
113+
109114

110115
static int vfs_rename(const char *oldPath, const char *newPath) {
111116
ESP_LOGI(tag, ">> rename oldPath=%s, newPath=%s", oldPath, newPath);
@@ -133,6 +138,7 @@ void registerTestVFS(char *mountPoint) {
133138
vfs.fstat = vfs_fstat;
134139
vfs.stat = vfs_stat;
135140
vfs.link = vfs_link;
141+
vfs.unlink = vfs_unlink;
136142
vfs.rename = vfs_rename;
137143

138144
err = esp_vfs_register(mountPoint, &vfs, NULL);

wifi/fragments/access-point.c

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Test being an access point. When we run this app, watch the console and look
3+
* for a message of the form:
4+
*
5+
* event: SYSTEM_EVENT_AP_START
6+
*
7+
* This means that we have started being an access point.
8+
*
9+
* Now connect your WiFi client device (phone/PC) and we should see a message:
10+
*
11+
* event: SYSTEM_EVENT_AP_STACONNECTED, mac:7c:dd:90:9e:b5:62, aid:1
12+
*
13+
* This says that we have now connected.
14+
*
15+
*/
16+
#include <esp_event.h>
17+
#include <esp_event_loop.h>
18+
#include <esp_log.h>
19+
#include <esp_system.h>
20+
#include <esp_wifi.h>
21+
#include <freertos/FreeRTOS.h>
22+
#include <nvs_flash.h>
23+
24+
//static char tag[] = "access-point";
25+
26+
/**
27+
* An ESP32 WiFi event handler.
28+
* The types of events that can be received here are:
29+
*
30+
* SYSTEM_EVENT_AP_PROBEREQRECVED
31+
* SYSTEM_EVENT_AP_STACONNECTED
32+
* SYSTEM_EVENT_AP_STADISCONNECTED
33+
* SYSTEM_EVENT_AP_START
34+
* SYSTEM_EVENT_AP_STOP
35+
* SYSTEM_EVENT_SCAN_DONE
36+
* SYSTEM_EVENT_STA_AUTHMODE_CHANGE
37+
* SYSTEM_EVENT_STA_CONNECTED
38+
* SYSTEM_EVENT_STA_DISCONNECTED
39+
* SYSTEM_EVENT_STA_GOT_IP
40+
* SYSTEM_EVENT_STA_START
41+
* SYSTEM_EVENT_STA_STOP
42+
* SYSTEM_EVENT_WIFI_READY
43+
*/
44+
esp_err_t esp32_wifi_eventHandler(void *ctx, system_event_t *event) {
45+
// Your event handling code here...
46+
return ESP_OK;
47+
}
48+
49+
void access_point_task(void *ignore) {
50+
nvs_flash_init();
51+
tcpip_adapter_init();
52+
ESP_ERROR_CHECK( esp_event_loop_init(esp32_wifi_eventHandler, NULL) );
53+
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
54+
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
55+
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
56+
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_AP) );
57+
wifi_config_t apConfig = {
58+
.ap = {
59+
.ssid="ESP32_TESTAP",
60+
.ssid_len=0,
61+
.password="",
62+
.channel=0,
63+
.authmode=WIFI_AUTH_OPEN,
64+
.ssid_hidden=0,
65+
.max_connection=4,
66+
.beacon_interval=100
67+
}
68+
};
69+
ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_AP, &apConfig) );
70+
ESP_ERROR_CHECK( esp_wifi_start() );
71+
vTaskDelete(NULL);
72+
}

0 commit comments

Comments
 (0)