关于虚拟设备与Android APP数据收发
[*]情况描述
APP发送控制指令虚拟设备不响应
发送指令的回调会被调用,但是,回调的结果不对
@Override
public void didReceiveData(XPGWifiDevice device,
ConcurrentHashMap<String, Object> dataMap,
int result){
。。。
}如上所示,回调函数的3个参数里面,dataMap为空,result值为-20
经查API,-20对应的错误代码为
public static final int XPGWifiError_INVALID_PARAM -20 但是,我发送数据的格式
int GWifiDevice::write(char const*): {"entity0":{"Switch":"1"},"cmd":1}跟IOE Demo发送数据的格式
int GWifiDevice::write(char const*): {"entity0":{"Switch":"1"},"cmd":1}是完全一样的
但是,IOE Demo发送的控制指令虚拟设备完全能够正常响应
另,虚拟设备推送的数据也无法正常接收,接收到的结果值为213,我不知道这个213代表什么,我也不知道这是不是代表接收成功,但是日志的确没有像正常接收数据那样打印接收到的json格式的数据包
下面附上程序运行日志,各位大大帮帮忙看看我的问题出在哪里
[*]程序运行日志
84 matches in 83 lines for "22717" in buffer: log.txt
7:E/dalvikvm(22717): could not disable core file generation for pid 22717: Operation not permitted
39:W/xpgc (22717): 11:31:16 succeed output log to file:/sdcard/XpgAirCondition.log
41:W/linker(22717): library "libmaliinstr.so" not found
43:W/linker(22717): error:
47:W/xpgc (22717): 11:31:18 running gethostbyname(): api.gizwits.com
51:W/xpgc (22717): 11:31:18 gethostbyname api.gizwits.com success: 182.254.227.66
53:W/xpgc (22717): 11:31:18 running connect()
55:I/xpgc (22717): 11:31:18 connect to 182.254.227.66, port 80 success, fd 77
57:I/xpgc (22717):
59:W/xpgc (22717): 11:31:18 Send http head: POST /app/login HTTP/1.1
62:W/xpgc (22717): language: zh-CN
65:W/xpgc (22717): User-Agent: XPGWiFiSDK (v1.3.0.15082322)
68:W/xpgc (22717): Host: api.gizwits.com:80
71:W/xpgc (22717): Connection: keep-alive
74:W/xpgc (22717): Content-Type: application/json
77:W/xpgc (22717): X-Gizwits-Application-Id: 1837bd3c335f409ba6dba16b8dd5747c
80:W/xpgc (22717): Content-Length: 48
83:W/xpgc (22717):
86:W/xpgc (22717):
88:W/xpgc (22717):
90:W/xpgc (22717): 11:31:18 Send http body: {"username":"15077884905","password":"12345678"}
92:W/xpgc (22717):
94:I/xpgc (22717): 11:31:18 Http Content-Length or first ChunckedSize: 113
96:I/xpgc (22717):
98:W/xpgc (22717): 11:31:18 User 15077884905 login success, uid:404884c5a668434ebb552e15143a4e55, token:0e7f3a6434484597885885b0246daf71, expire_at:1441423879
100:I/xpgc (22717): 11:31:18 _recvThread() httpStruct = 0x772e5298 type = 6
102:I/xpgc (22717):
104:I/XPGWifiSDK(22717): Success callback didUserLogin, XPGWifiSDKListener != null
106:W/xpgc (22717): 11:31:18 Success Callback in>>> static void GWifiSDK::onUserLoginResp(UserLoginResp_t*) (error:0, errorMessage:)
108:W/xpgc (22717): 11:31:18 bool GWifiSDK::DiscoverDevices(): udp package send success
110:W/xpgc (22717): 11:31:18 running gethostbyname(): api.gizwits.com
114:W/xpgc (22717): 11:31:18 gethostbyname api.gizwits.com success: 182.254.227.66
116:W/xpgc (22717): 11:31:18 running connect()
118:I/xpgc (22717): 11:31:18 connect to 182.254.227.66, port 80 success, fd 77
120:I/xpgc (22717):
122:W/xpgc (22717): 11:31:18 Send http head: GET /app/bindings?show_disabled=0&limit=10000&skip=0 HTTP/1.1
125:W/xpgc (22717): language: zh-CN
128:W/xpgc (22717): User-Agent: XPGWiFiSDK (v1.3.0.15082322)
131:W/xpgc (22717): Host: api.gizwits.com:80
134:W/xpgc (22717): Connection: keep-alive
137:W/xpgc (22717): Content-Type: application/json
140:W/xpgc (22717): X-Gizwits-Application-Id: 1837bd3c335f409ba6dba16b8dd5747c
143:W/xpgc (22717): X-Gizwits-User-token: 0e7f3a6434484597885885b0246daf71
146:W/xpgc (22717): Content-Length: 0
149:W/xpgc (22717):
152:W/xpgc (22717):
154:W/xpgc (22717):
156:W/xpgc (22717): 11:31:18 Send http body: (null)
158:W/xpgc (22717):
162:I/xpgc (22717): 11:31:18 Http Content-Length or first ChunckedSize: 309
164:I/xpgc (22717):
166:W/xpgc (22717): 11:31:18 Http response: {"devices": [{"is_disabled": false, "mac": "virtual:site", "is_online": true, "host": "sandbox.gizwits.com", "port": 1883, "remark": "", "did": "i6wbbMacUrBursbzysga5i", "wifi_soft_version": null, "product_key": "03a1c94f1e35439da9341c9dd228e9fa", "is_sandbox": true, "passcode": "123456", "type": "normal"}]}
168:W/xpgc (22717):
170:W/xpgc (22717): 11:31:18 Get 1 devices from api.gizwits.com success
172:I/xpgc (22717): 11:31:18 _recvThread() httpStruct = 0x77362ef8 type = 14
174:I/xpgc (22717):
176:W/xpgc (22717): 11:31:18 Success Callback in>>> static void GWifiSDK::onGetBoundDeviesResp(GetBoundDevicesResp_t*) (error:0, errorMessage:)
178:I/xpgc (22717): 11:31:18 static void GWifiSDK::onGetBoundDeviesResp(GetBoundDevicesResp_t*): Start UnBindAllDevices
180:I/xpgc (22717): 11:31:18 static void GWifiSDK::onGetBoundDeviesResp(GetBoundDevicesResp_t*): End UnBindAllDevices
182:W/xpgc (22717): 11:31:18 bool GWifiDevice::IsBind(char const*)():760, device VIRTUAL:SITE is not bind to uid 404884c5a668434ebb552e15143a4e55, because the cache uid is empty.
184:I/xpgc (22717): 11:31:18 void GWifiSDK::MergeBindDevicesToTempDevices(): first, callback with bind list info.
186:I/xpgc (22717): 11:31:18 void GWifiSDK::DiscoverCallback(int): ==> try to push device mac:VIRTUAL:SITE, did:i6wbbMacUrBursbzysga5i, isLan:0, isOnline:1, isLogined:0, ip:, passcode: 123456 into devicelist
188:I/XPGWifiSDK(22717): Success callback didDiscovered 1 devices, XPGWifiSDKListener = com.snlion.gizwits.activity.BaseActivity$1@43625600: com.xtremeprog.xpgconnect.XPGWifiDevice@4364d620, mac: VIRTUAL:SITE
190:I/xpgc (22717): 11:31:18 void GWifiSDK::DiscoverCallback(int): (2189) Discovered 1 devices and notified UI
192:I/xpgc (22717): 11:31:18 void GWifiSDK::DiscoverCallback(int): (2190) getBoundDevices ack: 0
194:I/XPGWifiDevice(22717):setListener: com.snlion.gizwits.activity.BaseActivity$2@43625610, com.xtremeprog.xpgconnect.XPGWifiDevice@4364d620: VIRTUAL:SITE
198:I/xpgc (22717): 11:31:20 Start connecting to ip & port: 182.254.226.171:1883.
200:I/xpgc (22717): 11:31:20 ------------------------>connect elapsed: 77.000.
202:I/xpgc (22717): 11:31:20... succeed.
204:I/xpgc (22717): 11:31:20 Connected to server sandbox.gizwits.com:1883, connId: 0.
206:W/xpgc (22717): 11:31:20 xpgcLogin() clientid=usrPWnEU2aizHPXdlvMU2iq
208:W/xpgc (22717):
210:I/xpgc (22717): 11:31:20 mqtt_init_auth username:2$1837bd3c335f409ba6dba16b8dd5747c$404884c5a668434ebb552e15143a4e55 password:0e7f3a6434484597885885b0246daf71
212:W/xpgc (22717): 11:31:20 _recvThread() mqtt callback 32
214:I/xpgc (22717): 11:31:20 subscribing topic: dev2app/i6wbbMacUrBursbzysga5i
216:I/xpgc (22717): 11:31:20 topic "dev2app/i6wbbMacUrBursbzysga5i" subscribed
218:W/xpgc (22717): 11:31:20 _recvThread() mqtt callback 144
220:I/xpgc (22717): 11:31:20 void GWifiDevicePrivate::OnLogin(int): 0
222:I/XPGWifiDevice(22717): Success callback didLogin, XPGWifiDeviceListener = com.snlion.gizwits.activity.BaseActivity$2@43625610, com.xtremeprog.xpgconnect.XPGWifiDevice@4364d620: VIRTUAL:SITE
224:I/xpgc (22717): 11:31:20 int GWifiDevice::write(char const*): {"entity0":{"Switch":"1"},"cmd":1}
228:I/xpgc (22717): 11:31:24 int GWifiDevice::write(char const*): {"entity0":{"Switch":"1"},"cmd":1}
230:I/xpgc (22717): 11:31:26 int GWifiDevice::write(char const*): {"entity0":{"Switch":"1"},"cmd":1}
240:I/xpgc (22717): 11:31:28 int GWifiDevice::write(char const*): {"entity0":{"Switch":"1"},"cmd":1}
此日志的过滤条件是22717,即线程号,所以不用担心有用的信息会被过滤掉
[*]相关代码
发送数据的代码段:
if(device.isOnline()){
try{
final JSONObject jsonsend = new JSONObject();
jsonsend.put("cmd", 1);
JSONObject jsonparam = new JSONObject();
jsonparam.put("Switch", "1");
jsonsend.put("entity0", jsonparam);
device.write(jsonsend.toString());
}catch(JSONException e){
e.printStackTrace();
}
}else{
Toast.makeText(DeviceListActivity.this, "Error:Device Is Not Online !", Toast.LENGTH_SHORT).show();
}
<b></b><i></i><u></u><sub></sub><sup></sup><strike></strike>
相关回调:
@Override
public void didReceiveData(XPGWifiDevice device,
ConcurrentHashMap<String, Object> dataMap,
int result){
Message msg = Message.obtain();
//msg.obj = "Data Received Success";
if(result == -20){
msg.obj = "INVALID PARAMS";
}else{
msg.obj = "Other Error"+result;
}
msg.what = DATA_RECEIVE;
mcHandler.sendMessage(msg);
}; // end of didReceiveData
[*]PS:我的SDK是昨天升级的,升级之前是收不到这个回调的,因为我不知道SDK具体更新了什么,相关代码也不知道该修改哪里,也许这是个线索
[已解决]
本帖最后由 MalcolmC 于 2015-9-7 12:27 编辑Tom 发表于 2015-9-6 22:33
ERROR_INVALID_PARAM 出错的可能性,只有两个。一个是设备为空,一个是写入的数据为 null。看了你的原帖 ...
这才是正解!!!:victory:终于找到原因了!!!
感谢 bool GWifiDevice::IsBind(char const*)():760, device VIRTUAL:SITE is not bind to uid 404884c5a668434ebb552e15143a4e55, because the cache uid is empty.
这里,我发现了问题,但是不知道是怎么回事,字面意思是绑定没有成功,但是,isBind(uid)却通过了。。。
API里面说这个方法返回的是true或false,通过了应该是绑定成功了啊,那这句日志是怎么回事呢? v1.3.0.15082322这个版本的设备绑定有bug,下个版本已经修复,本周会发布到官网。 pomia 发表于 2015-9-1 14:43
v1.3.0.15082322这个版本的设备绑定有bug,下个版本已经修复,本周会发布到官网。 ...
终于有人回复了,而且,对这个回复,我可以表示满意么?
这个bug是造成我收发数据失败的原因么? MalcolmC 发表于 2015-9-1 15:06
终于有人回复了,而且,对这个回复,我可以表示满意么?
这个bug是造成我收发数据失败的原因么? ...
你好,帖子上提供的日志里面没有告诉我们 write 之后具体打印了什么信息,可以过滤 xpgc 的标签,然后打印出来,我可以分析一下。 MalcolmC 发表于 2015-8-31 09:48
bool GWifiDevice::IsBind(char const*)():760, device VIRTUAL:SITE is not bind to uid 404884c5a668434 ...
设备没有与这个 uid 绑定,才会有这个 log 打印。IsBind() 方法应返回 false。你说的通过了是返回 TRUE 吗? Tom 发表于 2015-9-3 20:40
你好,帖子上提供的日志里面没有告诉我们 write 之后具体打印了什么信息,可以过滤 xpgc 的标签,然后打 ...
我是过滤的进程号,意思是只要是这个程序的所有日志都在这里了,write之后没有输出什么日志,我可以肯定 Tom 发表于 2015-9-3 21:06
设备没有与这个 uid 绑定,才会有这个 log 打印。IsBind() 方法应返回 false。你说的通过了是返回 TRUE...
是的,if(isBind)....通过了的 Tom 发表于 2015-9-3 21:06
设备没有与这个 uid 绑定,才会有这个 log 打印。IsBind() 方法应返回 false。你说的通过了是返回 TRUE...
但是poima告诉我那个输出是正常的。。。 MalcolmC 发表于 2015-9-6 12:20
我是过滤的进程号,意思是只要是这个程序的所有日志都在这里了,write之后没有输出什么日志,我可以肯定 ...
ERROR_INVALID_PARAM 出错的可能性,只有两个。一个是设备为空,一个是写入的数据为 null。看了你的原帖,写入数据格式没错。那么,能登录成功,设备也不会为空。有一种情况,设备登录之后,再调用获取设备列表,这样会有问题。我想问一下,你的 app 是否是这样做的? MalcolmC 发表于 2015-9-6 12:37
但是poima告诉我那个输出是正常的。。。
虚拟设备,在当前用户能得到列表,并且包含这个设备,我们认为这个设备是已经绑定的,则 IsBind 返回 true。出现没有绑定的日志,根据源码上得出 IsBind() 一定是返回 false。 本帖最后由 Tom 于 2015-9-6 23:45 编辑
SDK 的做法是,IsBind 传入的 uid 会比对缓存的 uid 是否一致。如果一致,则为绑定成功。这个缓存的 uid,是最后一次登录、使用对应的 uid、token 获取设备列表的时候,SDK 会自动记录的一个值。 再讲细一点吧
bool GWifiDevice::IsBind(char const*)():760, device VIRTUAL:SITE is not bind to uid 404884c5a668434ebb552e15143a4e55, because the cache uid is empty.
这个日志出现的原因,是因为 SDK 缓存的 uid 是空的。出现这种情况,device.IsBind() 返回一定为 false。
页:
[1]