-
Notifications
You must be signed in to change notification settings - Fork 0
/
mqttclient.ls
41 lines (32 loc) · 861 Bytes
/
mqttclient.ls
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
require! {
mqtt,
# './models/tree3D.ls': { topology }
# './models/tree.ls': { topology }
'./models/sierpinski.ls': { topology }
# './models/brownian3d.ls': { topology }
leshdash: { times }
util: { inspect}
}
client = mqtt.connect 'mqtt://localhost'
client.on 'connect', ->
# client.subscribe 'turtle3d'
topo = topology
client.publish 'turtle3d', JSON.stringify(cmd: 'reset')
ping = ->
console.log 'TOPO', inspect(topo.serialize(), depth: 8)
topo := topo.next!
serialized = topo.serialize!
if not serialized.length then
clearInterval bla
else
client.publish 'turtle3d', JSON.stringify(cmd: 'data', data: serialized)
startLoop = (speed=100, max=3) ->
cnt = 0
step = ->
cnt++
if cnt > max
return
ping()
setTimeout(step, speed)
step()
startLoop()