Raspberry Pi Android App communication by Laurens-Wuyts on May 12, 2015 Table of

print
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/

 

 

 

Raspberry Pi Android App communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Intro: Raspberry Pi Android App communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Step 1: Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Step 2: Software for the computers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Step 3: Software Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Step 4: Creating the database using phpmyadmin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Step 5: Server side scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Step 6: Writing an app (Layout) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Step 7: Writing an app (Java code) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Step 8: Resume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

 

http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
technology workshop craft home food play outside costumes
Raspberry Pi Android App communication
by Laurens-Wuyts on May 12, 2015
Table of Contents
Raspberry Pi Android App communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Intro: Raspberry Pi Android App communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Step 1: Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Step 2: Software for the computers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Step 3: Software Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Step 4: Creating the database using phpmyadmin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Step 5: Server side scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Step 6: Writing an app (Layout) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Step 7: Writing an app (Java code) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Step 8: Resume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
Author:Laurens-Wuyts laurens.ddns.net
twitter: @Laurens_Wuyts
Intro: Raspberry Pi Android App communication
Hello everyone
Because app’s are being used almost everywhere, I decided to make my own tutorial on how to make an app and connect to a MySQL database hosted on a raspberry
pi.
For exchanging the data between the server and the client, I’m going to use JSON.
Step 1: Parts
For this instructables you’ll need several things.
An android phone or the emulator from android studio
A raspberry pi (I tried B and 2B)
An internet connection with port 80 forwarded to the IP of your Raspberry Pi (How to forward port 80?)
you can do it without forwarding, but then it’s only going to work inside your network
A computer (I’m running windows 8.1. But ,as mentioned in the comments, you can also use mac or linux)
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
Step 2: Software for the computers
For this instructables you’ll need android studio from Google.
Step 3: Software Raspberry Pi
I’m assuming you already have a running Raspberry Pi with raspbian. Otherwise: How to set up a raspbian?.
For the Raspberry Pi you’ll also need software. As server I’m using:
Apache 2
PHP
MySQL
PHPMyadmin (Not needed but recommended)
To install apache 2, PHP and MySQL I used this tutorial.
To install PHPmyadmin I used this tutorial.
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
Step 4: Creating the database using phpmyadmin
First open a web-browser and go to:
IP_RPi/phpmyadmin
Login to phpmyadmin
Click Databases
Create new database: Parts
Press create.
Open the database Parts.
Create new table Parts with 3 fields.
Press Start
First column:
column: ID
Type: INT
Auto increment: v
Second column:
column: Name
Type: VARCHAR
Length: 30
Third column:
column: part_nr
Type: INT
Press Save
Step 5: Server side scripting
On the Raspberry Pi we’ll need 4 files. You need to place them in the www directory of your raspberry pi:
UPDATE: On raspbian Jessie, you have to put them in /var/www/html
db_config.php
db_connect.php
db_create.php
db_view.php
The db_config file is used for storing the username, password and database name
The db_connect file is used to connect to the database specified in the db_config file.
The db_create file is used to create a row in the table in the connected database.
The db_view file is used to get all data stored in the database.
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
Step 6: Writing an app (Layout)
In this step I’ll explain how to make a simple app using android studio.
Here we will make the layout of the app and in the next step I’ll explain how to make the app working and how to communicate with the raspberry pi server.
So first start Android Studio.
Give your app a name and choose the directory to place it. Press Next.
Choose which devices you would like to support. I’m using phones starting from android 4.0.3.
After that you need to choose the activity. Choose: “Blank Activity”.
Let the last screen as it is.
After all these steps, you get an example “hello world” app.
In activity_main.xml remove the textview element at the right bar.
In values/strings.xml remove:
Hello world!
Go back to main_activity.xml
Drag a linear layout (vertical) to the top left corner of the screen.
Drag 2 text fields to the screen. The first one plaintext and the other one Number.
At the right scroll down untill you see “id”.
Change this for the first one to Name and for the second one to part_nr.
At the right scroll down untill you see “hint”.
Change this for the first one to Name and for the second one to Part Number.
Now drag a button onto the screen and change “text” to Send.
Now is the layout done.
You can test the app by connecting your phone to your computer and compiling the app.(The green arrow a the top)
This will take a while.
It should look something like the last image.
Up to the coding of the app.
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
File Downloads
activity_main.xml (1 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to ‘activity_main.xml’]
activity_confirm.xml (667 bytes)
[NOTE: When saving, if you see .tmp as the file ext, rename it to ‘activity_confirm.xml’]
Step 7: Writing an app (Java code)
For making an app work, you don’t only need a layout. You also need the code running in the background.
The language we are going to use is Java, because all android apps are written in Java. So lets start coding.
First of all, you need to download the attached file.
This file is a library so you can easily use JSON.
Place this file in:
directiory/app_name/app/src/main/java/company/app_name/JSONParser.java
For me it’s:
C :/Users/Laurens1/Desktop/instructables/Instructables/app/src/main/java/Laurens_wuyts/Instructables/JSONParser.java
After that you can open JSONParser in android studio. You now need to change the first line to:
package company.app_name;
Ok now we can start writing the main code.
Open the file MainActivity.java
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
First make a new Progress-dialog. This is used to display when the code is executing and you need to wait.
Place this in the main class.
private ProgressDialog pDialog;
Then we need a JSONparser object to send the data. So place this line under the previous line:
JSONParser jsonParser = new JSONParser();
Now we need two EditText items, so we can extrude the inserted text. This goes under the JSONParser.
EditText editText;
EditText editText2;
We move on to the oncreate function. Here we need to link the EditTexts from above with the real edittexts in the layout. You do it like this:
editText = (EditText) findViewById(R.id.Name);
editText2 = (EditText) findViewById(R.id.part_nr);
At the end we need to create a new class for connecting to the server and sending the previous typed info.
This is the class Create_part:
class Create_Part extends AsyncTask {
@Override protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage(“Sending part to the database…”); //Set the message for the loading window
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show(); //Place the loading message on the screen
}
@Override protected String doInBackground(String… args) {
String String_name = editText.getText().toString(); //Get the inserted text from the editText files
String Int_Part = editText2.getText().toString();
List params = new ArrayList<>();
params.add(new BasicNameValuePair(“Name”, String_name)); //Add the parameters to an array
params.add(new BasicNameValuePair(“part_nr”, Int_Part));
// Do the HTTP POST Request with the JSON parameters
// Change “RaspberryPi_IP to your home IP address or Noip service
JSONObject json = jsonParser.makeHttpRequest(“RaspberryPi_IP/db_create.php”, “POST”, params);
try {
int success = json.getInt(“success”);
if(success == 1){
Intent i = new Intent(getApplicationContext(), ConfirmActivity.class);
// Open a new activity to confirm it was sent. We’re going to create it later.
startActivity(i);
finish();
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url){
pDialog.dismiss(); // Close the loading window when ready
}
}
Now you can make a new function called Send. In this function you call Create_Part. Like so:
public void Send(View view) {
new Create_Part().execute();
}
In the activity_main.xml you now change the onclick action of the button on the right to:
Send
Ok your almost done, now you only need to make a new activity like you see in the image.
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
Change the activity name to: ConfirmActivity
Click Finish
Now go again to strings.xml and change the “hello_world” string from Hello World! to The part was created.
Now it should be done.
Rebuild the app and test it on your phone!
File Downloads
JSONParser.java (3 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to ‘JSONParser.java’]
MainActivity.java (3 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to ‘MainActivity.java’]
ConfirmActivity.java (1 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to ‘ConfirmActivity.java’]
Step 8: Resume
In this instructables we saw how to make a basic android app and connect it to a php mysql server.
I’m going to make a video for this tutorial, but now I don’t have time for it.
If you have questions/remarks please share them and I will see if I can answer them.
Thank you very much for following this instructables.
Laurens Wuyts
P.S. Please be kind, it’s my first instructables.
Related Instructables
Setting Up
Apache
WebServer on
Raspberry Pi by
WearGenius
Control
Raspberry pi
GPIO using an
app by Laurens-
Wuyts
Simple and
intuitive web
interface for
your Raspberry
Pi by
TheFreeElectron
SEND SMS
TCPIP
GATEWAY –
PHP, PYTHON
and MySQL with
RPI and a-gsm
shield by Dragos
Iosub
Raspberry Pi
simple blog
server. by
Computothought
Hottub / Pool
Controller Web
interface by
Rickiewickie
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
Advertisements
Comments
50 comments Add Comment view all 134 comments
FM Guru says: Aug 25, 2016. 11:11 AM REPLY
Ok so as a novice I have a question. Are you aware of a way to use the RasPi3 and control it with and Android Bluetooth app?
I have a very long story why I need this but it seems you may know the answer why I can’t find the answer. It involves using the RasPi as a media center.
Then dedicating a tablet to be the one paired device that controls it. Still use wifi to load media, just limit simple controls to Bluetooth.
Do you think it’s doable?
Laurens-Wuyts says: Aug 25, 2016. 12:11 PM REPLY
I think it’s doable.
I have an app, which can communicate with a HC-05 module over Bluetooth.
I think that if you configure the on-board Bluetooth using rfcomm, you should be able to use the same app (back end communication). Or you could use a
HC-05 module to the GPIO pins.
If you want the app, you can send me a private message with your email address and I’ll mail it to you.
After you received the data, you would need some kind of code/software to change the data to your controls.
Laurens
FM Guru says: Aug 25, 2016. 6:23 PM REPLY
Thanks Laurens. How do I contact you with a private message?
(Instructibles rookie)
Laurens-Wuyts says: Aug 25, 2016. 9:00 PM REPLY
Click on my name and press the ‘private message’ button.
Laurens
SaadB14 says: Jul 23, 2016. 12:27 AM REPLY
we have to communicate raspbeery pi with android.
which protocol should we use?
Laurens-Wuyts says: Jul 23, 2016. 1:24 AM REPLY
It depends. Do you want to communicate over internet or bluetooth.
As you’re commenting here, I assume you want to communicate over internet.
There are different methods to do this, but I think it easiest to use a webserver on the raspberry pi and use POST/GET requests to send your data.
Laurens
john_franz says: Aug 3, 2016. 3:00 PM REPLY
bluetooth sir?,, pls really need help to interface it offline
SaadB14 says: Jul 24, 2016. 8:41 AM REPLY
we want to communicate with android
our supervisor told us to search on protocol
which is being used to communicate between android and raspberry pi
Laurens-Wuyts says: Jul 24, 2016. 11:02 AM REPLY
The protocol I used in this instructables is HTTP.
In this protocol you have 2 types: UDP and TCP, I used TCP.
Laurens
SaadB14 says: Jul 28, 2016. 7:23 AM REPLY
ok
UDP or TCP also works if we communicate these two over wifi?
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
Laurens-Wuyts says: Jul 28, 2016. 8:26 AM REPLY
Yes, this protocol is a standard for internet communication, so WiFi, ethernet, ethernet over USB, etc.
Laurens
SaadB14 says: Jul 30, 2016. 7:26 AM REPLY
thank u soo much man
Ibshar Ishrat says: Jun 19, 2016. 12:17 PM REPLY
You have done a great job. I am new to Android Studio. I am getting this error that I should use the gettext method in the UI thread. Moreover, I am using
android sdk 23. The packages org.apache.http have been deprecated but I have followed a link and added android {useLibrary org.apache.http.legacy} in
build.gradle file which has fixed many errors. I’ll be waiting for your reply. Thanks in advance.•
Laurens-Wuyts says: Jun 19, 2016. 2:15 PM REPLY
I’m glad you liked it.
Have a look here. There is a suggestion that should work.
PS. I’m working on an updated instructables, which solves the deprecated issue.
Laurens
Ibshar Ishrat says: Jun 20, 2016. 5:30 AM REPLY
But there is another problem when I enter http://192.168.xx.xx/db_create.php I get an error that the requested url is not found on the server. Although
I have checked that the files are located in the www folder of my Raspberry pi .
Laurens-Wuyts says: Jun 20, 2016. 6:24 AM REPLY
Can you access the index page?
Can you look in /var/log/apache2/error.log and see if you can locate the error?
Laurens
Ibshar Ishrat says: Jun 20, 2016. 11:17 AM REPLY
Yes I can access phpmyadmin/index.php . Here is the error in error.log
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
Ibshar Ishrat says: Jun 20, 2016. 12:44 PM REPLY
Got it I think I have to move the files in the html folder isn’t it?
Laurens-Wuyts says: Jun 20, 2016. 1:33 PM REPLY
Yes, that’s true, that’s because you are running Raspbian Jessie and I was running raspbian Wheezy.
Laurens
Ibshar Ishrat says: Jul 1, 2016. 2:39 PM REPLY
Hello! I have another question. What changes would I have to make in application in order to GET data from server in app instead
of POST it?
Ibshar Ishrat says: Jun 22, 2016. 8:40 AM REPLY
Thank you Laurens. Your timely responses are appreciable.
Ibshar Ishrat says: Jun 20, 2016. 5:18 AM REPLY
Thank you once again that issue is solved 🙂
Ali AlAali says: Jun 25, 2016. 4:44 AM REPLY
Hey Laurens,
very impressive project you got here. i would to ask you what JSON library did you use, because i found several libraries in the link you referred to in the
beginning of the tutorial
thanks
Ali AlAali says: Jun 25, 2016. 5:32 AM REPLY
Oh never mind, i thought downloadable items were images. thanks
hodamadin says: Jun 13, 2016. 4:41 AM REPLY
Why this error:
Error:Execution failed for task ‘:app:processDebugResources’.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command
‘C:\Users\hoda\AppData\Local\Android\Sdk\build-tools\23.0.3\aapt.exe” finished with non-zero exit value 1
Laurens-Wuyts says: Jun 13, 2016. 5:16 AM REPLY
Where are you getting these error’s? When you build the app, or when you run the app?
The theme error is because the theme you want to use is not available.
The other one, I can’t say from the top of my head.
Laurens
hodamadin says: Jun 13, 2016. 4:45 AM REPLY
Why this Error:
Error: Error retrieving parent for item: No resource found that matches the given name ‘Theme.Leanback’.
UsefE says: Jun 9, 2016. 9:03 AM REPLY
Nice Bro (y)
Laurens-Wuyts says: Jun 9, 2016. 9:09 AM REPLY
Thanks! I’m glad you liked it.
Laurens
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
BhanaviS says: May 28, 2016. 4:38 AM REPLY
Hey Laurens, I tried the instructables. It was nice and to the point. However, like many other users who have mentioned it, my android app “unfortunately
stopped” too. Can you help me with this?
the screenshots of the logcat is –
Laurens-Wuyts says: May 28, 2016. 8:06 AM REPLY
Hello
I’m glad you liked it.
What have you put into: here –v
jsonParser.makeHttpRequest(” “, “POST”, params);
Have you added the internet permission to the manifest?
Laurens
BhanaviS says: May 30, 2016. 1:39 AM REPLY
In the jsonParser.make….. I added (“http://10.XXX.XXX.XXX/db_create.php”, “POST”, params);
Also I added the internet permission. The app runs successfully now. However, no data is reflected in the parts database. Might there be any problem
with my php files?
Laurens-Wuyts says: May 30, 2016. 2:47 AM REPLY
Yes it could be.
Can you on the server go to ‘var/log/apache2/access.log’ and see if you’re phone is listed here (IP address)?
Laurens
BhanaviS says: May 30, 2016. 11:01 AM REPLY
I rectified whichever errors I could find in the php scripts.
The logcat says- E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb2f7ad50
And the acess log lists my emulator’s ip address but says- Apache-HttpClient/UNAVAILABLE (java 1.4)
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
Laurens-Wuyts says: May 30, 2016. 11:15 AM REPLY
The logcat error is most likely an android error.
And the name from the access log is the standard name.
Can you check /var/log/apache2/error.log and see if there are any error’s in there?
Laurens
BhanaviS says: May 30, 2016. 1:19 PM REPLY
Nope. No error. I am trying to run the app on a lollipop emulator to see if it works. I searched for the logcat error and it says that only
marshmallow apis show the error.
Laurens-Wuyts says: May 30, 2016. 11:50 PM REPLY
I don’t think this error is the real cause.
Can you send me your php page?
Laurens
BhanaviS says: May 31, 2016. 6:45 AM REPLY
I think so too. The logcat in the verbose mode shows
result: {“success”:0,”message”:”Required field(s) is missing”}
BhanaviS says: May 31, 2016. 6:53 AM REPLY
I mailed you the php file. And I really appreciate all the help you are providing. 🙂
BhanaviS says: May 31, 2016. 3:12 PM REPLY
WORKED! Apparently, my default directory for the web server was /var/www/http rather tha var/www. Thank you so
much for your time and effort! I really really appreciate that. 🙂
mjd1290 says: May 16, 2016. 6:51 PM REPLY
I really appreciate your responses and all insight!
I managed to get this working! Something must’ve been incorrect in my .php files. I originally wrote the files myself, as writing the code helps me understand
what it’s actually doing. However, writing code in a nano editor almost seems like a fool’s errand, as it is not an IDE and won’t yell at you when you’ve done
something stupid (haha).
I copied & pasted your .php files, restarted the server, and voila!! My app’s no longer crashing and instead indicates success, and when I verify in
phpMyAdmin, sure enough there’s the part!
Thanks again for all of your help, and for making this instructables! It was incredibly informative, I learned a lot, and had fun troubleshooting my issues.
Moving on to your instructables regarding control of the GPIO bus from my Android!
A+
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
mjd1290 says: May 15, 2016. 10:35 AM REPLY
Greetings Laurens,
I’ve completed the steps in this ‘instructables’, and I’m going through the troubleshooting phase at this point. I seem to be able to communicate with my
Raspberry PI, which is good. The problem I’m having is every time I hit the following call in JSONParser:
HttpResponse httpResponse = httpClient.execute(httpPost);
it returns the entire .php file, as opposed to an encoded JSON object of the $response array. I’m looking into this further, however I’m just wondering if you
could provide any insight.
Thanks in advance!
Laurens-Wuyts says: May 15, 2016. 1:42 PM REPLY
Hello
I think it has something to do with php. I think it’s not installed or not correctly started.
Laurens
mjd1290 says: May 15, 2016. 3:46 PM REPLY
So I at least figured out part of my problem:
in each of my .php files, the beginning tag was <? php (white space included) vs. <?php (white space not included). This put me one step forward,
only now I’m not receiving any content at all from the server.
In JSONParser.makeHttpRequest(), in the (“POST”) part of the if statement:
HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent();
the InputStream object (is) is receiving zero content. So when I reach the code where the StringBuilder is built, my ‘json’ String object winds up being
empty.
Any ideas on why I wouldn’t be receiving any content? Apologies for the 21 questions. This is just a very interesting tutorial and I’d love to get it
working. I feel like I’m really close.
Laurens-Wuyts says: May 15, 2016. 11:35 PM REPLY
I’m glad you liked the tutorial.
I’m not sure what the exact issue is here, but what do you get when you go to the IP address of the server in your browser?
Laurens
tokero72 says: May 9, 2016. 10:40 AM REPLY
Hello Laurens,
I put Android SO on my Raspberry and I am creating an app that can communicate with other devices via the UART ports. I ‘m using java code to perform
this part created for linux that use for the conexion dev /ttyama0 file.
What would be the equivalent file in a raspberry android? or how I can access the GPIO ports using Android Studio?
Thanks
crazy22 says: Apr 7, 2016. 10:08 PM REPLY
waiting for reply
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
moexmania says: Apr 20, 2016. 7:39 AM REPLY
you can change the IP adress in your MainActivity in the line
JSONObject json = jsonParser.makeHttpRequest(“RaspberryPi_IP/db_create.php”, “POST”, params);
Instead of RaspberryPI_IP, you need to insert the IP adress
crazy22 says: Apr 7, 2016. 10:07 PM REPLY
hello
please ignore previous screenshot….because it is not clear.
I am attaching two screenshots:
Point No:1. logcat window when I am connecting my phone to computer
Point No:2.logcat window when I am sending inputs from my application through my phone
Note: second and third screenshots are for point No.2.
crazy22 says: Apr 7, 2016. 9:48 PM REPLY
hi Laurens
This is the image of logact when I am connecting my phone to computer..
still getting error….
I don’t know how to change ip address in app???
http://www.instructables.com/id/Raspberry-Pi-Android-App-communication/
view all 134 comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.