Merge remote-tracking branch 'origin/main'

This commit is contained in:
Niels Gras
2024-05-31 13:05:33 +02:00
4 changed files with 70 additions and 40 deletions

View File

@@ -1,33 +0,0 @@
#include <BLEDevice.h>
#include <BLEServer.h>
// 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
}

View File

@@ -0,0 +1,8 @@
// config.js
module.exports = {
host: '127.0.0.1',
user: 'fitbot',
password: 'fitbot123',
database: 'fitbot',
port: 3306, // Default MariaDB port
};

View File

@@ -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}`);
});