Friday 31 October 2014

Android App to connect to Thingspeak

Hi, everyone. Few days back we learned how we can upload data to Thingspeak cloud IoT platform. But it is very tedious job to every time open the web browser and insert command or data. So today we will develop an android app that will do it for us. It is recommended that you go through the Thingspeak documentation first. Ok so let's get started.


What you need

  • Laptop or PC with internet connection.
  • Thingspeak account.
  • Android smartphone.
  • Google account.

What is this APP thing?

In this tutorial we will make use of the Thingspeak Apps. You may ask what is this App. It is nothing but services provided by Thingspeak to communicate with your devices. These apps can be accessed by POST, GET, PUT and DELETE HTTP requests. You can check out my previous post on how to make an HTTP request to upload data to your Thingspeak Channel. In this tutorial we will make use of the following Thingspeak Apps.
  • Talkback - This App is used to control your device based on some decision made on the basis of your sensor data in your channel. Using this app you can store commands which your device may fetch at regular intervals or when an event occurs to execute.
  • React - This is a decision making App. We can use this app to trigger an event based on your Thingspeak data channel. The field on which decision is to be made can be String, Location or Numeric data. There are a whole lot of logic that you can execute based on the data. In this project I will use my android app to get my current GPS location and upload it to my channel based on which an event will be triggered. 
  • ThingHTTP - This App is used to do an HTTP request from within Thingspeak. So we can use this App to trigger our Talkback App in turn to update the commands.

Getting the Idea

What I am trying to do here is that I will develop an Android app that will POST my current location to my Thingspeak channel which will trigger some logic in the React App. This App will in turn call the ThingHTTP App to send a PUT request to my Talkback App and update the current command. This command will be fetched by my device on regular interval to perfom some action. The last part will not be covered in this post. I will cover it in my next post.

Setting up Thingspeak

It is assumed that you already have a Thingspeak channel set up. If not follow my previous post.
Before moving on please read the documentation each of this App so that you have a better understanding of how they work.
  • Open your Thingspeak account and click on the Apps tab.
 
  • You will get your Apps menu. Now click on Talkback App.
 
  • Now click on "New Talkback".
  • Now Fill in the Name and select your channel and set a default command by clicking add new command. For now we will add "CLOSE".

  • Now again click on the Apps tab and go to the "ThingHTTP" App.
  • Now click on "New ThingHTTP" and fill  up like this and save your ThingHTTP.


  • Now create another ThingHTTP App for closing. Like this.
 
  • Now click on App and now go to the React App.
  • Click on :"New React" and fill up like this. Save your React App.
 
  • Now create another React App in similar manner for closing like this.
 
  • While doing all the above steps give the parameters carefully like latitude, longitude,api_key etc. specific to your Apps.
  • Now you are ready to go. Lets create the Android App.

Setting up App Inventor 2

Since you are developing an app for android it is already assumed that you have a google account. Now go to the website http://ai2.appinventor.mit.edu. Use your google account to log in and create a new project. App Inventor is an online development platform for creating android apps without any knowledge of programming. It is based on graphical block development. You only need to arranged the required blocks just like a puzzle. Follow the getting started guide to have a clear understanding.
  • After you have opened App Inventor 2 and created a project bring the following objects to the canvas. Check this image to get a list.
 
  • Change the Button1 Text to Turn OFF and the Button2 Text to Turn ON
  • Change the Web1 url to https://api.thingspeak.com/talkbacks/<your Talkback ID>/commands/<your command ID> 
  • Change the Web2 url to https://api.thingspeak.com/update
  • Change the Clock1 Time interval to 10000.
  • Change LocationSensor1 Time interval to 10000.

  • Now click on "Blocks" on the top left corner of your screen.
  • If you have gone through the Getting started portion then you will be familiar with the blocks. So arrange the blocks as shown below.
 
  • Replace Web1.PutText api_key to your Talkback API_Key.
 
  • Replace Web2.PostText api_key to your Channel API_Key.



  • Now click on "Build"->"App(save .apk to my Computer)". It will download the file to your PC. Transfer the file to your android phone and install the app.

