Mobile bluetooth control relay Wireless Door lock Internet of things Android source code Android development Android WiFi control detailed comment test stability no bug

Source: Internet
Author: User

First, the function:

1.Android WiFi connection and disconnect, save the connection IP and port.

2.WIFI Control of 3 relays

3.16 Binary send instructions, can be sent single and multiple, separated by commas.

4.16 Binary Receive

If you need special features can find me custom ( program source code, custom expert Mobile: 18910620895 Wang Wang: chenhao0568 qq:345139427).

Second, the source code is as follows:

Login Login.java

Package Com.example.eeeee;import Java.io.inputstream;import Java.io.outputstream;import java.net.InetAddress; Import Java.net.socket;import android.os.bundle;import Android.os.handler;import Android.os.message;import Android.annotation.suppresslint;import Android.app.activity;import Android.view.view;import Android.widget.Button ; Import Android.widget.checkbox;import Android.widget.edittext;import Android.widget.toast;import Android.content.intent;import Android.content.sharedpreferences;import Android.content.SharedPreferences.Editor; @SuppressLint ("Newapi") public class Login<e, K, v> extends Activity {public static Socket msocket;public static Inpu TStream ips;public static OutputStream ops;//private final String debug_tag = "Mysocketact";p rivate string ip;private stri  ng port;//private ImageButton but7=null;private EditText serverip = null;private EditText serverport = null;private Button    Btn_login = Null;private CheckBox remember; @Override protected void OnCreate (Bundle savEdinstancestate) {super.oncreate (savedinstancestate);               Super.setcontentview (R.layout.login); The "Login" page-------------------------------------------------------------------------------------------this.      ServerIP = (EditText) Super.findviewbyid (R.ID.ET_IP); This.      ServerPort = (EditText) Super.findviewbyid (R.id.et_port);      Btn_login = (Button) This.findviewbyid (R.id.btn_login);      Remember = (CheckBox) This.findviewbyid (R.id.cb_remember);       Loadipport (); Event @Overridepublic loading IP address and port Btn_login.setonclicklistener (new View.onclicklistener () {//Press login button) void OnClick (View arg0) {//TODO auto-generated method Stub//fault tolerance judgment IP = Serverip.gettext (). toString (). Trim ();p ort = S Erverport.gettext (). toString (). Trim (); Serverip.requestfocus (), if (Ip==null|ip.trim () Equals ("")) Serverip.seterror ("Please enter the IP address!").                "); if (Port==null|port.trim (). Equals ("")) Serverport.seterror ("Please enter the port number!                ");            Else    {Connect ();             } return;}); } public void Saveipport ()//Save IP address and port {sharedpreferences uistate = getsharedpreferences ("RS485 C Ontroller ", mode_private); Editor Et=uistate.edit (); et.putstring ("IP", Serverip.gettext (). toString ());  Et.putstring ("Port", Serverport.gettext (). toString ());    Et.commit ();  } public void Loadipport ()//Load IP address and port {sharedpreferences uistate = getsharedpreferences ("RS485    Controller ", mode_private);    Serverip.settext (uistate.getstring ("IP", "192.168.1.180"));     Serverport.settext (uistate.getstring ("Port", "8899")); } public void Connect () {Toast.maketext (login.this, "Connected ...", Toast.length_short). Show (); New Thread (New Runnable () { @Overridepublic void Run () {try {msocket = new Socket (Inetaddress.getbyname (IP), Integer.parseint (port));//Msocket =new Socket ("192.168.1.180", 8899); ops = Msocket.getoutputstream (); IPs =msocket.getinputstream ();} catch (ExceptiOn e) {e.printstacktrace ();} finally {}handler.sendmessage (Handler.obtainmessage ());}}). Start ();} Message processing queue private Handler Handler = new Handler (new Handler.callback () {@Override public boolean handlemessage (Me Ssage msg) {if (Msocket = = null) {Toast.maketext (login.this, "Connection failed, please re-login!", Toast.length_short). Show ();} else{ Toast.maketext (Login.this, "connected successfully!", Toast.length_short). Show ();             if (remember.ischecked ()) {Saveipport ();}                                         Save IP address and port Intent intent = new intent (); Intent.setclass (Login.this,relay.class); startactivity (intent);   Go to login page//finish ();        } return false; }});}




First:





Mobile bluetooth control relay Wireless Door lock Internet of things Android source code Android development Android WiFi control detailed comment test stability no bug

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.