Skip to content

Instantly share code, notes, and snippets.

@koryk
Created August 6, 2023 12:33
Show Gist options
  • Save koryk/125652509d83e9b78a26a65ba3657083 to your computer and use it in GitHub Desktop.
Save koryk/125652509d83e9b78a26a65ba3657083 to your computer and use it in GitHub Desktop.
from http.server import BaseHTTPRequestHandler, HTTPServer
import os
class HTTPRequestHandler(BaseHTTPRequestHandler):
"""HTTP request handler with additional properties and functions."""
def do_GET(self):
"""handle GET requests."""
lookup = [ { 'path': 'fan_light_on', 'freq': '314.962e6', 'filename': 'fan/fan_light_power.iq' },{ 'path': 'fan_power_1', 'freq': '314.962e6', 'filename': 'fan/fan_power_1.iq' },{ 'path': 'fan_power_2', 'freq': '314.962e6', 'filename': 'fan/fan_power_2.iq' },{ 'path': 'fan_power_3', 'freq': '314.962e6', 'filename': 'fan/fan_power_3.iq' }, { 'path': 'fan_power', 'freq': '314.962e6', 'filename': 'fan/fan_power.iq' } ]
#lookup the path in lookup obj
for obj in lookup:
print(obj)
if self.path.endswith('/'+obj['path']):
os.system("sudo /home/pi/dev/rpitx/sendiq -s 250000 -f " + obj['freq'] + " -t u8 -i /home/pi/dev/rpitx/samples/" + obj['filename'])
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(b'OK')
return
#run sendiq
#send response when done
self.send_response(404)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(b'OK')
# Do stuff.
def run(server_class=HTTPServer, handler_class=HTTPRequestHandler):
server_address = ('', 8000)
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment