· 6 years ago · Feb 02, 2020, 04:04 AM
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')
11
12if (kval=="ABC123"):
13 f = open("IoTData.csv",'a')
14 f.write(str(val)+',')
15 f.flush()
16 f.close()
17
18 print ("Content-type:text/html\r\n\r\n")
19 print ("<html>")
20 print ("<head>")
21 print ("<title> Edge Device </title>")
22 print ("</head>")
23 print ("<body>")
24 print ("<h2>Data sent by client is %s</h2>" % (val))
25 print ("<h2>Received and Logged</h2>")
26 print ("</body>")
27 print ("</html>")
28else:
29 print ("Content-type:text/html\r\n\r\n")
30 print ("<html>")
31 print ("<head>")
32 print ("<title> Edge Device </title>")
33 print ("</head>")
34 print ("<body>")
35 print ("<h2>Wrong API KEY")
36 print ("</body>")
37 print ("</html>")