fix ade7758
This commit is contained in:
@@ -165,7 +165,7 @@ void wifi_ini(void)
|
||||
char chargeid[6];
|
||||
uint8_t mac[6];
|
||||
esp_wifi_get_mac(ESP_IF_WIFI_AP, mac);
|
||||
sprintf((char *)chargeid, MDNS_SSID, mac[5]);
|
||||
sprintf((char *)chargeid, MDNS_SSID, 0);
|
||||
|
||||
ESP_ERROR_CHECK(mdns_init());
|
||||
ESP_ERROR_CHECK(mdns_hostname_set(chargeid));
|
||||
@@ -188,7 +188,9 @@ esp_netif_t *wifi_get_ap_netif(void)
|
||||
esp_err_t wifi_set_config(bool enabled, const char *ssid, const char *password)
|
||||
{
|
||||
|
||||
ESP_LOGI(TAG, "Wifi set config");
|
||||
|
||||
ESP_LOGI(TAG, "wifi_set_config(enabled=%d, ssid=\"%s\")", enabled, ssid?:"<nil>");
|
||||
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_netif.h"
|
||||
#include "esp_mac.h"
|
||||
#include "nvs.h"
|
||||
#include "mdns.h"
|
||||
|
||||
#include "wifi.h"
|
||||
|
||||
|
||||
#include "nvs_flash.h"
|
||||
#include <string.h>
|
||||
|
||||
#define WIFI_STORAGE_NAMESPACE "wifi_config"
|
||||
|
||||
|
||||
|
||||
#define TAG "wifi"
|
||||
#define AP_SSID "plx-%02x%02x%02x"
|
||||
#define MDNS_HOSTNAME "plx%02x"
|
||||
|
||||
#define NVS_NAMESPACE "wifi"
|
||||
|
||||
static nvs_handle_t nvs;
|
||||
static esp_netif_t *ap_netif;
|
||||
EventGroupHandle_t wifi_event_group;
|
||||
|
||||
//
|
||||
// Event handler para modo AP
|
||||
//
|
||||
static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
|
||||
{
|
||||
if (event_base == WIFI_EVENT) {
|
||||
switch (event_id) {
|
||||
case WIFI_EVENT_AP_STACONNECTED: {
|
||||
wifi_event_ap_staconnected_t *event = event_data;
|
||||
ESP_LOGI(TAG, "STA " MACSTR " conectou, AID=%d", MAC2STR(event->mac), event->aid);
|
||||
xEventGroupSetBits(wifi_event_group, WIFI_AP_CONNECTED_BIT);
|
||||
break;
|
||||
}
|
||||
case WIFI_EVENT_AP_STADISCONNECTED: {
|
||||
wifi_event_ap_stadisconnected_t *event = event_data;
|
||||
ESP_LOGI(TAG, "STA " MACSTR " desconectou, AID=%d", MAC2STR(event->mac), event->aid);
|
||||
xEventGroupClearBits(wifi_event_group, WIFI_AP_CONNECTED_BIT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Iniciar o AP com SSID baseado no MAC
|
||||
//
|
||||
void wifi_ap_start(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Iniciando AP");
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_stop());
|
||||
|
||||
wifi_config_t ap_config = {
|
||||
.ap = {
|
||||
.ssid = "",
|
||||
.ssid_len = 0,
|
||||
.channel = 1,
|
||||
.password = "",
|
||||
.max_connection = 4,
|
||||
.authmode = WIFI_AUTH_OPEN
|
||||
}
|
||||
};
|
||||
|
||||
uint8_t mac[6];
|
||||
ESP_ERROR_CHECK(esp_read_mac(mac, ESP_MAC_WIFI_SOFTAP));
|
||||
snprintf((char *)ap_config.ap.ssid, sizeof(ap_config.ap.ssid), AP_SSID, mac[3], mac[4], mac[5]);
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &ap_config));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
xEventGroupSetBits(wifi_event_group, WIFI_AP_MODE_BIT);
|
||||
}
|
||||
|
||||
//
|
||||
// Inicializar Wi-Fi em modo AP
|
||||
//
|
||||
void wifi_ini(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Inicializando Wi-Fi (modo AP)");
|
||||
|
||||
ESP_ERROR_CHECK(nvs_open(NVS_NAMESPACE, NVS_READWRITE, &nvs));
|
||||
|
||||
wifi_event_group = xEventGroupCreate();
|
||||
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
/*
|
||||
if (!esp_event_loop_is_running()) {
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
}*/
|
||||
|
||||
ap_netif = esp_netif_create_default_wifi_ap();
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
||||
|
||||
uint8_t mac[6];
|
||||
ESP_ERROR_CHECK(esp_read_mac(mac, ESP_MAC_WIFI_SOFTAP));
|
||||
char hostname[16];
|
||||
snprintf(hostname, sizeof(hostname), MDNS_HOSTNAME, mac[5]);
|
||||
|
||||
ESP_ERROR_CHECK(mdns_init());
|
||||
ESP_ERROR_CHECK(mdns_hostname_set(hostname));
|
||||
ESP_ERROR_CHECK(mdns_instance_name_set("EVSE Controller"));
|
||||
|
||||
wifi_ap_start();
|
||||
}
|
||||
|
||||
esp_netif_t *wifi_get_ap_netif(void)
|
||||
{
|
||||
return ap_netif;
|
||||
}
|
||||
|
||||
esp_err_t wifi_set_config(bool enabled, const char *ssid, const char *password) {
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void wifi_get_ssid(char *value) {
|
||||
// Your implementation here
|
||||
}
|
||||
|
||||
void wifi_get_password(char *value) {
|
||||
// Your implementation here
|
||||
}
|
||||
|
||||
bool wifi_get_enabled(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user