MCPcopy Create free account
hub / github.com/SiddhantSilwal/RaspberryPi-GPIO-Web-Controller / toggle_monitor

Function toggle_monitor

AppData/app.py:460–482  ·  view source on GitHub ↗

Toggle input monitoring for a pin

()

Source from the content-addressed store, hash-verified

458
459@app.route('/api/monitor', methods=['POST'])
460def toggle_monitor():
461 """Toggle input monitoring for a pin"""
462 try:
463 data = request.get_json()
464 pin = int(data['pin'])
465 enable = data.get('enable', True)
466
467 if pin not in pin_states or pin_states[pin]['mode'] != 'input':
468 return jsonify({'error': f'Pin {pin} is not configured as input'}), 400
469
470 if enable:
471 input_monitors.add(pin)
472 log_event(f"Started monitoring pin {pin}")
473 else:
474 input_monitors.discard(pin)
475 log_event(f"Stopped monitoring pin {pin}")
476
477 return jsonify({'success': True, 'monitoring': pin in input_monitors})
478
479 except Exception as e:
480 error_msg = f"Error toggling monitor: {str(e)}"
481 log_event(error_msg, 'error')
482 return jsonify({'error': error_msg}), 500
483
484@app.route('/api/reset', methods=['POST'])
485def reset_all_pins():

Callers

nothing calls this directly

Calls 1

log_eventFunction · 0.85

Tested by

no test coverage detected