Skip to content

Commit 6a0bff7

Browse files
Juliana MashonJuliana Mashon
Juliana Mashon
authored and
Juliana Mashon
committed
Added functions to main.py and broker_functions.py--on_connect() takes no arguments
1 parent 1504b4c commit 6a0bff7

File tree

4 files changed

+109
-29
lines changed

4 files changed

+109
-29
lines changed

api_functions.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ def set_info(self, endpoint, field, value, id=None):
2828
def env(self, id=None, field=None, new_val=None):
2929
if id is None:
3030
data = self.api_connect.get('farmware_envs', id=None)
31-
print(data)
31+
print(data) # ?
3232
else:
3333
data = self.api_connect.get('farmware_envs', id)
34-
print(data)
34+
print(data) # ?
35+
# return ...
3536

3637
def log(self, message, type=None, channel=None):
3738
log_message = {

broker_connect.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def on_connect(self, *_args):
4646
self.client.subscribe(f"bot/{self.token['token']['unencoded']['bot']}/#")
4747

4848
def on_message(self, _client, _userdata, msg):
49-
print('-'*100)
50-
# Print channel
51-
print(f"Channel: {msg.topic} ({datetime.now().strftime("%Y-%m-%d %H:%M:%S")})\n")
52-
# Print message
49+
print('-' * 100)
50+
# print channel
51+
print(f'{msg.topic} ({datetime.now().strftime("%Y-%m-%d %H:%M:%S")})\n')
52+
# print message
5353
print(json.dumps(json.loads(msg.payload), indent=4))
5454

5555
def listen(self):

broker_functions.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ def shutdown(self):
146146
def calibrate_camera(self):
147147
calibrate_message = {
148148
**RPC_REQUEST,
149-
"args": {
150-
"label": "3fcd2d32-302b-46c9-9448-b4f30c3a9bb1",
151-
"priority": 600
152-
},
153149
"body": {
154150
"kind": "execute_script",
155151
"args": {
@@ -169,6 +165,19 @@ def calibrate_camera(self):
169165
# return ...
170166

171167
# photo_grid() --> sequence (broker message)
168+
def photo_grid(self):
169+
photo_grid_message = {
170+
**RPC_REQUEST,
171+
"body": {
172+
"kind": "execute",
173+
"args": {
174+
"sequence_id": 24372
175+
}
176+
}
177+
}
178+
179+
self.broker_connect.publish(photo_grid_message)
180+
# return ...
172181

173182
def control_servo(self, pin, angle):
174183
if angle < 0 or angle > 180:
@@ -379,15 +388,8 @@ def axis_length(self, axis='all'):
379388
def mount_tool(self, x, y, z):
380389
mount_tool_message = {
381390
**RPC_REQUEST,
382-
"args": {
383-
"label": "6a6b10a6-46a8-4b97-8b66-c55021c02bbd",
384-
"priority": 600
385-
},
386391
"body": {
387392
"kind": "execute",
388-
"args": {
389-
"sequence_id": 24350
390-
},
391393
"body": {
392394
"kind": "parameter_application",
393395
"args": {
@@ -422,7 +424,7 @@ def mount_tool(self, x, y, z):
422424
# lua() --> sequence (broker message)
423425
# if_statement() --> sequence (broker message)
424426

425-
def assertion(self, code, type, id=''):
427+
def assertion(self, code, as_type, id=''):
426428
assertion_message = {
427429
**RPC_REQUEST,
428430
"body": {
@@ -435,7 +437,7 @@ def assertion(self, code, type, id=''):
435437
"sequence_id": id # Recovery sequence ID
436438
}
437439
},
438-
"assertion_type": type # If test fails, do this
440+
"assertion_type": as_type # If test fails, do this
439441
}
440442
}
441443
}

main.py

+87-10
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,95 @@ def get_info(self, endpoint, id=None):
2828
def set_info(self, endpoint, field, value, id=None):
2929
return self.api.set_info(endpoint, field, value, id)
3030

31-
def connect(self):
32-
self.broker.broker_connect.connect()
31+
def env(self, id=None, field=None, new_val=None):
32+
return self.api.env(id, field, new_val)
33+
34+
def log(self, message, type=None, channel=None):
35+
return self.api.log(message, type, channel)
36+
37+
def safe_z(self):
38+
return self.api.safe_z()
39+
40+
def garden_size(self):
41+
return self.api.garden_size()
42+
43+
def group(self, id):
44+
return self.api.group(id)
45+
46+
def curve(self, id):
47+
return self.api.curve(id)
48+
49+
def read_status(self):
50+
return self.broker.read_status()
51+
52+
def read_sensor(self, id, mode, label='---'):
53+
return self.broker.read_sensor(id, mode, label)
54+
55+
def message(self, message, type=None, channel=None):
56+
return self.broker.message(message, type, channel)
3357

34-
def disconnect(self):
35-
self.broker.broker_connect.disconnect()
36-
return print("Disconnected from message broker.")
58+
def debug(self, message):
59+
return self.broker.debug(message)
3760

38-
def on(self, id):
39-
self.broker.on(id)
61+
def toast(self, message):
62+
return self.broker.toast(message)
63+
64+
def wait(self, time):
65+
return self.broker.wait(time)
66+
67+
def e_stop(self):
68+
return self.broker.e_stop()
69+
70+
def unlock(self):
71+
return self.broker.unlock()
72+
73+
def reboot(self):
74+
return self.broker.reboot()
75+
76+
def shutdown(self):
77+
return self.broker.shutdown()
78+
79+
def calibrate_camera(self):
80+
return self.broker.calibrate_camera()
81+
82+
def control_servo(self, pin, angle):
83+
return self.broker.control_servo(pin, angle)
84+
85+
def control_peripheral(self, id, value, mode=None):
86+
return self.broker.control_peripheral(id, value, mode)
4087

4188
def toggle_peripheral(self, id):
42-
self.broker.toggle_peripheral(id)
89+
return self.broker.toggle_peripheral(id)
90+
91+
def on(self, id):
92+
return self.broker.on(id)
93+
94+
def off(self, id):
95+
return self.broker.off(id)
96+
97+
def take_photo(self):
98+
return self.broker.take_photo()
99+
100+
def soil_height(self):
101+
return self.broker.soil_height()
102+
103+
def detect_weeds(self):
104+
return self.broker.detect_weeds()
105+
106+
def move(self, x, y, z):
107+
return self.broker.move(x, y, z)
108+
109+
def set_home(self, axis='all'):
110+
return self.broker.set_home(axis)
111+
112+
def find_home(self, axis='all', speed=100):
113+
return self.broker.find_home(axis, speed)
114+
115+
def axis_length(self, axis='all'):
116+
return self.broker.axis_length(axis)
117+
118+
def mount_tool(self, x, y, z):
119+
return self.broker.mount_tool(x, y, z)
43120

44-
def listen(self):
45-
self.broker.broker_connect.listen()
121+
def assertion(self, code, as_type, id=''):
122+
return self.broker.assertion(code, as_type, id)

0 commit comments

Comments
 (0)