Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
pajikos committed Mar 11, 2024
1 parent 6880013 commit b35db8e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mqtt-switch2.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ def health_check():

@app.route('/control', methods=['GET'])
def control_page():
global manual_control, last_call
state = 'ON' if switch.is_lit else 'OFF'
manual_control_state = 'ON' if manual_control else 'OFF'
return render_template('switch_control.html', state=state, manual_control=manual_control_state)
return render_template('switch_control.html', state=state, manual_control=manual_control_state, last_call=last_call)

@app.route('/switch/<state>', methods=['POST'])
def change_switch(state):
Expand All @@ -192,6 +193,7 @@ def change_switch(state):

@app.route('/mode/<state>', methods=['POST'])
def change_mode(state):
global manual_control
if state == 'ON':
manual_control = True
elif state == 'OFF':
Expand Down
1 change: 1 addition & 0 deletions templates/switch_control.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ <h1>Manual mode switch</h1>
<p>Current State: <strong id="manualControl">{{ manual_control }}</strong></p>
<button onclick="changeMode('ON')">Turn ON manual mode</button>
<button onclick="changeMode('OFF')">Turn OFF manual mode</button>
<p>Last Call from MQTT: <strong id="lastCall">{{ last_call }}</strong></p>

<script>
function changeState(state) {
Expand Down

0 comments on commit b35db8e

Please sign in to comment.