Skip to content

Fancy wifi provisioning #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ build_flags =

build_unflags = -Os -std=gnu++11 -std=gnu++17

; If you want to enable OTA Updates, uncomment and set OTA password here and in credentials.h
; If you want to enable OTA Updates, uncomment and set OTA password here and in credentials.cpp
; You can set upload_port to device's ip after it's set up for the first time
; Use the same password in SlimeVR Server to let it OTA Update the device
;upload_protocol = espota
Expand Down
4 changes: 4 additions & 0 deletions src/GlobalVars.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "configuration/Configuration.h"
#include "network/connection.h"
#include "network/manager.h"
#include "network/wifihandler.h"
#include "network/wifiprovisioning.h"
#include "sensors/SensorManager.h"
#include "status/StatusManager.h"

Expand All @@ -42,5 +44,7 @@ extern SlimeVR::Sensors::SensorManager sensorManager;
extern SlimeVR::Network::Manager networkManager;
extern SlimeVR::Network::Connection networkConnection;
extern BatteryMonitor battery;
extern SlimeVR::WiFiNetwork wifiNetwork;
extern SlimeVR::WiFiProvisioning wifiProvisioning;

#endif
28 changes: 28 additions & 0 deletions src/credentials.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* SlimeVR Code is placed under the MIT license
Copyright (c) 2025 Gorbit99 & SlimeVR Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

const char* otaPassword
= "SlimeVR-OTA"; // YOUR OTA PASSWORD HERE, LEAVE EMPTY TO DISABLE OTA UPDATES

const char* provisioningPassword
= "SlimeVR-Provisioning"; // YOUR PROVISIONING PASSWORD HERE, LEAVE EMPTY TO
// DISABLE PROVISIONING
5 changes: 3 additions & 2 deletions src/credentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
// firmware. We don't have any hardware buttons for the user to confirm
// OTA update, so this is the best way we have.
// OTA is allowed only for the first 60 seconds after device startup.
const char* otaPassword
= "SlimeVR-OTA"; // YOUR OTA PASSWORD HERE, LEAVE EMPTY TO DISABLE OTA UPDATES
extern const char* otaPassword;

extern const char* provisioningPassword;

#endif // SLIMEVR_CREDENTIALS_H_
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ SlimeVR::Status::StatusManager statusManager;
SlimeVR::Configuration::Configuration configuration;
SlimeVR::Network::Manager networkManager;
SlimeVR::Network::Connection networkConnection;
SlimeVR::WiFiNetwork wifiNetwork;
SlimeVR::WiFiProvisioning wifiProvisioning;

#if DEBUG_MEASURE_SENSOR_TIME_TAKEN
SlimeVR::Debugging::TimeTakenMeasurer sensorMeasurer{"Sensors"};
Expand Down
17 changes: 17 additions & 0 deletions src/network/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,23 @@ void Connection::update() {
configuration.save();
break;
}

case ReceivePacketType::WiFiProvisioning: {
WiFiProvisioningPacket wifiProvisioningPacket{};
memcpy(
&wifiProvisioningPacket,
m_Packet + 12,
sizeof(WiFiProvisioningPacket)
);

if (wifiProvisioningPacket.start) {
wifiProvisioning.startProvisioning();
} else {
wifiProvisioning.stopProvisioning();
}

break;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/network/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
namespace SlimeVR {
namespace Network {

void Manager::setup() { ::WiFiNetwork::setUp(); }
void Manager::setup() { wifiNetwork.setUp(); }

void Manager::update() {
WiFiNetwork::upkeep();
wifiNetwork.upkeep();

auto wasConnected = m_IsConnected;

m_IsConnected = ::WiFiNetwork::isConnected();
m_IsConnected = wifiNetwork.isConnected();

if (!m_IsConnected) {
return;
Expand Down
5 changes: 5 additions & 0 deletions src/network/packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ enum class ReceivePacketType : uint8_t {
SensorInfo = 15,
FeatureFlags = 22,
SetConfigFlag = 25,
WiFiProvisioning = 27,
};

enum class InspectionPacketType : uint8_t {
Expand Down Expand Up @@ -230,6 +231,10 @@ struct SetConfigFlagPacket {
bool newState{};
};

struct WiFiProvisioningPacket {
bool start;
};

#pragma pack(pop)

#endif // SLIMEVR_PACKETS_H_
Loading