Running the Apps

  • Now turn ON you GPS and WiFi/Data connection.
 
  • Now open the Talkback App on your Thingspeak account. You will find the default command as CLOSE.
 
  • Now open the app in your android phone and wait for sometime untill the location is displayed.
 
  • Now refresh the Talkback page. If you are at or near the location you specified in your React App, the command will automatically change to OPEN. You can also manually TURN ON/OFF using the buttons provided.
 

What will you Make?

Isn't it awesome? Now you can automatically pre-cool your room when you are close to your home or you can turn the room lights ON or OFF using the app. There are limitless possibilities of things that you can connect and control through the internet using simple tools like Thingspeak, App Inventor etc. Please keep me posted about your projects and if you are facing any difficulty in understanding the instructions please let me know through the comments. In our next post we will see how we can make our devices fetch these commands at regular intervals and perform certain tasks. Till then keep making and if you like my post please share and +1 me on google.

86 comments:

  1. Hi! I just wanna do autowatering system. How I can start watering with buttons start/stop

    ReplyDelete
  2. In your android app create a button which will send POST request to update the commands in the talkback app. On the controller side use GET requests to execute those commands. One command can be executed only once. Check out this page for more info. https://thingspeak.com/docs/talkback

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

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

    ReplyDelete
  5. hi, Sounak
    Thank you for showing your project.
    I could learn thingspeak app by you too.
    Now talkback app's version was changed and it did not become to return a response about OPEN & CLOSE as status on its app.

    If possible, Advice me with something.
    I want to get a response and the status on thingspeak's Channel and android app(app inventor).
    Thank you.

    ReplyDelete
  6. i cant acces my thingspeak talkback using this app to add a new command, inorder to add a talkback command. what i have to do?????

    ReplyDelete
  7. is there any video tutorials explaining more about talkback,react and thinghttp ??

    ReplyDelete
  8. Hii thanks for showing that....I actually want to get a graph from the thingspeak to Android app......can you help me with that please!!!!

    ReplyDelete
    Replies
    1. Hi,

      You can do an HTTP request to thingspeak to get your past data. Refer to Thingspeak documentation for that. After that you can use some graph plotting APIs like Plotly to get some graphs.

      Delete
  9. how can i login thingspeak user account in my own android app?

    ReplyDelete
    Replies
    1. Hi Jatin,

      Everything in Thingspeak works through HTTP requests. Every profile will have it's unique API key which allows you to use all the features of thingspeak.

      Delete
  10. Hey! I wanna send a command from my android app to control some ports on my development board, how can I do it?

    ReplyDelete
    Replies
    1. hey bro!
      I also want to do the same but even above project is not working , when I run my app it always pop-up an error "wrong no. of argument for posts" would u please help. any help is appreciable.

      Delete
  11. https://play.google.com/store/apps/details?id=aarsoftronix.thingspeak


    Best app for thingspeak work

    ReplyDelete
    Replies
    1. That is cool. At the time I wrote this blog I think this app was not there.

      Delete
  12. https://play.google.com/store/apps/details?id=comaarsoftronix.facebook.ihome

    Best for esp8266 work

    ReplyDelete
  13. You can still use this applications to track someones location.

    ReplyDelete
  14. Hi,
    Sorry guys I was out of touch from this blog for 2 years. I couldn't reply to most of your comments. But now I am planning to continue the blog with some new projects.

    ReplyDelete
  15. Hi,thanks for this tutorial,can this be done in android studio?

    ReplyDelete
  16. I have ESP8266 connected to DHT22. I see Temperature and Humidity on Thingspeak, both Private or Public. All I want to do now is control a relay from my Android cell phone. It would be great to see a step by step and comments from someone. I really do want to learn, but finding it really tough.

    ReplyDelete
  17. hi,how do i notify my android when some changes occur in the threshold level which is an matlab output

    ReplyDelete
  18. if you try renaming the master file, like the way some people did on gaana app, it won't play.  download

    ReplyDelete
  19. But how can I get data from thingspeak...I am facing problem in that part. Can u guide us?

    ReplyDelete
  20. that's awesome! Am having some difficulties with my project, that is building an app that will be able to track my wearable tracking device.

    ReplyDelete
  21. sir i just need send or post mobile gps data to thingspeak.can you explain me? sir.

    ReplyDelete
  22. tutuapp is the best app to download any kind of paid app free of charge. tutuapp android pokemon go game is the most famous game in the world and you can download it free of charge. Not only pokemon go app you can download any kind of apps free of charge.

    ReplyDelete
  23. You are doing a great job. You inspire me to write for other. Thank you very much. I would like to appreciate your work for good accuracy and got informative knowledge from here... Embedded System Training in Chennai
    Embedded System Training Institute in Chennai

    ReplyDelete
  24. install kodi firestick app using above link and unlock the features of it. all updates are free of charge.

    ReplyDelete
  25. This information is impressive; I am inspired by your post writing style & how continuously you describe this topic. Embedded System Training in Chennai
    Embedded System Training Institute in Chennai

    ReplyDelete
  26. I have recently started a blog, the info you provide on this site has helped me greatly. Thanks for all of your time & work.
    How to create an app

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

    ReplyDelete
  28. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..

    rpa training in Chennai | rpa training in pune

    rpa online training | rpa training in bangalore

    ReplyDelete
  29. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    Data Science training in Chennai | Data science training in bangalore
    Data science training in pune| Data science online training
    Pyton training in Kalyan nagar

    ReplyDelete
  30. After reading your post I understood that last week was with full of surprises and happiness for you. Congratz! Even though the website is work related, you can update small events in your life and share your happiness with us too.
    java training in omr | oracle training in chennai

    java training in annanagar | java training in chennai

    ReplyDelete
  31. I likable the posts and offbeat format you've got here! I’d wish many thanks for sharing your expertise and also the time it took to post!!
    python training Course in chennai
    python training in Bangalore
    Python training institute in kalyan nagar

    ReplyDelete
  32. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.
    health and safrety courses in chennai

    ReplyDelete
  33. I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post. Hats off to you! The information that you have provided is very helpful.
    date analytics certification training courses
    data science courses training

    ReplyDelete
  34. I just couldn't leave your website before telling you that I truly enjoyed the top quality info you present to your visitors? Will be back again frequently to check up on new posts.
    AI learning course malaysia

    ReplyDelete

  35. I was just browsing through the internet looking for some information and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject. Bookmarked this page, will come back for more.

    Data Science Course

    ReplyDelete
  36. After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.Data Science Courses

    ReplyDelete
  37. Thanks for sharing great info with us.

    I wanted to write a little comment to support you and wish you a good continuation All the best for all your blogging efforts.Your good knowledge and kindness in playing with all the pieces were very useful.
    data science course in pune

    ReplyDelete
  38. Two full thumbs up for this magneficent article of yours. I've really enjoyed reading this article today and I think this might be one of the best article that I've read yet. Please, keep this work going on in the same quality.for more info:
    https://360digitmg.com/course/certification-program-on-big-data-with-hadoop-spark
    https://360digitmg.com/course/machine-learning-using-python-r
    https://360digitmg.com/course/artificial-intelligence-ai-and-deep-learning

    ReplyDelete


  39. Great post.I really liked you article,your writing style is simply awesome with useful information. Best python certification course in Bangalore is offering Python training with 100% Placement assistance.Get certification under certified experts

    ReplyDelete
  40. I truly love this post..
    Thanks for sharing with us,
    We are again come on your website,
    Thanks and good day,
    Please visit our site,
    buylogo

    ReplyDelete
  41. This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.

    Datascience training in chennai

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

    ReplyDelete
  43. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
    Data-Analytics training in hyderabad

    ReplyDelete
  44. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!

    Data-science online course in Chenna

    ReplyDelete
  45. Cool stuff you have and you keep overhaul every one of us

    Simple Linear Regression

    ReplyDelete
  46. Great post i must say and thanks for the information.
    Data Science Course in Hyderabad

    ReplyDelete
  47. very well explained. I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Correlation vs Covariance
    Simple Linear Regression
    data science interview questions
    KNN Algorithm
    Logistic Regression explained

    ReplyDelete
  48. wonderful article. I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries. data science courses

    ReplyDelete
  49. You should be a piece of a challenge for probably the best website on the web. I will suggest this site!
    live

    ReplyDelete
  50. Wow such an amazing content keep it up. I have bookmarked your page to check out more informative content here.

    SASVBA Provides Best Deep Learning Course in Delhi with Latest Development Environment and Frameworks. We keep Our Courses Up to Date with the Latest industrial trends. SASVBA Is One of the best training Deep Learning Institute in Delhi NCR Which Helps Students to Crack Interviews in Tech Giants. We train college students as well as school students.

    FOR MORE IMFO:

    ReplyDelete
  51. Hey everyone.
    We are giving you the big best offer to buy logo design for your business with 80% off I expect You will be happy with us.Logo Designers

    ReplyDelete
  52. this is really great content thanks for sharing with us keep sharing more helpful content like this...!
    are you guys have an interest in web designing or logo designing then visit us?
    Logo Designers

    ReplyDelete
  53. Data Science Training in Pune

    Thanks for this content you have shared, very useful.

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

    ReplyDelete
  55. Nice blog. Informative and knowledgeable content. Big thumbs up for this blog. I really enjoyed this blog. Thank you for sharing with us.
    Data Science Course Training Institute in Hyderabad

    ReplyDelete
  56. Very awesome!!! When I seek for this I found this website at the top of all blogs in search engine. data science course in surat

    ReplyDelete
  57. Hi! This is my first visit to your blog! We are a team of volunteers and new initiatives in the same niche. Blog gave us useful information to work. You have done an amazing job!

    satta

    satta matta matka

    ReplyDelete
  58. Wonderful blog. I am delighted in perusing your articles. This is genuinely an incredible pursuit for me. I have bookmarked it and I am anticipating perusing new articles. Keep doing awesome!
    data analytics courses in hyderabad with placements

    ReplyDelete
  59. This instruction is quite beneficial! Developing an Android app that can connect with Thingspeak Apps appears to be a game changer for IoT projects. I'm looking forward to your next post detailing the remaining phases. Thank you for your contribution! 🚀📱
    Data Analytics Courses in India

    ReplyDelete
  60. The author brilliantly explains how to create an Android app to interact with Thingspeak for IoT control. This informative and well-structured guide encourages creativity in IoT projects.
    Data Analytics Courses In Dubai

    ReplyDelete

  61. I found the post to be highly good. The shared information are greatly appreciated
    Regards
    Dubai water Delivery

    ReplyDelete
  62. This advice is really helpful! It appears that creating an Android app that can link with Thingspeak Apps will revolutionise IoT applications. I anticipate reading about the remaining phases in your upcoming post. I appreciate your contribution.
    Data Analytics Courses in Agra

    ReplyDelete
  63. nice blog
    Data Analytics Courses In Vadodara

    ReplyDelete
  64. The blog is comprehensive tutorial for Android App to connect to Thingspeak thanks for sharing informative blog post.
    Digital Marketing Courses in Italy

    ReplyDelete
  65. Thank you for sharing! I always appreciate engaging with such high-quality content that offers valuable insights. The presented ideas are not only excellent but also remarkably innovative, adding a cool and enjoyable touch to the post. Keep up the fantastic work.
    Visit: Financial Data Analytics: Risk Management and Investment Strategies

    ReplyDelete
  66. Connecting an Android app to ThingSpeak for data is a smart move. Using ThingSpeak's API provides seamless integration for real-time data visualization and analytics. Ensure a user-friendly interface. great work.
    Data analytics framework

    ReplyDelete