-
Notifications
You must be signed in to change notification settings - Fork 1
/
5_command_with_arguments.py
37 lines (29 loc) · 1.1 KB
/
5_command_with_arguments.py
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
#
# Copyright (C) Orange
#
# 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 time
import json
import LiveObjects
# Create LiveObjects
lo = LiveObjects.Connection()
MESSAGE_RATE = 5
# Define command function with arguments handling
def foo(args={}):
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 + 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