Skip to content

Commit

Permalink
Merge pull request #3 from tomekmalek/master
Browse files Browse the repository at this point in the history
V. 2.0.0 update
  • Loading branch information
tomekmalek committed Apr 5, 2022
2 parents 8a07de6 + 021df4f commit 99c2ac9
Show file tree
Hide file tree
Showing 13 changed files with 746 additions and 357 deletions.
27 changes: 12 additions & 15 deletions 1_send_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,21 @@
# This software is distributed under the terms and conditions of the 'MIT'
# license which can be found in the file 'LICENSE.md' in this package distribution

import os
import sys
import time

import LiveObjects

#Create LiveObjects with parameters: ClientID - Security - APIKEY
lo = LiveObjects.Connection("PythonMQTT", LiveObjects.NONE, "<APIKEY>")
# Create LiveObjects
lo = LiveObjects.Connection()

MESSAGE_RATE = 5

messageRate = 5
# Main program
lo.connect() # Connect to LiveObjects
last = uptime = time.time()

#Main program
lo.connect() #Connect to LiveObjects
last = time.time()
uptime = time.time()
while True:
if time.time()>=last+messageRate:
lo.addToPayload("uptime", int(time.time() - uptime) ) #Add value to payload: name - value
lo.sendData() #Sending data to cloud
lo.loop() #Check for incoming messages and if connection is still active
last = time.time()
if (time.time()) >= last + MESSAGE_RATE:
lo.add_to_payload("uptime", int(time.time() - uptime)) # Add value to payload: name - value
lo.send_data() # Sending data to cloud
last = time.time()
lo.loop() # Check for incoming messages and if connection is still active
30 changes: 14 additions & 16 deletions 2_simple_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@
# This software is distributed under the terms and conditions of the 'MIT'
# license which can be found in the file 'LICENSE.md' in this package distribution

import os
import sys
import time

import LiveObjects

#Create LiveObjects with parameters: ClientID - Security - APIKEY
lo = LiveObjects.Connection("PythonMQTT", LiveObjects.NONE, "<APIKEY>")
# Create LiveObjects
lo = LiveObjects.Connection()

# Main program
# Available types: INT, BINARY, STRING, FLOAT
lo.add_parameter("message_rate", 5, LiveObjects.INT) # Add parameter: Name - Value - Type

lo.connect() # Connect to LiveObjects
last = uptime = time.time()

#Main program
lo.addParameter("messageRate", 5 , LiveObjects.INT) #Add parameter: Name - Value - Type
#Available types: INT BINARY STRING FLOAT
lo.connect() #Connect to LiveObjects
last = time.time()
uptime = time.time()
while True:
if time.time()>=last+lo.getParameter("messageRate"):#Get the parameter using its name
lo.addToPayload("uptime", int(time.time() - uptime) ) #Add value to payload: name - value
lo.sendData() #Sending data to cloud
lo.loop() #Check for incoming messages and if connection is still active
last = time.time()
if time.time() >= last + lo.get_parameter("message_rate"): # Get the parameter using its name
lo.add_to_payload("uptime", int(time.time() - uptime)) # Add value to payload: name - value
lo.send_data() # Sending data to cloud
last = time.time()
lo.loop() # Check for incoming messages and if connection is still active
36 changes: 17 additions & 19 deletions 3_parameter_with_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@
# This software is distributed under the terms and conditions of the 'MIT'
# license which can be found in the file 'LICENSE.md' in this package distribution

import os
import sys
import time

import LiveObjects


#Create LiveObjects with parameters: ClientID - Security - APIKEY
lo = LiveObjects.Connection("PythonMQTT", LiveObjects.NONE, "<APIKEY>")
# Create LiveObjects
lo = LiveObjects.Connection()


# Callback for a parameter change
def callback(parameter_name, new_value):
print("Changed value of the parameter " + parameter_name + " to " + str(new_value))

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

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

