-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayloadtest.py
More file actions
77 lines (64 loc) · 2.1 KB
/
payloadtest.py
File metadata and controls
77 lines (64 loc) · 2.1 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
import requests
import time
# OM2M server configuration
server_url = "http://192.168.158.66:8080"
resource_path = "/~/in-cse/in-name/solenoid"
content_instance_url = f"{server_url}{resource_path}"
# Authentication credentials
headers = {
"X-M2M-Origin": "admin:admin",
"Content-Type": "application/json;ty=4"
}
def post_command(command):
"""Post a command (ON/OFF) to the OM2M server"""
data = {
"m2m:cin": {
"con": command
}
}
try:
response = requests.post(
content_instance_url,
headers=headers,
json=data
)
if response.status_code == 201:
print(f"Successfully posted command: {command}")
print(f"Response: {response.text}")
else:
print(f"Failed to post command. Status code: {response.status_code}")
print(f"Response: {response.text}")
except Exception as e:
print(f"Error occurred: {e}")
def test_lock_cycle():
"""Test a full lock/unlock cycle with delay"""
# Unlock the solenoid
print("Sending UNLOCK command (ON)...")
post_command("ON")
# Wait for 5 seconds
print("Waiting 5 seconds...")
time.sleep(5)
# Lock the solenoid
print("Sending LOCK command (OFF)...")
post_command("OFF")
def manual_control():
"""Allow manual control of the solenoid lock"""
while True:
command = input("\nEnter command (ON=unlock, OFF=lock, exit to quit): ").strip().upper()
if command == "EXIT":
print("Exiting program...")
break
elif command in ["ON", "OFF"]:
post_command(command)
else:
print("Invalid command. Please enter ON, OFF, or exit.")
if __name__ == "__main__":
print("OM2M Solenoid Lock Control")
print("=========================")
choice = input("Choose mode:\n1. Test lock cycle (unlock/lock)\n2. Manual control\nYour choice (1/2): ")
if choice == "1":
test_lock_cycle()
elif choice == "2":
manual_control()
else:
print("Invalid choice. Exiting.")