File size: 875 Bytes
756c3e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Real-Time Data from Arduino</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.min.js"></script>
</head>
<body>
    <h1>Real-Time Data from Arduino</h1>
    <div id="serialData">Waiting for data...</div>

    <script>
        // Connect to the WebSocket server
        const socket = io();

        // Listen for the 'response' event from the server
        socket.on('response', function(data) {
            // Update the webpage with the new data
            document.getElementById('serialData').innerText = 'Arduino Data: ' + data.message;
        });

        // Send a test message (optional)
        socket.emit('message', 'Hello from browser');
    </script>
</body>
</html>