gateway_http_uplink.py
1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Script to be executed.
Open a http server with function serve_forever(port)
Created on Wed Jun 9 10:56:11 2021
@author: Georges de Massol
"""
from http.server import HTTPServer, BaseHTTPRequestHandler
import urllib.parse
import gateway
import test_gateway
import gat
ip = 'localhost'
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write(b'Serveur uplink en marche!')
print("do_get")
def do_POST(self):
print("do_post00")
# ↓↓↓ Lecture de la dernière valeur de GNU Radio ↓↓↓
# la lecture est faite le plus tôt possible pour éviter tout parasitage par un autre appareil.
# Tn : échantillon n
Tn = 123456
# ↑↑↑ Lecture de la dernière valeur de GNU Radio ↑↑↑
content_length = int(self.headers['Content-Length'])
body = self.rfile.read(content_length)
self.send_response(200)
self.end_headers()
print(urllib.parse.urlparse(self.path))
print("do_post0")
# print(urllib.parse.parse_qs(urllib.parse.urlparse(self.path).query))
event = urllib.parse.parse_qs(urllib.parse.urlparse(self.path).query).get('event', None)[0]
print("do_post1")
gat.postcompute(event, body, Tn)
print("do_post2")
def serve_forever(port = 6666):
"""
Function executed permanently.
Do not run code after this function.
Parameters
----------
port : int, optional
Port for the server. The default is 6666.
Returns
-------
None.
"""
print("d1")
httpd = HTTPServer((ip, port), SimpleHTTPRequestHandler)
print("d2")
print("http server for uplink started on {}:{}\n".format(ip, port))
print("d3")
httpd.serve_forever()
print("d4")
#do not add code then
serve_forever()