30 lines
718 B
Python
30 lines
718 B
Python
|
#!/usr/bin/env python3
|
||
|
# -*- coding: utf-8 -*-
|
||
|
import requests
|
||
|
import json
|
||
|
|
||
|
# Define the API endpoint URL
|
||
|
api_url = 'http://localhost:8042/buzzed' # Update with your actual API URL
|
||
|
|
||
|
# Data payload to be sent as JSON
|
||
|
data_payload = {
|
||
|
'buzzer': 'buzzer1',
|
||
|
'waffle_ready': 1
|
||
|
}
|
||
|
|
||
|
# Convert the payload to JSON format
|
||
|
json_payload = json.dumps(data_payload)
|
||
|
|
||
|
# Set the headers to indicate JSON content
|
||
|
headers = {'Content-Type': 'application/json'}
|
||
|
|
||
|
# Send POST request to the API endpoint
|
||
|
response = requests.post(api_url, data=json_payload, headers=headers)
|
||
|
|
||
|
# Check the response status
|
||
|
if response.status_code == 200:
|
||
|
print('Data added successfully!')
|
||
|
else:
|
||
|
print(f'Error adding data: {response.text}')
|
||
|
|