· 6 years ago · Dec 29, 2019, 03:08 PM
1#!/usr/bin/env python
2
3import cgi
4
5# Creating Form object
6
7form = cgi.FieldStorage()
8
9val = form.getvalue('field1')
10kval= form.getvalue('api_key')
11if (kval=="ABC123"):
12 f = open("IoTData.csv",'a')
13 f.write(str(val)+',')
14 f.flush()
15 f.close()
16
17 print ("Content-type:text/html\r\n\r\n")
18 print ("<html>")
19 print ("<head>")
20 print ("<title> Edge Device </title>")
21 print ("</head>")
22 print ("<body>")
23 print ("<h2>Data sent by client is %s</h2>" % (val))
24 print ("<h2>Received and Logged</h2>")
25 print ("</body>")
26 print ("</html>")
27else:
28 print ("Content-type:text/html\r\n\r\n")
29 print ("<html>")
30 print ("<head>")
31 print ("<title> Edge Device </title>")
32 print ("</head>")
33 print ("<body>")
34 print ("<h2>Wrong API KEY")
35 print ("</body>")
36 print ("</html>")