Example #1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from app import webapp

app = webapp(os.getenv("FLASK_CONFIG", "pro"))


if __name__ == '__main__':
    app.debug = app.config['DEBUG']
    app.run(host=os.getenv('SERVER_ADDR', '0.0.0.0'),
            port=int(os.getenv('SERVER_PORT', 5000)))
async def main_logic(websocket, path):
	await check_permit(websocket)
	await recv_msg(websocket)

if __name__ == '__main__':
	switch.switchSetup()
	switch.set_all_switch_off()

	HOST = ''
	PORT = 10223                              #Define port serial 
	BUFSIZ = 1024                             #Define buffer size
	ADDR = (HOST, PORT)

	global flask_app
	flask_app = app.webapp()
	flask_app.startthread()

	try:
		RL=robotLight.RobotLight()
		RL.start()
		RL.breath(70,70,255)
	except:
		print('Use "sudo pip3 install rpi_ws281x" to install WS_281x package\n使用"sudo pip3 install rpi_ws281x"命令来安装rpi_ws281x')
		pass

	while  1:
		wifi_check()
		try:                  #Start server,waiting for client
			start_server = websockets.serve(main_logic, '0.0.0.0', 8888)
			asyncio.get_event_loop().run_until_complete(start_server)