development
This commit is contained in:
parent
3e700ccd04
commit
5a22f4b8fd
2
components/AsyncWebServer/.gitignore
vendored
2
components/AsyncWebServer/.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
.vscode
|
|
||||||
.DS_Store
|
|
||||||
5
components/AsyncWebServer/readme.txt
Executable file
5
components/AsyncWebServer/readme.txt
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
This came from
|
||||||
|
|
||||||
|
https://github.com/Depau/ESPAsyncWebServer/tree/wi-se-patches
|
||||||
|
|
||||||
|
contains multiple bugfixes.
|
||||||
@ -1,10 +1,11 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
|
<!-- © MiroZ 2024 -->
|
||||||
<script type = "text/javascript">
|
<script type = "text/javascript">
|
||||||
var ws = null;
|
var ws = null;
|
||||||
function OpenSocket()
|
function OpenSocket()
|
||||||
{
|
{
|
||||||
ws = new WebSocket('ws://4.4.4.4/provision');
|
ws = new WebSocket('ws://172.68.4.1/provision');
|
||||||
ws.onopen = function()
|
ws.onopen = function()
|
||||||
{
|
{
|
||||||
console.info('onopen');
|
console.info('onopen');
|
||||||
@ -354,7 +355,7 @@ input {
|
|||||||
|
|
||||||
</p>
|
</p>
|
||||||
<div id="msg_ok">
|
<div id="msg_ok">
|
||||||
<h3>Beat-a-meat has ben succesfully configured. It is now ready for normal use.</h3>
|
<h3>Beat-a-meat has ben successfully configured. It is now ready for normal use.</h3>
|
||||||
</div>
|
</div>
|
||||||
<div id="msg_error">
|
<div id="msg_error">
|
||||||
<h3>Beat-a-meat was not able to connect to selected WiFi. Please check the spelling and password.</h3>
|
<h3>Beat-a-meat was not able to connect to selected WiFi. Please check the spelling and password.</h3>
|
||||||
|
|||||||
@ -2,15 +2,14 @@
|
|||||||
* ProvisionSoftAP.cpp
|
* ProvisionSoftAP.cpp
|
||||||
*
|
*
|
||||||
* Created on: Apr 17, 2019
|
* Created on: Apr 17, 2019
|
||||||
|
* Modified: 2024
|
||||||
* Author: miro
|
* Author: miro
|
||||||
*/
|
*/
|
||||||
#include <DNSServer.h>
|
#include <DNSServer.h>
|
||||||
#include "WiFi.h"
|
#include "WiFi.h"
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
// #include "ArduinoJson.h"
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
// #include "Storage.h"
|
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "freertos/event_groups.h"
|
#include "freertos/event_groups.h"
|
||||||
@ -21,12 +20,16 @@ static const char *TAG = "soft_ap";
|
|||||||
|
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
|
||||||
|
|
||||||
extern const uint8_t provision_html_start[] asm("_binary_provision_html_start");
|
extern const uint8_t provision_html_start[] asm("_binary_provision_html_start");
|
||||||
extern const uint8_t provision_html_end[] asm("_binary_provision_html_end");
|
extern const uint8_t provision_html_end[] asm("_binary_provision_html_end");
|
||||||
extern const uint8_t logo_png_start[] asm("_binary_logo_png_start");
|
extern const uint8_t logo_png_start[] asm("_binary_logo_png_start");
|
||||||
extern const uint8_t logo_png_end[] asm("_binary_logo_png_end");
|
extern const uint8_t logo_png_end[] asm("_binary_logo_png_end");
|
||||||
|
|
||||||
|
const uint8_t sta_ip[] = {172, 68, 4, 1};
|
||||||
|
const uint8_t net_mask[] = {255, 255, 255, 0};
|
||||||
|
const uint8_t first_ip[] = {172, 68, 4, 10};
|
||||||
|
const uint8_t last_ip[] = {172, 68, 4, 100};
|
||||||
|
|
||||||
|
|
||||||
ProvisionSoftAP::ProvisionSoftAP(int port)
|
ProvisionSoftAP::ProvisionSoftAP(int port)
|
||||||
{
|
{
|
||||||
@ -48,7 +51,6 @@ void ProvisionSoftAP::wifiEvent(arduino_event_id_t event, arduino_event_info_t i
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,7 +79,7 @@ void ProvisionSoftAP::websocketEvent(AsyncWebSocket * server, AsyncWebSocketClie
|
|||||||
|
|
||||||
void ProvisionSoftAP::handlePortal(AsyncWebServerRequest* request)
|
void ProvisionSoftAP::handlePortal(AsyncWebServerRequest* request)
|
||||||
{
|
{
|
||||||
ESP_LOGI("", "handle root %s", request->url().c_str());
|
ESP_LOGI(TAG, "Serving html, requested url: %s", request->url().c_str());
|
||||||
AsyncWebServerResponse * response = request->beginResponse_P(200, "text/html", (PGM_P)provision_html_start);
|
AsyncWebServerResponse * response = request->beginResponse_P(200, "text/html", (PGM_P)provision_html_start);
|
||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
@ -103,38 +105,17 @@ void ProvisionSoftAP::init(const char * ssid, const char * password)
|
|||||||
// start AP
|
// start AP
|
||||||
|
|
||||||
/* Soft AP network parameters */
|
/* Soft AP network parameters */
|
||||||
IPAddress apIP(4, 4, 4, 4);
|
IPAddress apIP(sta_ip);
|
||||||
IPAddress netMsk(255, 255, 255, 0);
|
IPAddress netMsk(net_mask);
|
||||||
IPAddress firstIp(4, 4, 4, 100);
|
IPAddress firstIp(first_ip);
|
||||||
wifiEventId = WiFi.onEvent(std::bind(&ProvisionSoftAP::wifiEvent, this, _1, _2));
|
wifiEventId = WiFi.onEvent(std::bind(&ProvisionSoftAP::wifiEvent, this, _1, _2));
|
||||||
|
|
||||||
WiFi.mode(WIFI_MODE_AP);
|
WiFi.mode(WIFI_MODE_AP);
|
||||||
WiFi.softAPConfig(apIP, apIP, netMsk);
|
WiFi.softAPConfig(apIP, apIP, netMsk, firstIp);
|
||||||
WiFi.softAP(ssid, password);
|
WiFi.softAP(ssid, password);
|
||||||
|
|
||||||
delay(200);
|
delay(200);
|
||||||
|
|
||||||
// set dhcp address range
|
|
||||||
tcpip_adapter_ip_info_t info = { };
|
|
||||||
IP4_ADDR(&info.ip, 4, 4, 4, 4);
|
|
||||||
IP4_ADDR(&info.gw, 4, 4, 4, 4);
|
|
||||||
IP4_ADDR(&info.netmask, 255, 255, 255, 0);
|
|
||||||
tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP);
|
|
||||||
|
|
||||||
if (tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &info) == ESP_OK)
|
|
||||||
{
|
|
||||||
dhcps_lease_t lease = { };
|
|
||||||
lease.enable = true;
|
|
||||||
|
|
||||||
IP4_ADDR(&lease.start_ip, 4, 4, 4, 10);
|
|
||||||
IP4_ADDR(&lease.end_ip, 4, 4, 4, 100);
|
|
||||||
|
|
||||||
tcpip_adapter_dhcps_option((tcpip_adapter_dhcp_option_mode_t) TCPIP_ADAPTER_OP_SET,
|
|
||||||
(tcpip_adapter_dhcp_option_id_t) TCPIP_ADAPTER_REQUESTED_IP_ADDRESS, (void*) &lease, sizeof(dhcps_lease_t));
|
|
||||||
|
|
||||||
tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP);
|
|
||||||
}
|
|
||||||
|
|
||||||
// setup the dns
|
// setup the dns
|
||||||
m_dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
|
m_dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
|
||||||
m_dnsServer.setTTL(30);
|
m_dnsServer.setTTL(30);
|
||||||
@ -150,11 +131,8 @@ void ProvisionSoftAP::init(const char * ssid, const char * password)
|
|||||||
m_webServer->on("/logo.png", std::bind(&ProvisionSoftAP::handleLogo, this, _1));
|
m_webServer->on("/logo.png", std::bind(&ProvisionSoftAP::handleLogo, this, _1));
|
||||||
m_webServer->onNotFound(std::bind(&ProvisionSoftAP::handlePortal, this, _1));
|
m_webServer->onNotFound(std::bind(&ProvisionSoftAP::handlePortal, this, _1));
|
||||||
|
|
||||||
|
|
||||||
m_webServer->begin();
|
m_webServer->begin();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
vTaskDelay(1);
|
vTaskDelay(1);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user