Skip to content

Commit

Permalink
Add WiFi provisioning and connection support
Browse files Browse the repository at this point in the history
  • Loading branch information
valletw committed May 27, 2024
1 parent f2d8a04 commit 8290758
Show file tree
Hide file tree
Showing 6 changed files with 345 additions and 19 deletions.
58 changes: 40 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,6 @@ flowchart
UPnP_CP -. WiFi .-> UPnP_R
```

## Build and program

For fast development, this project uses PlatformIO tools.

```shell
# Build project.
pio run

# Clean build files.
pio run --target clean

# Upload firmware.
pio run --target upload

# Erase device.
pio run --target erase
```

## Supported commands

The following control commands are:
Expand Down Expand Up @@ -71,3 +53,43 @@ Next | 0x18 | 0x48
Volume Up | 0x0C | 0x0F
Volume Down | 0x10 | 0x07
Mute | 0x04 | 0x0B

## WiFi provisioning

In order to avoid passing user credentials at compilation, SoftAP WiFi
provisioning method is used to send the user credentials and connect to the WiFi
network.

To exchange the user credentials, it is required to use the Espressif provisioning
application (information
[here](https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/provisioning/wifi_provisioning.html#provisioning-tools)).

Note: SoftAP is used, but it seems that the mobile application is not working.
Using the BLE application configured with SoftAP method works.

Default provisioning configuration:

- SSID: `UPnP Remote XXXXXX`
- Password: `P@ssw0rd`
- Proof of Possession: `abcd1234`

The default configuration can be override at compilation, check `build_flags`.
The SSID is suffixed by the 3 LSB of the MAC address.

## Build and program

For fast development, this project uses PlatformIO tools.

```shell
# Build project.
pio run

# Clean build files.
pio run --target clean

# Upload firmware.
pio run --target upload

# Erase device.
pio run --target erase
```
11 changes: 11 additions & 0 deletions include/wifi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* MIT License
* Copyright (c) 2024 William Vallet
*/

#ifndef WIFI_H_
#define WIFI_H_

extern void wifi_init(void);

#endif // WIFI_H_
3 changes: 3 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ framework = espidf
monitor_speed = 115200
build_flags =
-DIR_CODESET_CFG=0
# -DWIFI_PROV_SSID=""
# -DWIFI_PROV_PASS=""
# -DWIFI_PROV_PROOF=""

[env:esp-ir-receiver]
board = esp-ir-receiver
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
idf_component_register(
SRCS
main.c board.c led.c ir_decoder.c ir_decoder_nec.c
command.c
command.c wifi.c
)
20 changes: 20 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
#include "command.h"
#include "ir_decoder.h"
#include "led.h"
#include "wifi.h"
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_event.h"
#include "esp_flash.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include <stdio.h>
#include <stdint.h>

Expand Down Expand Up @@ -45,12 +48,29 @@ static void display_chip_information(void)
(chip_info.features & CHIP_FEATURE_IEEE802154) ? " IEEE-802.15.4" : "");
}

static void env_init(void)
{
// Storage initialisation.
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES
|| ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
{
ESP_ERROR_CHECK(nvs_flash_erase());
ESP_ERROR_CHECK(nvs_flash_init());
}
// Event loop initialisation.
ESP_ERROR_CHECK(esp_event_loop_create_default());
}

void app_main(void)
{
board_initialise();
esp_log_level_set("*", ESP_LOG_INFO);
ESP_LOGI(LOGGER_TAG, "*** ESP UPnP remote ***");
display_chip_information();
// Initialise WiFi (provisioning or connection).
env_init();
wifi_init();
// Initialise command processing.
command_init();
// IR decoder configuration.
Expand Down
Loading

0 comments on commit 8290758

Please sign in to comment.