This commit is contained in:
maudulo
2025-03-22 15:27:29 +01:00
parent aa017a2715
commit 3f3f9a8883
+24
View File
@@ -3,6 +3,7 @@ const URL = "192.168.185.20";
let socketMoteur = undefined;
let socketInfos = undefined;
let moteur = undefined;
let led = undefined;
const connectSockets = () => {
@@ -97,14 +98,37 @@ class Moteur {
}
class Led {
http = undefined;
send(color){
this.http = new XMLHttpRequest();
this.http.open('POST', 'http://' + URL + '/led/set_color', true);
this.http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
this.http.send('ledcolor=' + color);
}
red(){
this.send("#ff0000")
}
green(){
this.send("#00ff00")
}
blue(){
this.send("#0000ff")
}
}
function run() {
connectSockets();
moteur = new Moteur();
led = new Led();
socketMoteur.onmessage = function(event) {
console.log(`[message] Data received from server: ${event.data}`);