Skip to content

Commit 99c2ac9

Browse files
authored
Merge pull request #3 from tomekmalek/master
V. 2.0.0 update
2 parents 8a07de6 + 021df4f commit 99c2ac9

13 files changed

+746
-357
lines changed

1_send_data.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,21 @@
44
# This software is distributed under the terms and conditions of the 'MIT'
55
# license which can be found in the file 'LICENSE.md' in this package distribution
66

7-
import os
8-
import sys
97
import time
10-
118
import LiveObjects
129

13-
#Create LiveObjects with parameters: ClientID - Security - APIKEY
14-
lo = LiveObjects.Connection("PythonMQTT", LiveObjects.NONE, "<APIKEY>")
10+
# Create LiveObjects
11+
lo = LiveObjects.Connection()
12+
13+
MESSAGE_RATE = 5
1514

16-
messageRate = 5
15+
# Main program
16+
lo.connect() # Connect to LiveObjects
17+
last = uptime = time.time()
1718

18-
#Main program
19-
lo.connect() #Connect to LiveObjects
20-
last = time.time()
21-
uptime = time.time()
2219
while True:
23-
if time.time()>=last+messageRate:
24-
lo.addToPayload("uptime", int(time.time() - uptime) ) #Add value to payload: name - value
25-
lo.sendData() #Sending data to cloud
26-
lo.loop() #Check for incoming messages and if connection is still active
27-
last = time.time()
20+
if (time.time()) >= last + MESSAGE_RATE:
21+
lo.add_to_payload("uptime", int(time.time() - uptime)) # Add value to payload: name - value
22+
lo.send_data() # Sending data to cloud
23+
last = time.time()
24+
lo.loop() # Check for incoming messages and if connection is still active

2_simple_parameters.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,22 @@
44
# This software is distributed under the terms and conditions of the 'MIT'
55
# license which can be found in the file 'LICENSE.md' in this package distribution
66

7-
import os
8-
import sys
97
import time
10-
118
import LiveObjects
129

13-
#Create LiveObjects with parameters: ClientID - Security - APIKEY
14-
lo = LiveObjects.Connection("PythonMQTT", LiveObjects.NONE, "<APIKEY>")
10+
# Create LiveObjects
11+
lo = LiveObjects.Connection()
12+
13+
# Main program
14+
# Available types: INT, BINARY, STRING, FLOAT
15+
lo.add_parameter("message_rate", 5, LiveObjects.INT) # Add parameter: Name - Value - Type
16+
17+
lo.connect() # Connect to LiveObjects
18+
last = uptime = time.time()
1519

16-
#Main program
17-
lo.addParameter("messageRate", 5 , LiveObjects.INT) #Add parameter: Name - Value - Type
18-
#Available types: INT BINARY STRING FLOAT
19-
lo.connect() #Connect to LiveObjects
20-
last = time.time()
21-
uptime = time.time()
2220
while True:
23-
if time.time()>=last+lo.getParameter("messageRate"):#Get the parameter using its name
24-
lo.addToPayload("uptime", int(time.time() - uptime) ) #Add value to payload: name - value
25-
lo.sendData() #Sending data to cloud
26-
lo.loop() #Check for incoming messages and if connection is still active
27-
last = time.time()
21+
if time.time() >= last + lo.get_parameter("message_rate"): # Get the parameter using its name
22+
lo.add_to_payload("uptime", int(time.time() - uptime)) # Add value to payload: name - value
23+
lo.send_data() # Sending data to cloud
24+
last = time.time()
25+
lo.loop() # Check for incoming messages and if connection is still active

3_parameter_with_callback.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,28 @@
44
# This software is distributed under the terms and conditions of the 'MIT'
55
# license which can be found in the file 'LICENSE.md' in this package distribution
66

7-
import os
8-
import sys
97
import time
10-
118
import LiveObjects
129

1310

14-
#Create LiveObjects with parameters: ClientID - Security - APIKEY
15-
lo = LiveObjects.Connection("PythonMQTT", LiveObjects.NONE, "<APIKEY>")
11+
# Create LiveObjects
12+
lo = LiveObjects.Connection()
13+
14+
15+
# Callback for a parameter change
16+
def callback(parameter_name, new_value):
17+
print("Changed value of the parameter " + parameter_name + " to " + str(new_value))
1618

17-
#Callback for a parameter change
18-
def callback(parameterName, newValue):
19-
print("Changed value of the parameter "+parameterName+" to " + str(newValue))
2019

20+
# Main program
21+
# Available types: INT, BINARY, STRING, FLOAT
22+
lo.add_parameter("message_rate", 5, LiveObjects.INT, callback) # Add parameter: Name - Value - Type - Callback
23+
lo.connect() # Connect to LiveObjects
24+
last = uptime = time.time()
2125

