-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimulatedDevice.js
63 lines (50 loc) · 1.72 KB
/
SimulatedDevice.js
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
'use strict';
var connectionString = 'HostName=Resonate.azure-devices.net;DeviceId=Myo;SharedAccessKey=kd/hD5LFdFcO7OcDbEcggHPajsgU+MX9eEip/VtCdkw=';
var Mqtt = require('azure-iot-device-mqtt').Mqtt;
var DeviceClient = require('azure-iot-device').Client
var Message = require('azure-iot-device').Message;
var client = DeviceClient.fromConnectionString(connectionString, Mqtt);
function sendMessage(pose_name) {
// Create a message and send it to the IoT hub every second
setInterval(function(){
// Simulate telemetry.
var pose_name;
var message = new Message(JSON.stringify({
pose: pose_name
}));
//console.log('Sending message: ' + message.getData());
// Send the message.
client.sendEvent(message, function (err) {
if (err) {
console.error('send error: ' + err.toString());
} else {
console.log('message sent');
}
});
}, 1000);
}
$(document).ready(function(){
$("#enter").focus();
var blink = setInterval(function(){
$(".text").fadeTo(500, 0.4,
function(){
$(".text").fadeTo(500, 1);
});
},1000);
$(window).keypress(function(e){
var keycode = e.keyCode;
if (keycode == 49) {
command = "Hi, Alexa" // fist
} else if (keycode == 50) {
command = "Hello there!" //waveOut
} else if (keycode == 51) {
command = "Call Help" //waveIn
} else if (keycode == 52) {
command = "Play Music" //fingersStretch
} else {
return false;
}
$(".text").html(command);
sendMessage(command);
});
});