Skip to content

Commit 0616a06

Browse files
rabid-inventorGadgetoid
authored andcommitted
Automation2040W Mini: Fixed example.
1 parent 9dbd25b commit 0616a06

File tree

1 file changed

+46
-16
lines changed
  • micropython/examples/automation2040w/web_io_interface

1 file changed

+46
-16
lines changed

micropython/examples/automation2040w/web_io_interface/main.py

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@
88

99

1010
board = Automation2040W()
11+
isMini = False
12+
13+
# Uncomment for Automation2040WMini
14+
'''
15+
from automation import Automation2040WMini
16+
board = Automation2040WMini()
17+
isMini = True
18+
'''
1119

1220

1321
def status_handler(mode, status, ip):
1422

1523
print("Network: {}".format(WIFI_CONFIG.SSID))
1624
status_text = "Connecting..."
17-
board.conn_led(20.0)
25+
board.conn_led(20)
1826
if status is not None:
1927
if status:
2028
status_text = "Connection successful!"
@@ -72,7 +80,9 @@ def post(self, data):
7280
if 'two' in data.keys():
7381
board.output(1, int(data['two']))
7482
if 'three' in data.keys():
75-
board.output(2, int(data['three']))
83+
if (not isMini):
84+
board.output(2, int(data['three']))
85+
7686
return {'message': 'outputs updated'}, 201
7787

7888

@@ -82,7 +92,10 @@ def not_exists(self):
8292
return {'message': 'no data provided'}, 404
8393

8494
def get(self, data):
85-
return {"one": board.read_input(0), "two": board.read_input(1), "three": board.read_input(2), "four": board.read_input(3)}, 201
95+
if (not isMini):
96+
return {"one": board.read_input(0), "two": board.read_input(1), "three": board.read_input(2), "four": board.read_input(3)}, 201
97+
else:
98+
return {"one": board.read_input(0), "two": board.read_input(1), "three": "N/A", "four": "N/A"}, 201
8699

87100
def post(self, data):
88101
return {'message': 'outputs updated'}, 201
@@ -118,21 +131,28 @@ def not_exists(self):
118131
return {'message': 'no data provided'}, 404
119132

120133
def get(self, data):
134+
121135
if 'one' in data.keys():
122-
board.output(0, bool(data['one']))
136+
print(int(data['one']))
137+
board.output(0, bool(int(data['one'])))
123138
if 'two' in data.keys():
124-
board.output(1, bool(data['two']))
139+
board.output(1, bool(int(data['two'])))
125140
if 'three' in data.keys():
126-
board.output(2, bool(data['three']))
127-
return {"one": bool(board.output(0)), "two": bool(board.output(1)), "three": bool(board.output(2))}, 201
141+
if (not isMini):
142+
board.output(2, bool(int(data['three'])))
143+
if (not isMini):
144+
return {"one": bool(board.output(0)), "two": bool(board.output(1)), "three": bool(board.output(2))}, 201
145+
else:
146+
return {"one": bool(board.output(0)), "two": bool(board.output(1)), "three": "N/A"}, 201
128147

129148
def post(self, data):
130149
if 'one' in data.keys():
131-
board.output(0, int(data['one']))
150+
board.output(0, bool(int(data['one'])))
132151
if 'two' in data.keys():
133-
board.output(1, int(data['two']))
152+
board.output(1, bool(int(data['two'])))
134153
if 'three' in data.keys():
135-
board.output(2, int(data['three']))
154+
if (not isMini):
155+
board.output(2, int(data['three']))
136156
return {'message': 'outputs updated'}, 201
137157

138158

@@ -143,20 +163,30 @@ def not_exists(self):
143163

144164
def get(self, data):
145165
if 'one' in data.keys():
146-
board.relay(0, int(data['one']))
166+
if (not isMini):
167+
board.relay(0, int(data['one']))
168+
else:
169+
board.relay(int(data['one']))
147170
if 'two' in data.keys():
148-
board.relay(1, int(data['two']))
171+
if (not isMini):
172+
board.relay(1, int(data['two']))
149173
if 'three' in data.keys():
150-
board.relay(2, int(data['three']))
151-
return {"one": board.relay(0), "two": board.relay(1), "three": board.relay(2)}, 201
174+
if (not isMini):
175+
board.relay(2, int(data['three']))
176+
if (not isMini):
177+
return {"one": bool(board.relay(0)), "two": bool(board.relay(1)), "three": bool(board.relay(2))}, 201
178+
else:
179+
return {"one": bool(board.relay()), "two": "N/A", "three": "N/A"}, 201
152180

153181
def post(self, data):
154182
if 'one' in data.keys():
155183
board.relay(0, int(data['one']))
156184
if 'two' in data.keys():
157-
board.relay(1, int(data['two']))
185+
if (not isMini):
186+
board.relay(1, int(data['two']))
158187
if 'three' in data.keys():
159-
board.relay(2, int(data['three']))
188+
if (not isMini):
189+
board.relay(2, int(data['three']))
160190
return {'message': 'outputs updated'}, 201
161191

162192

0 commit comments

Comments
 (0)