22-
#Main program
23-
lo.addParameter("messageRate", 5 , LiveObjects.INT, callback) #Add parameter: Name - Value - Type - Callback
24-
#Available types: INT BINARY STRING FLOAT
25-
lo.connect() #Connect to LiveObjects
26-
last = time.time()
27-
uptime = time.time()
2826
while True:
29-
if time.time()>=last+lo.getParameter("messageRate"):#Get the parameter using its name
30-
lo.addToPayload("uptime", int(time.time() - uptime) ) #Add value to payload: name - value
31-
lo.sendData() #Sending data to cloud
32-
lo.loop() #Check for incoming messages and if connection is still active
33-
last = time.time()
27+
if time.time() >= last + lo.get_parameter("message_rate"): # Get the parameter using its name
28+
lo.add_to_payload("uptime", int(time.time() - uptime)) # Add value to payload: name - value
29+
lo.send_data() # Sending data to cloud
30+
last = time.time()
31+
lo.loop() # Check for incoming messages and if connection is still active

4_simple_command.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,29 @@
44
# This software is distributed under the terms and conditions of the 'MIT'
55
# license which can be found in the file 'LICENSE.md' in this package distribution
66

7-
import os
8-
import sys
97
import time
10-
118
import LiveObjects
129

13-
#Create LiveObjects with parameters: ClientID - Security - APIKEY
14-
lo = LiveObjects.Connection("PythonMQTT", LiveObjects.NONE, "<APIKEY>")
10+
# Create LiveObjects
11+
lo = LiveObjects.Connection()
12+
13+
MESSAGE_RATE = 5
1514

16-
messageRate = 5
1715

18-
#Define command function
16+
# Define command function
1917
def foo(arg={}):
20-
lo.outputDebug(LiveObjects.INFO,"Called function foo")
18+
lo.output_debug(LiveObjects.INFO, "Called function foo")
2119
return {}
2220

23-
#Main program
24-
lo.addCommand("foo",foo) #Add command to LiveObjects: name - function
25-
lo.connect() #Connect to LiveObjects
26-
last = time.time()
27-
uptime = time.time()
21+
22+
# Main program
23+
lo.add_command("foo", foo) # Add command to LiveObjects: name - function
24+
lo.connect() # Connect to LiveObjects
25+
last = uptime = time.time()
26+
2827
while True:
29-
if time.time()>=last+messageRate:
30-
lo.addToPayload("uptime", int(time.time() - uptime) ) #Add value to payload: name - value
31-
lo.sendData() #Sending data to cloud
32-
lo.loop() #Check for incoming messages and if connection is still active
33-
last = time.time()
28+
if time.time() >= last + MESSAGE_RATE:
29+
lo.add_to_payload("uptime", int(time.time() - uptime)) # Add value to payload: name - value
30+
lo.send_data() # Sending data to cloud
31+
last = time.time()
32+
lo.loop() # Check for incoming messages and if connection is still active

5_command_with_arguments.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,34 @@
44
# This software is distributed under the terms and conditions of the 'MIT'
55
# license which can be found in the file 'LICENSE.md' in this package distribution
66

7-
import os
8-
import sys
97
import time
108
import json
119
import LiveObjects
1210

13-
#Create LiveObjects with parameters: ClientID - Security - APIKEY
14-
lo = LiveObjects.Connection("PythonMQTT", LiveObjects.NONE, "<APIKEY>")
11+
# Create LiveObjects
12+
lo = LiveObjects.Connection()
1513

16-
messageRate = 5
14+
MESSAGE_RATE = 5
1715

18-
#Define command function with arguments handling
16+
17+
# Define command function with arguments handling
1918
def foo(args={}):
20-
lo.outputDebug(LiveObjects.INFO,"Called function foo with args", json.dumps(args))
21-
counter = 0
22-
for i in range(args["repetitions"]):
23-
print("Repetition nr "+str(i))
24-
counter+=1
25-
return { "Repeated" : str(counter)+" times"}
26-
27-
#Main program
28-
lo.addCommand("foo",foo) #Add command to LiveObjects: name - function
29-
lo.connect() #Connect to LiveObjects
30-
last = time.time()
31-
uptime = time.time()
19+
lo.output_debug(LiveObjects.INFO, "Called function foo with args", json.dumps(args))
20+
counter = 0
21+
for i in range(args["repetitions"]):
22+
print("Repetition nr " + str(i))
23+
counter += 1
24+
return {"Repeated": str(counter) + " times."}
25+
26+
27+
# Main program
28+
lo.add_command("foo", foo) # Add command to LiveObjects: name - function
29+
lo.connect() # Connect to LiveObjects
30+
last = uptime = time.time()
31+
3232
while True:
33-
if time.time()>=last+messageRate:
34-
lo.addToPayload("uptime", int(time.time() - uptime) ) #Add value to payload: name - value
35-
lo.sendData() #Sending data to cloud
36-
lo.loop() #Check for incoming messages and if connection is still active
37-
last = time.time()
33+
if time.time() >= last + MESSAGE_RATE:
34+
lo.add_to_payload("uptime", int(time.time() - uptime)) # Add value to payload: name - value
35+
lo.send_data() # Sending data to cloud
36+
last = time.time()
37+
lo.loop() # Check for incoming messages and if connection is still active

0 commit comments

Comments
 (0)