Skip to content

Commit 1813864

Browse files
committed
Updates
1 parent 315a115 commit 1813864

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

ea/index.html

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Particle Photon Control</title>
7+
<script>
8+
async function callParticleFunction(functionName) {
9+
const deviceId = '0a10aced202194944a059338'; // Replace with your Particle Photon 2 device ID
10+
const accessToken = 'be7fbe58b2ce37101ba8ec4ba937264e90fa6ca0'; // Replace with your Particle access token
11+
12+
const url = `https://api.particle.io/v1/devices/${deviceId}/${functionName}`;
13+
const data = {
14+
arg: '',
15+
access_token: accessToken
16+
};
17+
18+
try {
19+
const response = await fetch(url, {
20+
method: 'POST',
21+
headers: {
22+
'Content-Type': 'application/x-www-form-urlencoded'
23+
},
24+
body: new URLSearchParams(data)
25+
});
26+
27+
const result = await response.json();
28+
console.log(result);
29+
30+
if (functionName === 'toggleLED') {
31+
//alert(`LED is now ${result.return_value === 1 ? 'ON' : 'OFF'}`);
32+
} else if (functionName === 'activateBuzzer') {
33+
//alert('Buzzer activated');
34+
}
35+
} catch (error) {
36+
console.error('Error:', error);
37+
}
38+
}
39+
40+
function toggleLED() {
41+
callParticleFunction('toggleLED');
42+
}
43+
44+
function activateBuzzer() {
45+
callParticleFunction('activateBuzzer');
46+
}
47+
</script>
48+
</head>
49+
<body>
50+
<h1>Particle Photon Control</h1>
51+
<button onclick="toggleLED()">Toggle LED</button>
52+
<button onclick="activateBuzzer()">Activate Buzzer</button>
53+
</body>
54+
</html>

0 commit comments

Comments
 (0)