-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.lua
56 lines (49 loc) · 1.38 KB
/
functions.lua
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
require('config')
function mqtt_state()
TOPIC = '/data/'
DATA = '{"mac":"'..mac..'","state":"'..gpio.read(DATA_PIN)..'"}'
m:publish(TOPIC, DATA, 0, 0, function(conn)
print(TOPIC.." : "..CLIENT_ID.." - "..DATA)
end)
end
function mqtt_subscribe()
TOPIC = '/action/'
m:subscribe(TOPIC, 2, function(m)
print("Successfully subscribed to the topic: "..TOPIC)
end)
end
function mqtt_ping()
TOPIC = '/ping/'
DATA = '{"mac":"'..mac..'"}'
m:publish(TOPIC, DATA, 0, 0, function(conn)
print(TOPIC.." : "..CLIENT_ID)
end)
end
function mqtt_online()
TOPIC = '/online/'
DATA = '{"mac":"'..mac..'","ip":"'..ip..'","name":"'..CLIENT_ID..'","type":"'..DEVICE_TYPE..'"}'
m:publish(TOPIC, DATA, 0, 0, function(conn)
print(TOPIC.." : "..CLIENT_ID)
end)
end
function mqtt_ip()
TOPIC = '/ip/'
DATA = '{"mac":"'..mac..'","ip":"'..ip..'"}'
m:publish(TOPIC, DATA, 0, 0, function(conn)
print(TOPIC.." : "..DATA)
end)
end
function mqtt_name()
TOPIC = '/name/'
DATA = '{"mac":"'..mac..'","name":"'..CLIENT_ID..'"}'
m:publish(TOPIC, DATA, 0, 0, function(conn)
print(TOPIC.." : "..DATA)
end)
end
function mqtt_type()
TOPIC = '/type/'
DATA = '{"mac":"'..mac..'","type":"'..DEVICE_TYPE..'"}'
m:publish(TOPIC, DATA, 0, 0, function(conn)
print(TOPIC.." : "..DATA)
end)
end