added source code
parent
c4877f76e3
commit
a1315e1e50
|
@ -0,0 +1,2 @@
|
|||
idf_component_register(SRCS "hello_world_main.c"
|
||||
INCLUDE_DIRS "")
|
|
@ -0,0 +1,5 @@
|
|||
#
|
||||
# "main" pseudo-component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
#ifndef _server_h
|
||||
#define _server_h
|
||||
|
||||
#include "esp_wifi_types.h"
|
||||
#include "shared.h"
|
||||
#include "esp_event.h"
|
||||
|
||||
static
|
||||
void on_station_connects(wifi_event_ap_staconnected_t* event) {
|
||||
LOGLN("Station %d connected", event->aid);
|
||||
}
|
||||
|
||||
static
|
||||
void on_station_disconnects(wifi_event_ap_stadisconnected_t* event) {
|
||||
LOGLN("Station %d disconnected", event->aid);
|
||||
}
|
||||
|
||||
static
|
||||
void on_wifi_event(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data) {
|
||||
switch(event_id) {
|
||||
case WIFI_EVENT_AP_STACONNECTED:
|
||||
on_station_connects(event_data);
|
||||
break;
|
||||
case WIFI_EVENT_AP_STADISCONNECTED:
|
||||
on_station_disconnects(event_data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline
|
||||
void wifi_init() {
|
||||
LOGLN("Configuring WIFI");
|
||||
// init tcp/ip stack
|
||||
tcpip_adapter_init();
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
// initialize wifi
|
||||
wifi_init_config_t wifi_startup = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&wifi_startup));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &on_wifi_event, NULL));
|
||||
LOGLN("WiFi initialized");
|
||||
}
|
||||
|
||||
static inline
|
||||
void softap_init() {
|
||||
LOGLN("Starting wireless Access Point");
|
||||
// set mode to wifi
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
|
||||
|
||||
// configure wifi hardware to serve as a wifi access point
|
||||
wifi_config_t accesspoint_startup_config = {
|
||||
.ap = {
|
||||
.ssid = SSID,
|
||||
.ssid_len = strlen(SSID),
|
||||
.password = PASSW,
|
||||
.max_connection=32,
|
||||
.authmode = WIFI_AUTH_WPA_WPA2_PSK
|
||||
}
|
||||
};
|
||||
|
||||
// configure with created startup config
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &accesspoint_startup_config));
|
||||
// start wifi access point
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
LOGLN("Opened AP SSID: \"%s\" PW: \"%s\"", SSID, PASSW);
|
||||
}
|
||||
|
||||
#endif // !_server_h
|
|
@ -0,0 +1,18 @@
|
|||
#include "shared.h"
|
||||
#include "network.h"
|
||||
#include "rom/ets_sys.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <esp_http_server.h>
|
||||
|
||||
void app_main() {
|
||||
LOGLN("starting {");
|
||||
|
||||
wifi_init();
|
||||
softap_init();
|
||||
|
||||
LOGLN("}");
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef _server_h
|
||||
#define _server_h
|
||||
|
||||
void server_init() {
|
||||
}
|
||||
|
||||
#endif // !_server_h
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef _shared_h
|
||||
#define _shared_h
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <esp_wifi.h>
|
||||
#include "esp_system.h"
|
||||
|
||||
#define SSID "ESP8266"
|
||||
#define PASSW "XR-Lab2023"
|
||||
#define WIFI_CONFIG
|
||||
|
||||
static const char* APP_TAG="CINEKID_LEDS";
|
||||
|
||||
#define LOGLN(...) do {\
|
||||
printf("%s | ", APP_TAG);\
|
||||
printf(__VA_ARGS__);\
|
||||
printf("\n");\
|
||||
} while(0)
|
||||
|
||||
#endif // !_shared_h
|
Loading…
Reference in New Issue