Added basic safe limit functionality
This commit is contained in:
9
app.py
9
app.py
@ -75,6 +75,9 @@ def transmit():
|
|||||||
if pin != app.config['pin']:
|
if pin != app.config['pin']:
|
||||||
return {'success': False, 'message': 'Unauthorised'}, 401
|
return {'success': False, 'message': 'Unauthorised'}, 401
|
||||||
|
|
||||||
|
if intensity > app.config['limit']:
|
||||||
|
return {'success': False, 'message': 'Exceeded Safe Limit'}, 406
|
||||||
|
|
||||||
# Send the data to WHSPAH
|
# Send the data to WHSPAH
|
||||||
tx: whspah.Transmitter = app.config['transmitter']
|
tx: whspah.Transmitter = app.config['transmitter']
|
||||||
tx.transmit(txID, channel, action, intensity, lucal)
|
tx.transmit(txID, channel, action, intensity, lucal)
|
||||||
@ -92,6 +95,8 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument('--pin', type=int, default=random.randint(1000, 9999),
|
parser.add_argument('--pin', type=int, default=random.randint(1000, 9999),
|
||||||
help='The authorisation pin, defaults to a random number '+
|
help='The authorisation pin, defaults to a random number '+
|
||||||
'between 1000 and 9999')
|
'between 1000 and 9999')
|
||||||
|
parser.add_argument('--limit', type=int, default=99,
|
||||||
|
help='The same limit for intensity.')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Sets the logging version based on --debug
|
# Sets the logging version based on --debug
|
||||||
@ -107,6 +112,10 @@ if __name__ == '__main__':
|
|||||||
app.config['pin'] = args.pin
|
app.config['pin'] = args.pin
|
||||||
print(f'Running with pin {args.pin}.')
|
print(f'Running with pin {args.pin}.')
|
||||||
|
|
||||||
|
# Configure Limit
|
||||||
|
app.config['limit'] = args.limit
|
||||||
|
print(f'Running with safe limit {args.limit}.')
|
||||||
|
|
||||||
if args.debug:
|
if args.debug:
|
||||||
# If in debug mode, run Flask's built in server
|
# If in debug mode, run Flask's built in server
|
||||||
app.run(host=args.ip, port=args.port, debug=True)
|
app.run(host=args.ip, port=args.port, debug=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user