To best understand BLE’s inner workings, you will need two phones. Let’s jump right in and begin building our app. Part 1 will focus on Server and Client setup and establishing a BLE connection. This is used to redirect the user to the MainActivity.java file.There are many resources available on Bluetooth on Android, but unfortunately many are incomplete snippets, use out-of-date concepts, or only explain half of the puzzle! In this series, we will learn how to set up both a Bluetooth Low Energy (BLE) Client and Server and demystify the Generic Attribute Profile (GATT) communication process. In the “onClick()” method you can find the “ intent2”. Then we need to add a “ setOnClickListener” to the “ ipButton”. The “ipButton” is used to access the Button from the layout file by using the ID of the button. The “setFilters” function will apply the filter to the “ ipAddress” which has entered the IP address. The “ InputFilter” is used to apply some pattern checker to check the entered string is an IP address or not. In the below code we have “ ipAddress” to take the IP address of the NodeMCU by accessing the ID of the EditText from the layout file, but we are also going to apply an additional task to check if the input text is matched to the format of an IP address or not. We need to add the following code below in the “ WifiActivityDevices.java” file. I am not going to discuss about the button as I have already discussed the button in the previous tutorials.Īs we have discussed before the WifiActivityDevices.java file is for the wifi feature. The id of the button is “ip_button” and the text of the button is “ Connect”. Now, we need to add the code for the Button. It will be shown whenever the EditText will empty. The “ android:hint” is used to give a hint to the user. You can find some height and width attributes which I have used to give a dimension to the EditText. I have given an ID to this section by using the “ attribute. The below code can be used to add an EditText in a layout. In the above image, we have an EditText which is indicating to enter the IP address. And we need to add a Button to get connected to the wifi and to redirect to the MainActivity file. Here we need to add an EditText to take the input from the user. The activity_wifi_device.xml file is the layout of the WifiActivityDevices.java file. You need to click on the “ sync” which you can see on the top right corner after adding the dependency. The highlighted code needs to be added to the adle file. This code is to give permission to the Wifi to the app. The highlighted code in the below image needs to be added to the Manifest file. In the below images, you can see that I have marked the manifest file and the adle file with a red square. And we need to add a dependency in the “ adle” file. Before we will start the coding part of the android app, we need to add few lines of code in the AndroidMenifest.xml file. The corresponding layout file that is “ activity_wifi_devices.xml” file will be created with this activity as I have mentioned in the red circle in the above image. So we need to create an activity named “ WifiActivityDevices”. I have marked those files in red in the picture below. We need to create some more classes, activities, and layouts in this tutorial. In the below image, you can see the folder structure that we have already discussed in our previous tutorials. So far now, I have just given you an overview of the application. In the below image, you can see in the toolbar section it is showing a message “ Connected to the WiFi”. When the user will press the button after entering the IP address, it will be redirected to the main activity page and the wifi will get connected. You can see the below image as a reference. When the WiFi of the user will be turned on, the user will be redirected to the wifi activity where we will add some input section to get the IP address and a connect button. If the WiFi is already turned off then the user will get a popup to turn on the WiFi, as you can see in the second image below. The user will be redirected to the Wi-Fi activity by clicking on the “WiFi”. Now let’s have a look at the image below. In the below image you can find that we have already added an image of a light bulb, a button, a toolbar, and the Bluetooth feature. Let’s see what we are going to build in this tutorial.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |