forked from snyk-fixtures/python-app-device-cloud-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_app.py
More file actions
executable file
·86 lines (63 loc) · 2.34 KB
/
validate_app.py
File metadata and controls
executable file
·86 lines (63 loc) · 2.34 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
#!/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 helix
import os
import signal
import sys
from time import sleep
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)
client = helix.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) != helix.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()
sys.exit(0)