https://ezhome2016.wordpress.com/
An easy to set up Android app to control electronic devices connected to Iot chip PC (Like raspberry Pi) through home-WiFi.
This app essentially acts as a Client and sends control messages to the server(iot device like Raspberry Pi) via WiFi.
Get started:
Assuming that the Raspberry Pi is running on a raspbian OS with java sdk preinstalled.
-
Download or Clone the project into a directory on your desktop.
-
The Server (java - Socket Server) on the Raspberry Pi. - To recieve commands from App.
Install Pi4j Module:
- The server uses Pi4j java wrapper to control the GPIO ports on the Raspberry Pi
- Easy install Pi4j using the command : curl -s get.pi4j.com | sudo bash
- More details on : http://pi4j.com/install.html.
Note: To recieve messages from this app, your server should be configured with static ip: ip address : 192.168.0.13 Listening port : 6000
or
You can manually edit these values according to the autogenerated ip-address value on the Pi.
Compile and Run the java Server code:
- Copy the Server1.java code to the directory in Pi. (I used FileZilla)
- cd into the directory and run the following commands: pi4j --compile Server1.java pi4j --run Server1
- This will start the server at port 6000, server starts to listen for messages/requests at this port.
-
The App - (Socket Client) - To Send Commands
- Enable Debug mode in Android Device.
- Connect Android phone to the Android Studio.
- Download and run the build.gradle file
- Build and run the project.
- On success, the app will be installed in the Android device, up and running.
Note - The app assumes the server to be running at ip address : 192.168.0.13 and port : 6000.
Now we are all set to exchange messages.!!!!
- Button press on the app should display the corresponding On/ Off messages on the Pi Console.
- The gpio pin numbering used here is according to the pi4j mappings given in this link.(I use Raspberry Pi B+) http://pi4j.com/pins/model-b-plus.html
Coming up next:
- Connecting gpio to control a relay
- Timer functionality
- custom ip address