Skip to content

Commit 8c0c1eb

Browse files
Try to recreate AP config if missing "band" or "channel"
1 parent 1447471 commit 8c0c1eb

File tree

1 file changed

+51
-30
lines changed

1 file changed

+51
-30
lines changed

src/NetworkManager.cpp

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@
4646
QDBusObjectPath AP_PATH;
4747
Connection DEFAULT_AP;
4848
QString RASPBERRYPI_TYPE;
49-
#ifdef WOMBAT
50-
#define WIFI_DEVICE "wlan0" // always wlan0 for raspberry pi
51-
#else
52-
#define WIFI_DEVICE "wlo1" // wlo1 for dev machine
53-
#endif
49+
// #ifdef WOMBAT
50+
// #define WIFI_DEVICE "wlan0" // always wlan0 for raspberry pi
51+
// #else
52+
// #define WIFI_DEVICE "wlo1" // wlo1 for dev machine
53+
// #endif
5454

55+
#define WIFI_DEVICE "wlo1" // wlo1 for dev machine
5556

5657
#define AP_NAME m_dev->serial() + "-wombat"
5758
#define AP_SSID (AP_NAME).toUtf8()
@@ -275,8 +276,6 @@ void NetworkManager::changeWifiBands(QString band, int channel)
275276
qDebug() << "Correct connection ssid " << connectionSettings[NM_802_11_WIRELESS_KEY]["ssid"].toString();
276277
QPair<Connection, QDBusObjectPath> correctConnectionPair = getConnection(connectionSettings[NM_802_11_WIRELESS_KEY]["ssid"].toString());
277278

278-
279-
280279
QDBusPendingReply<QDBusObjectPath> reply = m_nm->ActivateConnection(correctConnectionPair.second, devicePath, QDBusObjectPath("/"));
281280
reply.waitForFinished();
282281
getReply(reply);
@@ -325,6 +324,29 @@ bool NetworkManager::enableAP()
325324
qDebug() << "AP Path: " << apPath.path();
326325
qDebug() << "AP Path Connection already exists";
327326
qDebug() << "AP Strength: " << active().strength();
327+
OrgFreedesktopNetworkManagerSettingsConnectionInterface connection(NM_SERVICE, apPath.path(), QDBusConnection::systemBus());
328+
329+
Connection settings = connection.GetSettings().value();
330+
331+
bool containsBand = settings.contains("band");
332+
bool containsChannel = settings.contains("channel");
333+
334+
// Check if the settings contain "band" and "channel"
335+
if (!containsBand || !containsChannel)
336+
{
337+
qDebug() << "Missing 'band' or 'channel' in AP settings. Recreating AP configuration.";
338+
339+
//Delete previous AP Configuration
340+
qDebug() << "Deleting the previous AP connection: " << apPath.path();
341+
connection.Delete();
342+
// Recreate AP configuration
343+
createAPConfig();
344+
sleep(3);
345+
apPath = getAPSettingsObjectPath();
346+
qDebug() << "New apPath" << apPath.path();
347+
m_nm->ActivateConnection(apPath, devicePath, QDBusObjectPath("/"));
348+
return true;
349+
}
328350

329351
if (NetworkManager::ref().isActiveConnectionOn() == true)
330352
{
@@ -684,30 +706,29 @@ NetworkManager::NetworkManager()
684706

685707
void NetworkManager::getRaspberryPiType()
686708
{
687-
QStringList arguments;
688-
arguments << "-c" << "cat /proc/cpuinfo | grep Revision | awk '{print $3}'";
689-
690-
QProcess *myProcess = new QProcess(this);
691-
myProcess->start("/bin/sh", arguments); // Use /bin/sh or /bin/bash to interpret the command
692-
myProcess->waitForFinished();
693-
QByteArray output = myProcess->readAllStandardOutput();
694-
695-
qDebug() << "Revision code output: " << output;
696-
if (output.trimmed() == "a020d3" || output.trimmed() == "a020d4")
697-
{
698-
RASPBERRYPI_TYPE = "3B+";
699-
}
700-
else if (output.trimmed() == "a02082" || output.trimmed() == "a22082" || output.trimmed() == "a32082" || output.trimmed() == "a52082" || output.trimmed() == "a22083")
701-
{
702-
RASPBERRYPI_TYPE = "3B";
703-
}
704-
else
705-
{
706-
RASPBERRYPI_TYPE = "Unknown";
707-
}
708-
709-
qDebug() << "RASPBERRYPI_TYPE: " << RASPBERRYPI_TYPE;
709+
QStringList arguments;
710+
arguments << "-c" << "cat /proc/cpuinfo | grep Revision | awk '{print $3}'";
711+
712+
QProcess *myProcess = new QProcess(this);
713+
myProcess->start("/bin/sh", arguments); // Use /bin/sh or /bin/bash to interpret the command
714+
myProcess->waitForFinished();
715+
QByteArray output = myProcess->readAllStandardOutput();
716+
717+
qDebug() << "Revision code output: " << output;
718+
if (output.trimmed() == "a020d3" || output.trimmed() == "a020d4")
719+
{
720+
RASPBERRYPI_TYPE = "3B+";
721+
}
722+
else if (output.trimmed() == "a02082" || output.trimmed() == "a22082" || output.trimmed() == "a32082" || output.trimmed() == "a52082" || output.trimmed() == "a22083")
723+
{
724+
RASPBERRYPI_TYPE = "3B";
725+
}
726+
else
727+
{
728+
RASPBERRYPI_TYPE = "Unknown";
729+
}
710730

731+
qDebug() << "RASPBERRYPI_TYPE: " << RASPBERRYPI_TYPE;
711732
}
712733

713734
void NetworkManager::nmAccessPointAdded(const QDBusObjectPath &accessPoint)

0 commit comments

Comments
 (0)