development

This commit is contained in:
Miro Zmrzli 2024-05-15 12:35:23 -07:00
parent 3e700ccd04
commit 5a22f4b8fd
4 changed files with 19 additions and 37 deletions

View File

@ -1,2 +0,0 @@
.vscode
.DS_Store

View File

@ -0,0 +1,5 @@
This came from
https://github.com/Depau/ESPAsyncWebServer/tree/wi-se-patches
contains multiple bugfixes.

View File

@ -1,10 +1,11 @@
<!doctype html>
<html>
<!-- © MiroZ 2024 -->
<script type = "text/javascript">
var ws = null;
function OpenSocket()
{
ws = new WebSocket('ws://4.4.4.4/provision');
ws = new WebSocket('ws://172.68.4.1/provision');
ws.onopen = function()
{
console.info('onopen');
@ -354,7 +355,7 @@ input {
</p>
<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 id="msg_error">
<h3>Beat-a-meat was not able to connect to selected WiFi. Please check the spelling and password.</h3>

View File

@ -2,15 +2,14 @@
* ProvisionSoftAP.cpp
*
* Created on: Apr 17, 2019
* Modified: 2024
* Author: miro
*/
#include <DNSServer.h>
#include "WiFi.h"
#include "Arduino.h"
// #include "ArduinoJson.h"
#include <list>
#include <iterator>
// #include "Storage.h"
#include "Settings.h"
#include <functional>
#include "freertos/event_groups.h"
@ -21,12 +20,16 @@ static const char *TAG = "soft_ap";
using namespace std::placeholders;
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 logo_png_start[] asm("_binary_logo_png_start");
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)
{
@ -48,7 +51,6 @@ void ProvisionSoftAP::wifiEvent(arduino_event_id_t event, arduino_event_info_t i
break;
default:
break;
}
}
@ -77,7 +79,7 @@ void ProvisionSoftAP::websocketEvent(AsyncWebSocket * server, AsyncWebSocketClie
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);
request->send(response);
}
@ -103,38 +105,17 @@ void ProvisionSoftAP::init(const char * ssid, const char * password)
// start AP
/* Soft AP network parameters */
IPAddress apIP(4, 4, 4, 4);
IPAddress netMsk(255, 255, 255, 0);
IPAddress firstIp(4, 4, 4, 100);
IPAddress apIP(sta_ip);
IPAddress netMsk(net_mask);
IPAddress firstIp(first_ip);
wifiEventId = WiFi.onEvent(std::bind(&ProvisionSoftAP::wifiEvent, this, _1, _2));
WiFi.mode(WIFI_MODE_AP);
WiFi.softAPConfig(apIP, apIP, netMsk);
WiFi.softAPConfig(apIP, apIP, netMsk, firstIp);
WiFi.softAP(ssid, password);
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
m_dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
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->onNotFound(std::bind(&ProvisionSoftAP::handlePortal, this, _1));
m_webServer->begin();
while (true)
{
vTaskDelay(1);