Skip to content

Commit

Permalink
updating wifi connection
Browse files Browse the repository at this point in the history
  • Loading branch information
akdeb committed Feb 2, 2025
1 parent 566b8e2 commit 99a888f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
7 changes: 5 additions & 2 deletions firmware/src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ const char *EAP_PASSWORD = "password";
// const char *password_personal = "password";

// ! WebSocket server details
const char *backend_server = "51.8.202.78";
const uint16_t backend_port = 80;
const char *backend_server = "<IP address of your server>";
const uint16_t backend_port = 8000;

const char *websocket_path = "/live";
const char *auth_token = "<your-STARMOON_API_KEY-here>";
// ! WebSocket local server
// const char *backend_server = "your wifi ip address";
// const uint16_t backend_port = 8000;
Expand Down
31 changes: 29 additions & 2 deletions firmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,31 @@ void websocketSetup(String server_domain, int port, String path)
webSocket.setReconnectInterval(1000);
}

/**
* 1. Very simple Wifi connection (LOCAL)
* With hardcoded Auth Token available on the Settings page running locally
*/
void connectToWiFiAndWebSocketWithPassword()
{
if (!connectToWiFi())
{
Serial.println("Failed to connect to Wi-Fi. Good night!");
enterSleep();
return;
}

// Connect to WebSocket if successfully registered
Serial.println("Connecting to WebSocket server...");
websocketSetup(backend_server, backend_port, websocket_path);
}

/**
* 2. Wifi connection with AP (LOCAL)
* 1. Create a Device in the `devices` table in supabase with a unique `user_code`
* 2. When clicking on AP to connect to wifi, enter email `admin@starmoon.app` and the user_code you created above
* 3. The device MAC address will be registered and the auth token will be stored in the device
* 4. The device will connect to the WebSocket server and start responding
*/
void connectToWifiAndWebSocket()
{
int result = wifiConnect();
Expand Down Expand Up @@ -901,7 +926,8 @@ void connectToWifiAndWebSocket()
void getAuthTokenFromNVS()
{
preferences.begin("auth", false);
authTokenGlobal = preferences.getString("auth_token", "");
// authTokenGlobal = preferences.getString("auth_token", ""); // Wifi connection with AP
authTokenGlobal = auth_token; // Simple Wifi connection
Serial.print("authTokenGlobal: ");
Serial.println(authTokenGlobal);
preferences.end();
Expand Down Expand Up @@ -947,7 +973,8 @@ void setup()
deviceState = STATE_CONNECTING;
}

connectToWifiAndWebSocket();
connectToWiFiAndWebSocketWithPassword(); // Simple Wifi connection
// connectToWifiAndWebSocket(); // Wifi connection with AP

i2s_install_speaker();
i2s_setpin_speaker();
Expand Down

0 comments on commit 99a888f

Please sign in to comment.