Mise à jour de 'gohttp.py'
This commit is contained in:
		
							parent
							
								
									fa0c8785c7
								
							
						
					
					
						commit
						67cd0ba2f7
					
				
							
								
								
									
										29
									
								
								gohttp.py
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								gohttp.py
									
									
									
									
									
								
							|  | @ -13,6 +13,13 @@ import os | ||||||
| import subprocess | import subprocess | ||||||
| import cgi | import cgi | ||||||
| import time | import time | ||||||
|  | import json | ||||||
|  | 
 | ||||||
|  | fileObject = open("config.json", "r") | ||||||
|  | jsonContent = fileObject.read() | ||||||
|  | config = json.loads(jsonContent) | ||||||
|  | print(config) | ||||||
|  | 
 | ||||||
| GPIO.setwarnings(False) | GPIO.setwarnings(False) | ||||||
| os.system('pkill -9 httpd') | os.system('pkill -9 httpd') | ||||||
| GPIO.setmode(GPIO.BCM) | GPIO.setmode(GPIO.BCM) | ||||||
|  | @ -46,6 +53,12 @@ class S(http.server.SimpleHTTPRequestHandler): | ||||||
|         self.wfile.write("POST request for {}".format(self.path).encode('utf-8')) |         self.wfile.write("POST request for {}".format(self.path).encode('utf-8')) | ||||||
| 
 | 
 | ||||||
|     def _set_response(self): |     def _set_response(self): | ||||||
|  | 
 | ||||||
|  |         fileObject = open("config.json", "r") | ||||||
|  |         jsonContent = fileObject.read() | ||||||
|  |         config = json.loads(jsonContent) | ||||||
|  |         print(config) | ||||||
|  | 
 | ||||||
|         #time.sleep(5) |         #time.sleep(5) | ||||||
|         GPIO.setup(pinList[0], GPIO.OUT) |         GPIO.setup(pinList[0], GPIO.OUT) | ||||||
|         status0=int(GPIO.input(pinList[0])) |         status0=int(GPIO.input(pinList[0])) | ||||||
|  | @ -141,6 +154,15 @@ class S(http.server.SimpleHTTPRequestHandler): | ||||||
|         file = read_html_template("index.html") |         file = read_html_template("index.html") | ||||||
|         self.send_response(200, "OK") |         self.send_response(200, "OK") | ||||||
|         self.end_headers() |         self.end_headers() | ||||||
|  |         #replace config in index.html | ||||||
|  |         file = file.replace("DESIGN1",config['com1']) | ||||||
|  |         file = file.replace("DESIGN2",config['com2']) | ||||||
|  |         file = file.replace("DESIGN3",config['com3']) | ||||||
|  |         file = file.replace("DESIGN4",config['com4']) | ||||||
|  |          | ||||||
|  |         file = file.replace("URL_HTTP",config['url']) | ||||||
|  |         file = file.replace("PORT_HTTP",str(config['port'])) | ||||||
|  |          | ||||||
|         print ('Relay0 = '+str(status0)) |         print ('Relay0 = '+str(status0)) | ||||||
|         if status0 == 0: |         if status0 == 0: | ||||||
|           file = file.replace("CHECKED1", "checked") |           file = file.replace("CHECKED1", "checked") | ||||||
|  | @ -195,9 +217,4 @@ def run(handler_class=S, port=8000): | ||||||
|     logging.info('Stopping httpd...\n') |     logging.info('Stopping httpd...\n') | ||||||
| 
 | 
 | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
|     from sys import argv |     run(port=config['port']) | ||||||
| 
 |  | ||||||
|     if len(argv) == 2: |  | ||||||
|         run(port=int(argv[1])) |  | ||||||
|     else: |  | ||||||
|         run() |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user