-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservidor.js
More file actions
68 lines (62 loc) · 1.67 KB
/
Copy pathservidor.js
File metadata and controls
68 lines (62 loc) · 1.67 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const express = require("express");
const cinco= require("johnny-five");
const path = require("path");
const bodyParser = require("body-parser");
const app = express()
const circuito = new cinco.Board({port: "COM3"})
/*Codigo de servidor*/
var lucecita;
var bocina;
var temp;
var c;
app.get("/", home)
function home(request,response){
response.sendFile(path.join( __dirname +"/control.html"));
}
app.get("/temperatura", temp)
function temp(request,response){
response.send("Esta C alientito");
}
app.listen(9219, iniciar)
function iniciar(){
console.log("ServerUP")
}
app.use(bodyParser.json());
app.post("/mensaje", mensaje);
function mensaje(req,res){
var m = req.body.mensaje;
iot_voz(m);
res.send("ok");
}
/*Codigo de circuito*/
circuito.on("ready", electronica)
function electronica(){
lucecita = new cinco.Led(13)
var sensor = new cinco.Thermometer({
controller: "LM35",
pin: "A0"
});
//lucecita.on()
sensor.on("data", actualizar)
function actualizar(datos){
console.log(datos.C)
}
}
function iot_voz(voz){
console.log("**"+voz+"**");
if(
voz.search("google") != -1 && voz.search("encender") != -1
|| voz.search("google") != -1 && voz.search("enciende") !=-1
|| voz.search("google") != -1 && voz.search("prende") !=-1
|| voz.search("google") != -1 && voz.search("prender") !=-1
){
lucecita.on();
}
else if(voz.search("google") != -1 && voz.search("apagar") != -1 || voz.search("google") != -1 && voz.search("apaga") != -1){
lucecita.off();
lucecita.stop();
}
else if(voz.search("google") != -1 && voz.search("fiesta") != -1 || voz.search("google") != -1 && voz.search("party") != -1){
lucecita.strobe();
}
}