-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrigolo-coap.golo
81 lines (61 loc) · 2.23 KB
/
trigolo-coap.golo
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
module trigolocoap
import guino
import coap
function main = |args| {
let myArduino = device(): port("/dev/cu.usbmodem1411"): initialize(): onSet(|self| {
let redLed = self: getLedInstance("red", 13)
let blueLed = self: getLedInstance("blue", 9)
let yellowLed = self: getLedInstance("yellow", 2)
let red_on = coapResource(): identifier("red_on"): name("red_on")
: $get(|exchange| {
redLed: switchOn()
exchange: respond(CONTENT(), "yo!")
}): initialize()
let red_off = coapResource(): identifier("red_off"): name("red_off")
: $get(|exchange| {
redLed: switchOff()
exchange: respond(CONTENT(), "yo!")
}): initialize()
let blue_on = coapResource(): identifier("blue_on"): name("blue_on")
: $get(|exchange| {
blueLed: switchOn()
exchange: respond(CONTENT(), "yo!")
}): initialize()
let blue_off = coapResource(): identifier("blue_off"): name("blue_off")
: $get(|exchange| {
blueLed: switchOff()
exchange: respond(CONTENT(), "yo!")
}): initialize()
let yellow_on = coapResource(): identifier("yellow_on"): name("yellow_on")
: $get(|exchange| {
yellowLed: switchOn()
exchange: respond(CONTENT(), "yo!")
}): initialize()
let yellow_off = coapResource(): identifier("yellow_off"): name("yellow_off")
: $get(|exchange| {
yellowLed: switchOff()
exchange: respond(CONTENT(), "yo!")
}): initialize()
let stop = coapResource(): identifier("stop"): name("stop")
: $get(|exchange| {
self: stop()
exchange: respond(CONTENT(), "yo!")
})
: initialize()
#blueLed: switchOn()
#yellowLed: switchOn()
#redLed: switchOn()
let server = coapServer(): initialize()
: add(red_on)
: add(red_off)
: add(blue_on)
: add(blue_off)
: add(yellow_on)
: add(yellow_off)
: start()
println("... started ...")
#self: stop()
}): onFail(|err| {
println("Huston? We've got a problem!")
})
}