diff --git a/code/arduino/Movement-sensor-code/Connectivity.cpp b/code/arduino/Movement-sensor-code/Connectivity.cpp index 6e96ca3..e56767e 100644 --- a/code/arduino/Movement-sensor-code/Connectivity.cpp +++ b/code/arduino/Movement-sensor-code/Connectivity.cpp @@ -8,23 +8,49 @@ void Connectivity::connectWiFi(char* ssid, char* pass){ } } -void Connectivity::websocketSetup(char* ip, uint16_t port, char* adress){ - //ws server address, port and URL - webSocket.begin(ip , port, adress); - // try every 500 again if connection has failed - webSocket.setReconnectInterval(500); -} +// void Connectivity::websocketSetup(char* ip, uint16_t port, char* adress){ +// //ws server address, port and URL +// webSocket.begin(ip , port, adress); +// // try every 500 again if connection has failed +// webSocket.setReconnectInterval(500); +// } -void Connectivity::sendData(float roll, float pitch, float yaw){ - String message = "{\"Sensor\": 1, \"roll\":\"" + String(roll) + "\",\"pitch\":\"" + String(pitch) + "\",\"yaw\":\"" + String(yaw) + "\"}"; - webSocket.sendTXT(message); +// void Connectivity::sendData(float roll, float pitch, float yaw){ +// String message = "{\"Sensor\": 1, \"roll\":\"" + String(roll) + "\",\"pitch\":\"" + String(pitch) + "\",\"yaw\":\"" + String(yaw) + "\"}"; +// webSocket.sendTXT(message); +// } + +const char* getServerURL = "http://145.109.171.85:42069/get-ip"; +String ipAddress = ""; + +String Connectivity::fetchIPAddress() { + if (WiFi.status() == WL_CONNECTED) { + HTTPClient http; + WiFiClient client; + http.begin(client, getServerURL); + + int httpCode = http.GET(); + if (httpCode > 0) { + if (httpCode == HTTP_CODE_OK) { + ipAddress = http.getString(); + } + } else { + Serial.printf("GET request failed, error: %s\n", http.errorToString(httpCode).c_str()); + } + + http.end(); + } else { + Serial.println("WiFi not connected"); + } + return ipAddress; // Add this return statement } /** Send a POST request to a server with provided data */ int Connectivity::httpPost(const char *serverAddress, const char *serverSubPath, const unsigned short serverPort, const char *data, const size_t dataLength, const char *contentType) { - if ( wifi_client.connect(serverAddress, serverPort)) { + WiFiClient wifi_client; // Ensure WiFiClient is declared and initialized + if (wifi_client.connect(serverAddress, serverPort)) { wifi_client.printf("POST %s HTTP/1.1\r\n", serverSubPath); wifi_client.printf("Content-Type: %s\r\n", contentType); wifi_client.printf("Content-Length: %d\r\n", dataLength); @@ -35,4 +61,4 @@ int Connectivity::httpPost(const char *serverAddress, const char *serverSubPath, } return 1; -} \ No newline at end of file +} diff --git a/code/arduino/Movement-sensor-code/Connectivity.h b/code/arduino/Movement-sensor-code/Connectivity.h index 90742aa..6de0109 100644 --- a/code/arduino/Movement-sensor-code/Connectivity.h +++ b/code/arduino/Movement-sensor-code/Connectivity.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -18,12 +19,12 @@ public: void websocketSetup(char* ip, uint16_t port, char* adress); void sendData(float roll, float pitch, float yaw); int httpPost(const char *serverAddress, const char *serverSubPath, const unsigned short serverPort, const char *data, const size_t dataLength, const char *contentType); - + String fetchIPAddress(); private: ESP8266WiFiMulti wifi; WiFiClient wifi_client; - WebSocketsClient webSocket; + // WebSocketsClient webSocket; }; diff --git a/code/arduino/Movement-sensor-code/Movement-sensor-code.ino b/code/arduino/Movement-sensor-code/Movement-sensor-code.ino index 15c5a57..061f12d 100644 --- a/code/arduino/Movement-sensor-code/Movement-sensor-code.ino +++ b/code/arduino/Movement-sensor-code/Movement-sensor-code.ino @@ -4,6 +4,7 @@ void setup() { //connect to internet and start sensor connectivity.connectWiFi(ssid, pass); sensorManager.sensorSetup(); + Serial.begin(9600); } unsigned long lastTime = 0; // will store the last time the code was run @@ -12,7 +13,6 @@ void loop() { SensorManager::eulerAngles eulerRotation = sensorManager.getEulerAngles(); // SensorManager::acceleration rotationAcceleration = sensorManager.getAcelleration(); - struct acceleration { float x = 9; float y = 9; @@ -34,7 +34,7 @@ struct acceleration { accelData.z, "data"); // %d = int, %f = floatation, %s = string - connectivity.httpPost(IP_ADDRESS, "/", 3445, buffer, strlen(buffer), "application/json"); + connectivity.httpPost(connectivity.fetchIPAddress(), "/", 3445, buffer, strlen(buffer), "application/json"); lastTime = currentTime; } } diff --git a/code/arduino/bluetoothEsp/bluetoothEsp.ino b/code/arduino/bluetoothEsp/bluetoothEsp.ino deleted file mode 100644 index 0e0eaaf..0000000 --- a/code/arduino/bluetoothEsp/bluetoothEsp.ino +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include - -// Define the service UUID -#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" - -// Define the characteristic UUID -#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" - -void setup() { - // Create a BLE server - BLEServer *pServer = BLEDevice::createServer(); - - // Create a BLE service - BLEService *pService = pServer->createService(SERVICE_UUID); - - // Create a BLE characteristic - BLECharacteristic *pCharacteristic = pService->createCharacteristic( - CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ); - - // Set the characteristic value - pCharacteristic->setValue("Hello, Bluetooth!"); - - // Start the service - pService->start(); - - // Start advertising the service - pServer->getAdvertising()->start(); -} - -void loop() { - // Nothing to do here -} \ No newline at end of file diff --git a/code/server/test/config.js b/code/server/test/config.js new file mode 100644 index 0000000..87c69b0 --- /dev/null +++ b/code/server/test/config.js @@ -0,0 +1,8 @@ +// config.js +module.exports = { + host: '127.0.0.1', + user: 'fitbot', + password: 'fitbot123', + database: 'fitbot', + port: 3306, // Default MariaDB port + }; diff --git a/code/server/test/testConnection.js b/code/server/test/testConnection.js new file mode 100644 index 0000000..4eb953a --- /dev/null +++ b/code/server/test/testConnection.js @@ -0,0 +1,35 @@ +const express = require('express'); +const mariadb = require('mariadb'); +const config = require('./config'); + +const app = express(); +const port = 443; // Use port 443 + +const pool = mariadb.createPool({ + host: config.host, + user: config.user, + password: config.password, + database: config.database, + connectionLimit: 5, + acquireTimeout: 30000, // Increase timeout to 30 seconds +}); + +app.get('/', async (req, res) => { + let conn; + try { + conn = await pool.getConnection(); + console.log("Connected to MariaDB!"); + const rows = await conn.query("SELECT * FROM Exercise ORDER BY RAND() LIMIT 1"); + console.log(rows); // [{val: 1}] + res.json(rows); // Send the result as JSON response + } catch (err) { + console.error("Unable to connect to MariaDB:", err); + res.status(500).send("Unable to connect to MariaDB"); + } finally { + if (conn) conn.release(); // Release the connection back to the pool + } +}); + +app.listen(port, '145.92.8.132', () => { + console.log(`Server is listening on http://145.92.8.132:${port}`); +}); diff --git a/code/src/Fitbot/.idea/misc.xml b/code/src/Fitbot/.idea/misc.xml index 0389b70..a6192e8 100644 --- a/code/src/Fitbot/.idea/misc.xml +++ b/code/src/Fitbot/.idea/misc.xml @@ -21,6 +21,8 @@ + + diff --git a/code/src/Fitbot/app/src/main/AndroidManifest.xml b/code/src/Fitbot/app/src/main/AndroidManifest.xml index c28ce66..32bdaaf 100644 --- a/code/src/Fitbot/app/src/main/AndroidManifest.xml +++ b/code/src/Fitbot/app/src/main/AndroidManifest.xml @@ -22,9 +22,9 @@ + + + + \ No newline at end of file diff --git a/code/src/Fitbot/app/src/main/res/drawable/fitbot_launcher_background.xml b/code/src/Fitbot/app/src/main/res/drawable/fitbot_launcher_background.xml new file mode 100644 index 0000000..ca3826a --- /dev/null +++ b/code/src/Fitbot/app/src/main/res/drawable/fitbot_launcher_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/code/src/Fitbot/app/src/main/res/drawable/ic_baseline_skip_next_48.xml b/code/src/Fitbot/app/src/main/res/drawable/ic_baseline_skip_next_48.xml new file mode 100644 index 0000000..400f0a5 --- /dev/null +++ b/code/src/Fitbot/app/src/main/res/drawable/ic_baseline_skip_next_48.xml @@ -0,0 +1,5 @@ + + + diff --git a/code/src/Fitbot/app/src/main/res/drawable/ic_launcher_background.xml b/code/src/Fitbot/app/src/main/res/drawable/ic_launcher_background.xml index 3050a42..3a8cd35 100644 --- a/code/src/Fitbot/app/src/main/res/drawable/ic_launcher_background.xml +++ b/code/src/Fitbot/app/src/main/res/drawable/ic_launcher_background.xml @@ -1,170 +1,74 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + xmlns:android="http://schemas.android.com/apk/res/android"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/code/src/Fitbot/app/src/main/res/layout/activity_end_screen.xml b/code/src/Fitbot/app/src/main/res/layout/activity_end_screen.xml index 4579826..35aa21a 100644 --- a/code/src/Fitbot/app/src/main/res/layout/activity_end_screen.xml +++ b/code/src/Fitbot/app/src/main/res/layout/activity_end_screen.xml @@ -12,7 +12,7 @@ android:layout_height="450dp" android:layout_marginStart="80dp" android:layout_marginTop="24dp" - android:background="@drawable/help2_background" + android:background="@drawable/border_background_2" android:orientation="vertical" android:padding="16dp" app:layout_constraintStart_toStartOf="parent" @@ -24,7 +24,7 @@ android:layout_gravity="center" android:layout_marginTop="20dp" android:layout_marginBottom="40dp" - android:background="@drawable/help_background" + android:background="@drawable/border_background" android:orientation="vertical" android:paddingVertical="15dp" android:paddingHorizontal="20dp" @@ -44,7 +44,7 @@ android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="10dp" - android:background="@drawable/help_background" + android:background="@drawable/border_background" android:orientation="vertical" android:padding="16dp" app:layout_constraintStart_toStartOf="parent" @@ -64,7 +64,7 @@ android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="10dp" - android:background="@drawable/help_background" + android:background="@drawable/border_background" android:orientation="vertical" android:padding="16dp" app:layout_constraintStart_toStartOf="parent" diff --git a/code/src/Fitbot/app/src/main/res/layout/activity_fitness.xml b/code/src/Fitbot/app/src/main/res/layout/activity_fitness.xml index 000302c..08f24a3 100644 --- a/code/src/Fitbot/app/src/main/res/layout/activity_fitness.xml +++ b/code/src/Fitbot/app/src/main/res/layout/activity_fitness.xml @@ -14,52 +14,104 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - android:layout_marginTop="30dp" - android:background="@drawable/help2_background" + android:layout_marginTop="20dp" + android:background="@drawable/border_background_2" android:orientation="horizontal" - android:padding="20dp" + android:padding="30dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.505" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> - + android:background="@drawable/border_background" + android:layout_gravity="center" + android:gravity="center_horizontal"> + android:layout_width="300dp" + android:layout_height="300dp" + android:layout_centerInParent="true" /> + + - - + + + + + + + + + + + + + + + + @@ -80,17 +132,26 @@ tools:ignore="SpeakableTextPresentCheck" />