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
97import time
10-
118import 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 ()
2826while 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
0 commit comments