-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
94 lines (77 loc) · 1.67 KB
/
Copy pathserver.js
File metadata and controls
94 lines (77 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const express = require("express")
const arduino = require("johnny-five")
const path = require("path")
const bodyParser = require("body-parser")
const canciones = require("j5-songs")
const app = express()
const circuito = new arduino.Board()
var lucecita, bocina;
/*
CÓDIGO DEL SERVIDOR
*/
app.get("/", casita)
function casita(req, res) {
res.sendFile( path.join( __dirname + "/interfaz.html" ) )
}
app.use(bodyParser.json())
app.post("/mensaje", mensaje)
app.get("/temperatura", temper)
app.listen(8000, iniciar)
function mensaje(req,res) {
var m = req.body.voz
iot_voz(m)
res.send("ok")
}
function temper(req, res) {
res.send("Está como calentito")
}
function iniciar() {
console.log("Mi primer server :3")
}
/*
CÓDIGO DEL CIRCUITO
*/
circuito.on("ready", electronica)
function electronica() {
lucecita = new arduino.Led(13)
var sensor = new arduino.Thermometer({
controller: "LM35",
pin: "A0"
})
bocina = new arduino.Piezo(9)
lucecita.on()
sensor.on("data", actualizar);
}
function iot_voz(voice)
{
lucecita.stop();
lucecita.off();
console.log("**"+voice+"**");
if(voice.search("encender") != -1 || voice.search("enciende") != -1)
{
lucecita.on()
}
if(voice.search("apagar") != -1 || voice.search("apaga") != -1)
{
lucecita.off()
}
if(voice.search("fiesta") != -1 || voice.search("rumba") != -1)
{
lucecita.strobe()
}
if(voice.search("canción") != -1)
{
bocina.play(canciones.load("beethovens-fifth"))
}
if(voice.search("soy tu padre") != -1)
{
bocina.play(canciones.load("starwars-theme"))
}
if(voice.search("rusia") != -1)
{
bocina.play(canciones.load("tetris-theme"))
}
}
function actualizar(datos) {
//console.log(datos.C)
}