-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathvalidate_app.py
More file actions
executable file
·105 lines (77 loc) · 2.75 KB
/
validate_app.py
File metadata and controls
executable file
·105 lines (77 loc) · 2.75 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
'''
Copyright (c) 2016-2017 Wind River Systems, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
OR CONDITIONS OF ANY KIND, either express or implied.
'''
"""
Simple app that validates the capabilities of the host machine to run an IOT
application.
"""
import errno
import device_cloud
import os
import signal
import sys
from time import sleep
if "VALIDATE_COVERAGE" in os.environ:
import coverage
enable_cov = True
else:
enable_cov = False
if sys.version_info.major == 2:
input = raw_input
running = True
def sighandler(signum, frame):
"""
Signal handler for exiting app
"""
global running
if signum == signal.SIGINT:
print("Received SIGINT, stopping application...")
running = False
def pass_action(client, params, user_data):
if params and params["param"] == "value":
return 0
else:
return 18
def fail_action(client, params, user_data):
return (19, "fail and such")
if __name__ == "__main__":
signal.signal(signal.SIGINT, sighandler)
if enable_cov == True:
cov = coverage.Coverage()
cov.start()
client = device_cloud.Client("iot-validate-app")
client.config.config_file = "validate.cfg"
client.initialize()
client.action_register_callback("pass_action", pass_action)
client.action_register_callback("fail_action", fail_action)
if client.connect(timeout=10) != device_cloud.STATUS_SUCCESS:
print("Failed to connect")
sys.exit(1)
client.telemetry_publish("property", 12.34)
client.attribute_publish("attribute", "text and such")
client.location_publish(45.351603, -75.918713, heading=12.34, altitude=1.0,
speed=2.0, accuracy=3.0, fix_type="crystal ball")
client.event_publish("logs and such")
client.alarm_publish("alarm", 1, "very serious alarm")
client.file_upload(os.path.abspath(__file__), upload_name="validate_upload",
blocking=True, timeout=30)
client.file_download("validate_upload",
os.path.abspath("validate_download"),
blocking=True, timeout=30)
input("Hit enter to exit:")
client.disconnect()
if os.path.exists(client.config.config_file):
os.remove(client.config.config_file)
if enable_cov == True:
cov.stop()
cov.save()
cov.html_report(omit="/usr/local/lib/*")
sys.exit(0)