From 3f3f9a8883fcce763c35eb1b1ecb9be425ecf6cb Mon Sep 17 00:00:00 2001 From: maudulo Date: Sat, 22 Mar 2025 15:27:29 +0100 Subject: [PATCH] add led --- script.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/script.js b/script.js index 99ef0fe..aa704a3 100644 --- a/script.js +++ b/script.js @@ -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}`);