#Main program
lo.addParameter("messageRate", 5 , LiveObjects.INT, callback) #Add parameter: Name - Value - Type - Callback
#Available types: INT BINARY STRING FLOAT
lo.connect() #Connect to LiveObjects
last = time.time()
uptime = time.time()
while True:
if time.time()>=last+lo.getParameter("messageRate"):#Get the parameter using its name
lo.addToPayload("uptime", int(time.time() - uptime) ) #Add value to payload: name - value
lo.sendData() #Sending data to cloud
lo.loop() #Check for incoming messages and if connection is still active
last = time.time()
if time.time() >= last + lo.get_parameter("message_rate"): # Get the parameter using its name
lo.add_to_payload("uptime", int(time.time() - uptime)) # Add value to payload: name - value
lo.send_data() # Sending data to cloud
last = time.time()
lo.loop() # Check for incoming messages and if connection is still active
35 changes: 17 additions & 18 deletions 4_simple_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@
# This software is distributed under the terms and conditions of the 'MIT'
# license which can be found in the file 'LICENSE.md' in this package distribution

import os
import sys
import time

import LiveObjects

#Create LiveObjects with parameters: ClientID - Security - APIKEY
lo = LiveObjects.Connection("PythonMQTT", LiveObjects.NONE, "<APIKEY>")
# Create LiveObjects
lo = LiveObjects.Connection()

MESSAGE_RATE = 5

messageRate = 5

#Define command function
# Define command function
def foo(arg={}):
lo.outputDebug(LiveObjects.INFO,"Called function foo")
lo.output_debug(LiveObjects.INFO, "Called function foo")
return {}

#Main program
lo.addCommand("foo",foo) #Add command to LiveObjects: name - function
lo.connect() #Connect to LiveObjects
last = time.time()
uptime = time.time()

# Main program
lo.add_command("foo", foo) # Add command to LiveObjects: name - function
lo.connect() # Connect to LiveObjects
last = uptime = time.time()

while True:
if time.time()>=last+messageRate:
lo.addToPayload("uptime", int(time.time() - uptime) ) #Add value to payload: name - value
lo.sendData() #Sending data to cloud
lo.loop() #Check for incoming messages and if connection is still active
last = time.time()
if time.time() >= last + MESSAGE_RATE:
lo.add_to_payload("uptime", int(time.time() - uptime)) # Add value to payload: name - value
lo.send_data() # Sending data to cloud
last = time.time()
lo.loop() # Check for incoming messages and if connection is still active
46 changes: 23 additions & 23 deletions 5_command_with_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@
# This software is distributed under the terms and conditions of the 'MIT'
# license which can be found in the file 'LICENSE.md' in this package distribution

import os
import sys
import time
import json
import LiveObjects

#Create LiveObjects with parameters: ClientID - Security - APIKEY
lo = LiveObjects.Connection("PythonMQTT", LiveObjects.NONE, "<APIKEY>")
# Create LiveObjects
lo = LiveObjects.Connection()

messageRate = 5
MESSAGE_RATE = 5

#Define command function with arguments handling

# Define command function with arguments handling
def foo(args={}):
lo.outputDebug(LiveObjects.INFO,"Called function foo with args", json.dumps(args))
counter = 0
for i in range(args["repetitions"]):
print("Repetition nr "+str(i))
counter+=1
return { "Repeated" : str(counter)+" times"}

#Main program
lo.addCommand("foo",foo) #Add command to LiveObjects: name - function
lo.connect() #Connect to LiveObjects
last = time.time()
uptime = time.time()
lo.output_debug(LiveObjects.INFO, "Called function foo with args", json.dumps(args))
counter = 0
for i in range(args["repetitions"]):
print("Repetition nr " + str(i))
counter += 1
return {"Repeated": str(counter) + " times."}


# Main program
lo.add_command("foo", foo) # Add command to LiveObjects: name - function
lo.connect() # Connect to LiveObjects
last = uptime = time.time()

while True:
if time.time()>=last+messageRate:
lo.addToPayload("uptime", int(time.time() - uptime) ) #Add value to payload: name - value
lo.sendData() #Sending data to cloud
lo.loop() #Check for incoming messages and if connection is still active
last = time.time()
if time.time() >= last + MESSAGE_RATE:
lo.add_to_payload("uptime", int(time.time() - uptime)) # Add value to payload: name - value
lo.send_data() # Sending data to cloud
last = time.time()
lo.loop() # Check for incoming messages and if connection is still active
Loading

0 comments on commit 99c2ac9

Please sign in to comment.