-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_job.js
53 lines (46 loc) · 1.08 KB
/
test_job.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
var mqtt = require('mqtt').connect('mqtt://localhost:2048');
var config = require('./config.js');
var cocktails = {
bloody: {
activations: [
{time: 5000}, // milliseconds
{time: 3000},
{time: 6000}
]
},
spritz: {
activations: [
{time:4000},
{time: 3000},
{time: 4000}
]
}
};
var defs = {
cocktails: cocktails,
workers: {
bob: {
cocktails: [{machine: 0, cocktail: 'bloody'}, {machine: 1, cocktail: 'spritz'}]
},
mark: {
cocktails: [{machine: 0, cocktail: 'spritz'}, {machine: 1, cocktail: 'spritz'}]
}
}
};
var jobs = [{
id: 0,
name: 'Matteo',
cocktail: 'bloody',
pump: 0,
activations: defs.cocktails.bloody.activations
}];
mqtt.on('connect', function() {
mqtt.subscribe(config.worker);
});
mqtt.on('message', function(topic, message) {
console.log('received message', message.toString());
message = JSON.parse(message.toString());
if (message.status === 'button pressed') {
mqtt.publish('pi1', JSON.stringify({status: 'new jobs', jobs: jobs}));
}
});