How to connect my wifi module to home router in android -
i developing app control home appliances through android phone
i have hardware on wifi module(eg. config_1) installed.at first connecting android phone hardware device wifi(config_1) setting name device(eg.test) , restarting it,
this code setting name device
new setdevicename(context).execute("http://"+confirmed_ip+"/devicename?devicename="+device_name);//calling asynctask public class setdevicename extends asynctask<string, void, string>{ context context; public setdevicename(context c) { context = c; } @override protected void onpreexecute() { super.onpreexecute(); progressdialog = new progressdialog(context); progressdialog.setmessage("setting device name..."); progressdialog.setindeterminate(true); progressdialog.setcancelable(false); progressdialog.show(); } @override protected string doinbackground(string... urls){ string responsestring=""; httpclient client = null; try { string url = urls[0]; client = new defaulthttpclient(); httpget = new httpget(url); httpresponse responseget = client.execute(get); httpentity resentityget = responseget.getentity(); if (resentityget != null) { responsestring = entityutils.tostring(resentityget); log.i("get response", responsestring.trim()); } } catch (exception e) { log.d("andro_async_error sd", "error "+e.tostring()); } log.d("andro_async_response sd", responsestring.trim()); client.getconnectionmanager().shutdown(); return responsestring.trim(); } @override protected void onpostexecute(string response) { super.onpostexecute(response); runnable progressrunnable = new runnable() { @override public void run() { progressdialog.cancel(); } }; handler pdcanceller = new handler(); pdcanceller.postdelayed(progressrunnable, 10000); progressdialog.setmessage("done"); progressdialog.dismiss(); new restartdevice(context).execute("http://"+confirmed_ip+"/wifi?ssid="+globalvalues.ssid +"&pass="+globalvalues.password+"&state="+globalvalues.con_type +"&type="+device_type); //save(); } }
this works fine .then want restart device
public class restartdevice extends asynctask<string, void, string>{ context context; public restartdevice(context c) { context = c; } @override protected void onpreexecute() { super.onpreexecute(); progressdialog = new progressdialog(context); progressdialog.setmessage("restarting device..."); progressdialog.setindeterminate(true); progressdialog.setcancelable(false); progressdialog.show(); } @override protected string doinbackground(string... urls){ string responsestring=""; httpclient client = null; try { string url = urls[0]; client = new defaulthttpclient(); httpget = new httpget(url); httpresponse restart_responseget = client.execute(get);//getting error on line httpentity restartentityget = restart_responseget.getentity(); if (restartentityget != null) { responsestring = entityutils.tostring(restartentityget); log.i("get response", responsestring.trim()); } } catch (exception e) { log.d("andro_async_error in r", "error "+e.tostring()); } log.d("andro_async_response r", responsestring.trim()); client.getconnectionmanager().shutdown(); return responsestring.trim(); } @override protected void onpostexecute(string response) { super.onpostexecute(response); runnable progressrunnable = new runnable() { @override public void run() { progressdialog.cancel(); } }; handler pdcanceller = new handler(); pdcanceller.postdelayed(progressrunnable, 10000); progressdialog.setmessage("done"); progressdialog.dismiss(); save(); } }
i calling restartdevice this
new restartdevice(context).execute("http://"+confirmed_ip+"/wifi?ssid="+ssid +"&pass="+password+"&state="+globalvalues.con_type +"&type="+device_type);
here ssid homerouter ssid , password home router password getting error in
httpresponse restart_responseget = client.execute(get);
error error
org.apache.http.nohttpresponseexception: target server failed respond
i searched lot why android : target server failed respond?
android: org.apache.http.nohttpresponseexception: target server failed respond
but none helped me..how solve ??
wiki
Comments
Post a Comment