Open-source IoT Platform

Device management, data collection, processing and visualization
for your IoT projects
Learn about Thingsboard

Tuesday, January 3, 2017

Raspberry Pi GPIO control using Android Things and Thingsboard

Thingsboard is an open-source server-side platform that allows you to monitor and control IoT devices. It is free for both personal and commercial usage and you can deploy it anywhere. If this is your first experience with the platform we recommend to review what-is-thingsboard page and getting-started guide.

This sample application will allow you to control GPIO of your Raspberry Pi device using Thingsboard RPC widgets. We will observe GPIO control using Leds connected to the pins. The purpose of this application is to demonstrate Thingsboard RPC capabilities.

Raspberry Pi will use simple Android Things application that will connect to Thingsboard server via MQTT and listen to RPC commands. Current GPIO state and GPIO control widget is visualized using built-in customizable dashboard.

The video below demonstrates the final result of this tutorial.





Prerequisites

You will need to Thingsboard server up and running. Use either Live Demo or Installation Guide to install Thingsboard.

List of hardware and pinouts

  • Raspberry Pi - we will use Raspberry Pi 3 Model B but you can use any other model.

  • 11 Leds with corresponding resistors

  • 13 female-to-male jumper wires

Wiring schema

Since our application will allow to control state of all available GPIO pins, we recommend to attach some LEDs to those pins for visibility. You can use this basic instruction or another one to wire some LEDs. Below is sample wiring schema used in this tutorial.

image

Programming the Raspberry Pi

Flashing the Android Things image

First you need to flash Android Things image to your Raspberry Pi board using this guide. After finishing this guide make sure that your board has Internet access and accessible via adb tool.

Android Things development environment

Before starting with application introduced in this tutorial you need to prepare development environment to work with Android Things applications. Follow instructions from the official guide to build and deploy your first Android Things application.

Application source code

Now you should obtain source code of the GpioControlSample application from Thingsboard sanples GitHub repository. You can do this by issuing the following git clone command:

git clone https://github.com/thingsboard/samples

Open cloned samples folder and navigate to android-things/GpioControlSample.

Open GpioControlActivity.java file located at app/src/main/java/org/thingsboard/sample/gpiocontrol folder.

You will need to modify THINGSBOARD_HOST constant to match your Thingsboard server installation IP address or hostname. Use “demo.thingsboard.io” if you are using live demo server.

The value of ACCESS_TOKEN constant corresponds to sample Raspberry Pi device in pre-provisioned demo data. If you are using live demo server - get the access token for pre-provisioned “Raspberry Pi Demo Device”.

Running the application

Make sure that your Raspberry device is accessible via adb tool:

adb devices

Navigate to GpioControlSample application folder and deploy application to the device:

./gradlew assembleDebug
adb push ./app/build/outputs/apk/app-debug.apk /data/local/tmp/org.thingsboard.sample.gpiocontrol
adb shell pm install -r "/data/local/tmp/org.thingsboard.sample.gpiocontrol"

Or you can use other options to deploy Android application:

Finally you can start the application by issuing the following adb command:

adb shell am start -n "org.thingsboard.sample.gpiocontrol/org.thingsboard.sample.gpiocontrol.GpioControlActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

Data visualization

In order to simplify this guide we have included “Raspberry PI GPIO Demo Dashboard” to the demo data that is available in each thingboard installation. Of course, you can modify this dashboard: tune, add, delete widgets, etc. You can access this dashboard by logging in as a tenant administrator.

In case of local installation:

In case of live-demo server:

  • login: your live-demo username (email)
  • password: your live-demo password

See live-demo page for more details how to get your account.

Once logged in, open Dashboards->Raspberry PI GPIO Demo Dashboard page. You should observe demo dashboard with GPIO control and status panel for your device. Now you can switch status of GPIOs using control panel. As a result you will see LEDs status change on device and on the status panel.

Below is the screenshot of the “Raspberry PI GPIO Demo Dashboard”.

image

Next steps

Browse other samples or explore guides related to main Thingsboard features:

Your feedback

If you found this article interesting, please leave your feedback in the comments section, post questions or feature requests on the forum and “star” our project on the github in order to stay tuned for new releases and tutorials.

25 comments :

  1. Hey people! You can hire a subject professional from https://essaysrescue.com/paperrater-review/ for any type of work. Our writers specialize across all subjects and academic levels. Their profound expertise is the key to brilliant results and fast delivery. Any task is do-able with their pro help.

    ReplyDelete
  2. Hello guys! I'd like to buy interview essay. I am assigned to write this type of essay but do not have a wide experience of passing interviews. I need assistance of a professional writer.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. I really enjoyed reading your thoughts on [theme] and your article was fantastic. You offered a fresh viewpoint that caused me to reconsider the matter.Birla Trimaya Team Appreciates you

    ReplyDelete
  5. I'm happy to be able to help people know about duck life game, you should play this amazing game.

    ReplyDelete
  6. Prestige Lavender Fields Team enjoy what you guys are doing. Keep up the great work guys I've added you guys to my blogroll for your incredibly thoughtful writing and reporting. It, in my opinion, will raise the quality of my website.

    ReplyDelete
  7. Prestige Serenity Shores appreciate your support and look forward to providing you in the future with even more thought-provoking and exciting content.

    ReplyDelete
  8. Investing in Birla Trimaya
    Shettigere not only provides an excellent living experience but also offers a promising investment opportunity in one of Bangalore's rapidly developing areas.

    ReplyDelete
  9. Prestige Park Grove is a heartfelt tribute to the beauty and power of familial ties.

    ReplyDelete
  10. This blog article turns information into an engaging journey rather than only providing information. It's a pleasure to read and learn from you because of your distinctive writing style. Prestige Southern Star

    ReplyDelete
  11. Adarsh Welkin Park Hosa Road is the epitome of modern urban living, offering a luxurious lifestyle in the heart of the city.

    ReplyDelete
  12. The team at Provident Deansgate will enjoy what you do. Keep up the good work. I have added you to my blog for your wonderful and thoughtful posts and reports. I think it will improve the quality of my site.

    ReplyDelete
  13. I wanted to take a moment to express my sincere appreciation for your remarkable blog - Provident Deansgate

    ReplyDelete
  14. A comparative analysis showcasing how Sobha Neopolis Price stands out among other residential properties, emphasizing its distinctive features and advantages.

    ReplyDelete
  15. Imagine if moving your stuff could be as smooth as controlling your Raspberry Pi – that would be pretty neat! So, just like making your gadgets work together, the idea of making local moving easier and more organized sounds pretty awesome too!

    ReplyDelete
  16. Prestige Park Ridge is one of the flagship projects of Prestige Group near Bannerghatta Road, Bengaluru. Offering different housing options such as 1, 2 and 3 BHK flats, the project strives to offer best-in-class facilities to its residents.

    ReplyDelete
  17. rep shoes are very popular among users, mainly because they are cheap and the quality is the same as the original products. Topreplicas mainly targets high-end, making high-quality rep shoes, such as: jordan 4 reps, nike reps, jordans reps, etc. If you want a cheap price and have high requirements for quality, this is undoubtedly the most suitable one for you.

    ReplyDelete
  18. Elevate your ultimate style with jordans Reps shoes, topreplicas are just right for you. It has the same quality as the original at an unbeatable price.

    ReplyDelete
  19. """Natural predators can play a significant role in pest management.""" Pest Control Oakville

    ReplyDelete
  20. What a fabulous post this has been. Never seen this kind of useful post. Cat Needs Best

    ReplyDelete