-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
84 lines (69 loc) · 2.79 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Generador de Código Arduino iBeacon</title>
</head>
<body>
<h1>Generador de Código Arduino iBeacon</h1>
<label for="uuid">UUID:</label>
<input type="text" id="uuid" placeholder="Ej: 4B57454D-4132-3430-3630-303030304541" style="width: 400px;"><br><br>
<label for="major">Major:</label>
<input type="number" id="major" placeholder="Ej: 4660"><br><br>
<label for="minor">Minor:</label>
<input type="number" id="minor" placeholder="Ej: 30520"><br><br>
<button id="generate">Generar Código</button>
<h2>Código Generado:</h2>
<pre><code id="output" style="background-color: #f4f4f4; padding: 10px; border: 1px solid #ddd; display: block;"></code></pre>
<script>
document.getElementById("generate").addEventListener("click", () => {
const uuid = document.getElementById("uuid").value.toUpperCase().replace(/-/g, '');
const major = parseInt(document.getElementById("major").value) || 0;
const minor = parseInt(document.getElementById("minor").value) || 0;
if (uuid.length !== 32) {
alert("El UUID debe tener exactamente 32 caracteres (16 bytes) después de quitar los guiones.");
return;
}
const uuidBytes = uuid.match(/.{1,2}/g).map(byte => `0x${byte}`);
const majorBytes = [(major >> 8) & 0xFF, major & 0xFF].map(byte => `0x${byte.toString(16).toUpperCase().padStart(2, '0')}`);
const minorBytes = [(minor >> 8) & 0xFF, minor & 0xFF].map(byte => `0x${byte.toString(16).toUpperCase().padStart(2, '0')}`);
const code = `
#include <ArduinoBLE.h>
void setup() {
Serial.begin(9600);
while (!Serial);
if (!BLE.begin()) {
Serial.println("No se pudo inicializar BLE");
while (1);
}
// Configuración del nombre del dispositivo
BLE.setDeviceName("iBeaconDevice");
BLE.setLocalName("iBeacon Debug");
// Datos de advertising con Manufacturer Data
uint8_t manufacturerData[] = {
0x4C, 0x00, // ID de fabricante (Apple)
0x02, 0x15, // iBeacon type + longitud
${uuidBytes.join(', ')}, // UUID (16 bytes)
${majorBytes.join(', ')}, // Major
${minorBytes.join(', ')}, // Minor
0xC5 // Tx Power
};
// Establecer los datos Manufacturer Data
BLE.setManufacturerData(manufacturerData, sizeof(manufacturerData));
// Iniciar advertising
if (BLE.advertise()) {
Serial.println("Advertising iniciado correctamente");
} else {
Serial.println("Error al iniciar advertising");
}
}
void loop() {
// Mantener BLE activo
}
`.trim();
document.getElementById("output").textContent = code;
});
</script>
</body>
</html>