Commit 3fa51d37 by hank

python状态统一

parent 641fdddc
......@@ -2,4 +2,5 @@
node_modules
node_modules
log/*
.DS_Store
\ No newline at end of file
.DS_Store
__pycache__/*
\ No newline at end of file
......@@ -11,12 +11,12 @@ if __name__ == "__main__":
def sendUdp(data):
print(data.encode('utf-16be'), 'utf-16be')
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto(data.encode('utf-16be'), ('127.0.0.1', 7000))
s.sendto(data.encode('utf-16be'), ('127.0.0.1', 7001))
s.close()
parser = argparse.ArgumentParser()
parser.add_argument("--ip", default="127.0.0.1",
help="The ip of the OSC server")
parser.add_argument("--port", type=int, default=7000,
parser.add_argument("--port", type=int, default=7001,
help="The port the OSC server is listening on")
args = parser.parse_args()
......@@ -31,4 +31,5 @@ if __name__ == "__main__":
for index in range(len(b)):
arr[index+4] = b[index]
client.send_message("/route", [bytes(arr)])
client.send_message("/首页/全国", [0, 1])
\ No newline at end of file
client.send_message("/首页/全国", [0, 1])
client.send_message("/state", [0])
\ No newline at end of file
from flask import Flask, request, jsonify, make_response
from flask_cors import CORS
from utils_log import handler
import random
import socket
import os
import argparse
import json
import logging
from pythonosc import osc_message_builder
from pythonosc import udp_client
# localIP = socket.gethostbyname(socket.gethostname()) # 得到本地ip
localIP = '0.0.0.0'
app = Flask(__name__)
CORS(app, supports_credentials=True)
app.logger.addHandler(handler)
books = [
dict(id=1, isdn=random.randrange(1, 1000), title='a python book', author=dict(
name='l0set', city='hunan'
......@@ -96,8 +99,9 @@ def create_slider():
if(result['index'] == 2):
sendMessage([{"page": "bi"}]) # BIM
return jsonify(code=0, message='success')
@app.route('/api/ctr', methods=['POST'])
@app.route('/api/route', methods=['POST'])
def create_ctr():
app.logger.info(str(request))
# data = json.loads(request.json)
print(request.json['arguments'], len(request.json['arguments']))
# print(data)
......@@ -110,5 +114,12 @@ def create_ctr():
# sendMessage('/route',[getBigUnicode(request.json['path']), 0 ,1])
sendMessage('/route',message)
return jsonify(code=0, message='success', data = request.json)
@app.route('/api/getState', methods=['get'])
def handle_route():
with open('test.txt',mode = 'r' , encoding = "UTF-8" ) as f:
str = f.read()
f.close()
return jsonify(code=0, message='success', data = str)
if __name__ == '__main__':
app.run(host=localIP, port=8900)
# -*- coding: UTF-8 -*-
import argparse
import math
import json
......@@ -11,62 +12,6 @@ print(socket.gethostname())
# localIP = socket.gethostbyname(socket.gethostname()) # 得到本地ip
print('127.0.0.1')
def print_volume_handler(unused_addr, args, volume):
print(volume.decode('utf-8'))
print("[{0}] ~ {1}".format(args[0], volume))
def print_compute_handler(unused_addr, args, volume):
print(args)
try:
print("[{0}] ~ {1}".format(args[0], args[1](volume)))
except ValueError:
pass
def ctrLamp(id, open):
url = "http://iotadmin.bgycc.com/v2/diagnosis/device/set/"+id
payload = "{\r\n\"datapoint\":[\r\n\r\n\r\n{\r\n\"index\":0,\r\n\"value\":"+open+"\r\n\r\n}\r\n]\r\n}"
headers = {
'Content-Type': "application/json",
'Access-Token': "OTZDOEQwREZBN0Y4RjY0NUFGRkY0NzQwMUU1NjFDNjQxNUM3MEE4QzY4N0E1QjBFQTNBM0U2QzU5OUVGNENGQw=="
}
response = ''
print(response.text)
def pot1open(p):
print('pot1open')
ctrLamp('1684316145', '1')
def pot1close(p):
print('pot1close')
ctrLamp('1684316145', '0')
def pot2open(p):
print('pot2open')
ctrLamp('1684315223', '1')
def pot2close(p):
print('pot2close')
ctrLamp('1684315223', '0')
def pot3open(p):
print('pot3open')
ctrLamp('1684311829', '1')
def pot3close(p):
print('pot3close')
ctrLamp('1684311829', '0')
def goPage(p):
url = "http://127.0.0.1:8089/" + \
str(json.loads(p)['p'])+"/"+str(json.loads(p)['n'])
......@@ -76,8 +21,10 @@ def goPage(p):
def section(unused_addr, args):
print(args)
goPage(args)
print(args.decode('utf-16be'))
str = args.decode('utf-16be').replace('䉅啃', '')
with open('test.txt',mode = 'w' , encoding = "UTF-8" ) as f:
f.write(str)
......@@ -86,14 +33,14 @@ if __name__ == "__main__":
parser.add_argument("--ip",
default='127.0.0.1', help="The ip to listen on")
parser.add_argument("--port",
type=int, default=9000, help="The port to listen on")
type=int, default=7001, help="The port to listen on")
args = parser.parse_args()
dispatcher = dispatcher.Dispatcher()
# dispatcher.map("/Page", print)
# dispatcher.map("/section", print)
dispatcher.map("/待机", print)
dispatcher.map("/state", section)
print(args)
server = osc_server.ThreadingOSCUDPServer(
......
{
"ip" : "192.168.1.110",
"route" : "/首页/全国",
"volume" : 50,
"brightness" : 50,
"enableTouch" : true,
"music" : {
"isPlay" : true,
"fileIndex" : 2,
"repeat" : -1,
"volume" : 20
}
}
\ No newline at end of file
import os
import time
import logging
# log配置,实现日志自动按日期生成日志文件
def make_dir(make_dir_path):
"""
文件生成
:param make_dir_path:
:return:
"""
path = make_dir_path.strip()
if not os.path.exists( path ):
os.makedirs( path )
return path
log_dir_name = "logs"
log_file_name = 'logger-' + time.strftime( '%Y-%m-%d', time.localtime( time.time() ) ) + '.log'
log_file_folder = os.path.abspath(
os.path.join( os.path.dirname( __file__ ), os.pardir, os.pardir ) ) + os.sep + log_dir_name
make_dir( log_file_folder )
log_file_str = log_file_folder + os.sep + log_file_name
log_level = logging.INFO
handler = logging.FileHandler( log_file_str, encoding='UTF-8' )
handler.setLevel( log_level )
logging_format = logging.Formatter(
'%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s' )
handler.setFormatter( logging_format )
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment