Is it possible to use PI4J to make an android application to control the GPIO pins of Raspberry pi?

900 views
Skip to first unread message

Abhijeet Ramgir

unread,
Jun 6, 2015, 7:30:56 AM6/6/15
to pi...@googlegroups.com
Hello,

    I'm new to PI4J and android, but I just wanted to know before I start with this idea, that is it possible to make an android application to control and listen the GPIO pins on the raspberry pi through the internet with PI4J?

   Any help would be appreciated!

Thanks,
Abhijeet.

Robert Savage

unread,
Jun 6, 2015, 7:57:05 AM6/6/15
to pi...@googlegroups.com, abhijee...@gmail.com
Yes you can use Pi4J on the Raspberry Pi to control the GPIO directly.  However, Pi4J does not provide any remote transport capabilities, you would have to add that to allow your Android app to communicate with the RPi.  

In a 2014 Devoxx talk, I demonstrated a sample project that uses MQTT to communicate between the RPi and an Android app..  Both the Android app and Pi sample source code can be found here:  http://www.savagehomeautomation.com/devoxx

Another option would be to use a project like webiopi which provides a REST based interface to control GPIO remotely.  


Thanks, Robert

Abhijeet Ramgir

unread,
Jun 6, 2015, 8:00:57 AM6/6/15
to pi...@googlegroups.com, abhijee...@gmail.com
Hello Robert Savage ,

  Thanks for the reply, is it possible to read the state of the GPIO pin using webiopi, and other than making a webapp, is it possible to make a native android app to communicate with Webiopi  using the REST client, or should i just modify the UI and make WEBAPP?

Thanks a ton!
Abhiojeet.

Sergey Shlykovich

unread,
Aug 5, 2015, 12:51:38 PM8/5/15
to Pi4J
Yes. You can control your RaspberryPi remotely using client for Android: https://play.google.com/store/apps/details?id=com.alisa.lswitch

It requires you to install small server on your device: https://github.com/sshlyk/switch-server

I am working on adding details instructions on http://www.instructables.com/

Sergey Shlykovich

unread,
Aug 5, 2015, 5:07:51 PM8/5/15
to Pi4J

Robert Savage

unread,
Aug 6, 2015, 8:06:43 AM8/6/15
to Pi4J
Abhijeet,

Pi4J itself just allows your Java code to communicate with the hardware.  You have yo add your own code to expose it over the network.

However, last year I gave a talk at Devoxx where I demonstrated using Pi4J and a Raspberry Pi to communicate sensor data via MQTT over the network to both a JavaFx application and an Android app on a mobile device. 

Check out this page for the slides and links:

The following projects are the ones I am talking about.
If you like the MQTT route, you may also want to check out the node-red project. (http://nodered.org/)
With node-red you can install on a Pi and visually wire up (via the web gui) GPIOs to MQTT topics. This could eliminate you having to write any code on the Pi. ;-)
Reply all
Reply to author
Forward
0 new messages