Untitled
unknown
plain_text
16 days ago
1.4 kB
5
Indexable
<!DOCTYPE html>
<html>
<body style="background:black;color:white;font-size:40px;text-align:center;padding-top:100px;">
<button onclick="toggle()" style="font-size:50px;padding:30px;">
Toggle Hotspot
</button>
<pre id="log"></pre>
<script>
const SERVICE='F000FFC0-0451-4000-B000-000000000000';
const CHAR='F000FFC1-0451-4000-B000-000000000000';
let device,server,service,char;
async function connect(){
device = await navigator.bluetooth.requestDevice({
acceptAllDevices:true,
optionalServices:[SERVICE]
});
server = await device.gatt.connect();
service = await server.getPrimaryService(SERVICE);
char = await service.getCharacteristic(CHAR);
}
async function read(){
let v = await char.readValue();
return new TextDecoder().decode(v);
}
async function write(t){
let e = new TextEncoder().encode(t);
await char.writeValue(e);
}
async function toggle(){
try{
if(!char){
await connect();
}
let s = await read();
document.getElementById('log').innerText=s;
if(s.includes('STATE:OFF')){
await write('1');
await new Promise(r=>setTimeout(r,3000));
let n = await read();
document.getElementById('log').innerText=n;
}else{
await write('0');
document.getElementById('log').innerText='TURNED OFF';
}
}catch(e){
document.getElementById('log').innerText=e;
}
}
</script>
</body>
</html>Editor is loading...
Leave a Comment