add led
This commit is contained in:
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user