55from usr .threading import Thread , Condition
66from usr .logging import getLogger
77import sys_bus
8+ from usr .OTA_test import OTA
89
910
1011
1112logger = getLogger (__name__ )
1213
1314
15+
1416WSS_DEBUG = True
1517WSS_HOST = "wss://api.tenclass.net/xiaozhi/v1/"
1618ACCESS_TOKEN = "test-token"
@@ -65,14 +67,19 @@ def validate(request, response):
6567class WebSocketClient (object ):
6668
6769 def __init__ (self , host = WSS_HOST , debug = WSS_DEBUG ):
70+ global WSS_HOST
71+ self .ota = OTA (mac = self .get_mac_address ())
6872 self .debug = debug
69- self .host = host
73+ WSS_HOST = self .ota .run ()
74+ self .host = WSS_HOST ["websocket" ]["url" ]
7075 self .__resp_helper = RespHelper ()
7176 self .__recv_thread = None
7277 self .__audio_message_handler = None
7378 self .__json_message_handler = None
7479 self .__last_text_value = None
75-
80+ logger .info ("OTA:{}" .format (WSS_HOST ))
81+
82+
7683 def __str__ (self ):
7784 return "{}(host=\" {}\" )" .format (type (self ).__name__ , self .host )
7885
@@ -129,7 +136,7 @@ def connect(self):
129136 __client__ = ws .Client .connect (
130137 self .host ,
131138 headers = {
132- "Authorization" : "Bearer {}" .format (ACCESS_TOKEN ),
139+ "Authorization" : "Bearer {}" .format (WSS_HOST [ "websocket" ][ "token" ] ),
133140 "Protocol-Version" : PROTOCOL_VERSION ,
134141 "Device-Id" : self .get_mac_address (),
135142 "Client-Id" : self .generate_uuid ()
@@ -138,6 +145,7 @@ def connect(self):
138145 )
139146
140147 try :
148+
141149 self .__recv_thread = Thread (target = self .__recv_thread_worker )
142150 self .__recv_thread .start (stack_size = 64 )
143151 except Exception as e :
0 commit comments