mqtt client id is now a mac address, fixing issue of not being able to have more than one tag connected at the time. Logo and html is updated. Tag will now correctly go into and stay in provision for 2 minutes before reset if it wasn't able to connect to wifi
This commit is contained in:
parent
aa93a71fa1
commit
ee77bb4e78
BIN
html/logo.png
BIN
html/logo.png
Binary file not shown.
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 26 KiB |
@ -389,15 +389,15 @@ input {
|
|||||||
<input type="button" onClick="onButton1()" name="button3" id="button1" value="Button1">
|
<input type="button" onClick="onButton1()" name="button3" id="button1" value="Button1">
|
||||||
<input type="button" onClick="onButton2()" name="button4" id="button2" value="Button2">
|
<input type="button" onClick="onButton2()" name="button4" id="button2" value="Button2">
|
||||||
</div>
|
</div>
|
||||||
<h2>Timmah's special WiFi configuration and stuff</h2>
|
<h2>Welcome to WellHub Wifi intialization</h2>
|
||||||
<p><img src="logo.png" alt=""/><br>
|
<p><img src="logo.png" alt=""/><br>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
<div id="msg_ok">
|
<div id="msg_ok">
|
||||||
<h3>Timmah has ben successfully configured and it is ready for normal use.<br>You can now close this window.</h3>
|
<h3>WellHub has ben successfully configured and it is ready for normal use.<br>You can now close this window.</h3>
|
||||||
</div>
|
</div>
|
||||||
<div id="msg_error">
|
<div id="msg_error">
|
||||||
<h3>Timmah was not able to connect to selected WiFi. Please check the spelling and password.</h3>
|
<h3>WellHub was not able to connect to selected WiFi. Please check the spelling and password.</h3>
|
||||||
</div>
|
</div>
|
||||||
<div id="wait_scan">
|
<div id="wait_scan">
|
||||||
<h3>Please wait, scanning local WiFi...</h3>
|
<h3>Please wait, scanning local WiFi...</h3>
|
||||||
|
|||||||
@ -77,6 +77,8 @@ void App::init()
|
|||||||
|
|
||||||
needs_provision = false;
|
needs_provision = false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
m_wifi->pause(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(needs_provision)
|
if(needs_provision)
|
||||||
|
|||||||
@ -46,18 +46,21 @@ void MqttService::task()
|
|||||||
uint8_t len = 0;
|
uint8_t len = 0;
|
||||||
if(m_app_if.getBuffer()->getBlock(buffer, len))
|
if(m_app_if.getBuffer()->getBlock(buffer, len))
|
||||||
{
|
{
|
||||||
|
char top[64];
|
||||||
|
uint8_t mac[6];
|
||||||
|
WiFi.macAddress(mac);
|
||||||
|
|
||||||
while (!m_mqtt_client->connected())
|
while (!m_mqtt_client->connected())
|
||||||
{
|
{
|
||||||
|
sprintf(top, "wh_%02X%02X%02X%02X%02X%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
|
|
||||||
ESP_LOGI(TAG, "connecting to mqtt broker, dev id '%s'...", SETTINGS.mqtt.device_id);
|
ESP_LOGI(TAG, "connecting to mqtt broker, dev id '%s'...", SETTINGS.mqtt.device_id);
|
||||||
if (m_mqtt_client->connect("Esp32 client", SETTINGS.mqtt.device_id, NULL))
|
if (m_mqtt_client->connect(top, SETTINGS.mqtt.device_id, NULL))
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "connected");
|
ESP_LOGI(TAG, "connected");
|
||||||
uint8_t mac[6];
|
|
||||||
WiFi.macAddress(mac);
|
|
||||||
|
|
||||||
char top[64];
|
|
||||||
|
|
||||||
sprintf(top, "/%02X%02X%02X%02X%02X%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
sprintf(top, "/%02X%02X%02X%02X%02X%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Subscribing to %s", top);
|
ESP_LOGI(TAG, "Subscribing to %s", top);
|
||||||
if(m_mqtt_client->subscribe(top))
|
if(m_mqtt_client->subscribe(top))
|
||||||
ESP_LOGI(TAG, "subscribed");
|
ESP_LOGI(TAG, "subscribed");
|
||||||
|
|||||||
@ -42,10 +42,12 @@ void ProvisionSoftAP::wifiEvent(arduino_event_id_t event, arduino_event_info_t i
|
|||||||
switch (event)
|
switch (event)
|
||||||
{
|
{
|
||||||
case ARDUINO_EVENT_WIFI_AP_STACONNECTED:
|
case ARDUINO_EVENT_WIFI_AP_STACONNECTED:
|
||||||
|
esp_timer_stop(m_timer);
|
||||||
ESP_LOGI(TAG, "station " MACSTR " joined, AID=%d", MAC2STR(info.wifi_ap_staconnected.mac), info.wifi_ap_staconnected.aid);
|
ESP_LOGI(TAG, "station " MACSTR " joined, AID=%d", MAC2STR(info.wifi_ap_staconnected.mac), info.wifi_ap_staconnected.aid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARDUINO_EVENT_WIFI_AP_STADISCONNECTED:
|
case ARDUINO_EVENT_WIFI_AP_STADISCONNECTED:
|
||||||
|
ESP_ERROR_CHECK(esp_timer_start_periodic(m_timer, INACTIVE_TIMER));
|
||||||
ESP_LOGI(TAG, "station " MACSTR " left", MAC2STR(info.wifi_ap_stadisconnected.mac));
|
ESP_LOGI(TAG, "station " MACSTR " left", MAC2STR(info.wifi_ap_stadisconnected.mac));
|
||||||
m_webSocket->closeAll();
|
m_webSocket->closeAll();
|
||||||
break;
|
break;
|
||||||
@ -175,12 +177,27 @@ void ProvisionSoftAP::start(const char * ssid, const char * password)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProvisionSoftAP::timerCallback(void* arg)
|
||||||
|
{
|
||||||
|
esp_restart();
|
||||||
|
}
|
||||||
|
|
||||||
void ProvisionSoftAP::start()
|
void ProvisionSoftAP::start()
|
||||||
{
|
{
|
||||||
uint8_t mac[6];
|
uint8_t mac[6];
|
||||||
WiFi.macAddress(mac);
|
WiFi.macAddress(mac);
|
||||||
char ssid[33];
|
char ssid[33];
|
||||||
|
|
||||||
|
esp_timer_create_args_t timer;
|
||||||
|
timer.arg = this;
|
||||||
|
timer.callback = &timerCallback;
|
||||||
|
timer.dispatch_method = ESP_TIMER_TASK;
|
||||||
|
timer.skip_unhandled_events = true;
|
||||||
|
timer.name = "provision reset timer";
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_timer_create(&timer, &m_timer));
|
||||||
|
ESP_ERROR_CHECK(esp_timer_start_periodic(m_timer, INACTIVE_TIMER)); // 5 min
|
||||||
|
|
||||||
sprintf(ssid, "Wellhub-%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
sprintf(ssid, "Wellhub-%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
start(ssid, "12345678");
|
start(ssid, "12345678");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,9 +11,12 @@
|
|||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <DNSServer.h>
|
#include <DNSServer.h>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <esp_timer.h>
|
||||||
#include "ReaderWriter.h"
|
#include "ReaderWriter.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
|
#define INACTIVE_TIMER (2*60*1000*1000)
|
||||||
|
|
||||||
class ProvisionSoftAP
|
class ProvisionSoftAP
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -26,6 +29,9 @@ private:
|
|||||||
|
|
||||||
ReaderWriter * m_rwriter = nullptr;
|
ReaderWriter * m_rwriter = nullptr;
|
||||||
|
|
||||||
|
esp_timer_handle_t m_timer;
|
||||||
|
static void timerCallback(void* arg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char m_ssid[32] = {0};
|
char m_ssid[32] = {0};
|
||||||
char m_pwd[32] = {0};
|
char m_pwd[32] = {0};
|
||||||
|
|||||||
@ -64,11 +64,23 @@ void Wifi::task()
|
|||||||
{
|
{
|
||||||
m_wifi_status = WIFI_STATUS::PENDING;
|
m_wifi_status = WIFI_STATUS::PENDING;
|
||||||
m_wifi_status = startConnecting();
|
m_wifi_status = startConnecting();
|
||||||
|
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
while(m_pause)
|
||||||
|
{
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
delay(15000);
|
delay(15000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Wifi::pause(bool pause)
|
||||||
|
{
|
||||||
|
m_pause = pause;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Connect to provisioned wifi
|
/// @brief Connect to provisioned wifi
|
||||||
/// @param index index of wifi in settings
|
/// @param index index of wifi in settings
|
||||||
/// @return WIFI_STATUS::CONNECTED/NOT_CONENCTED connected
|
/// @return WIFI_STATUS::CONNECTED/NOT_CONENCTED connected
|
||||||
|
|||||||
@ -36,6 +36,7 @@ protected:
|
|||||||
WIFI_STATUS startConnecting();
|
WIFI_STATUS startConnecting();
|
||||||
WIFI_STATUS connectTo(int index);
|
WIFI_STATUS connectTo(int index);
|
||||||
int scan();
|
int scan();
|
||||||
|
bool m_pause = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Wifi();
|
Wifi();
|
||||||
@ -45,6 +46,8 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
int start();
|
int start();
|
||||||
|
void pause(bool pause);
|
||||||
|
|
||||||
WIFI_STATUS status() { return m_wifi_status; }
|
WIFI_STATUS status() { return m_wifi_status; }
|
||||||
WIFI_STATUS waitForConnection();
|
WIFI_STATUS waitForConnection();
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user