-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmqtt_publish1.py
66 lines (50 loc) · 1.97 KB
/
mqtt_publish1.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
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
import paho.mqtt.client as mqtt
from random import randrange, uniform
import time
from enum import Enum
import os
mqttBroker = "192.168.1.113"
client = mqtt.Client("User")
client.connect(mqttBroker)
class ProgramState(Enum):
START = 1
RUNNING = 2
def user_interface(program_state=ProgramState.START):
if program_state == ProgramState.START:
introduction = "This program will allow you to control the Donkey. \n" \
"You can command robot to move forward by typing the distance, you want the robot to travel. \n" \
"If You wish to change the direction type: \n" \
"R - to turn right \n" \
"L - to turn left \n" \
"T - to turn back \n" \
"F - to finish giving the commands \n\n"
print(introduction)
command = 'START'
client.publish("COMMANDS", command)
print("Just published " + str(command) + " to Topic COMMANDS")
time.sleep(1)
while True:
try:
command = input(">")
if command not in ['R', 'L', 'T', 'F', 'STOP']:
# sprawdza czy input jest liczbą
try:
int(command)
except:
raise ValueError(f"Invalid command. You entered '{command}'. Command can be only an int() number or R, L, T, F")
if command == 'F':
command = 'STOP'
# user_input.append(command)
client.publish("COMMANDS", command)
print("Just published " + str(command) + " to Topic COMMANDS")
time.sleep(1)
if command == 'STOP':
break
except ValueError as input_exeption_msg:
print(input_exeption_msg)
user_interface()
# 1345os.system('kill SIGINT2')
# message = user_interface()
# client.publish("TEMPERATURE", message)
# print("Just published " + str(message) + " to Topic TEMPERATURE")
# time.sleep(1)