Reader small image

You're reading from  Android Things Projects

Product typeBook
Published inJun 2017
Reading LevelBeginner
PublisherPackt
ISBN-139781787289246
Edition1st Edition
Languages
Right arrow
Author (1)
Francesco Azzola
Francesco Azzola
author image
Francesco Azzola

Francesco Azzola is an electronic engineer with over 15 years of experience in computer programming and JEE architecture. He is SCEA certified (Sun Certified Enterprise Architect), SCWCD, and SCJP. He is an Android and IoT enthusiast. He loves creating IoT projects using Arduino, Raspberry Pi, Android, and other platforms. He is interested in the convergence between IoT and mobile applications. Previously, he worked in the mobile development field for several years. He has created a blog called survivingwithandroid,where he shares posts about coding in Android and IoT projects.
Read more about Francesco Azzola

Right arrow

Sending data from the Android Things app


Once the client is ready, we have to call it from MainActivity.java, the class that we used to read sensor data. The easiest way to send data to Artik Cloud is invoking its API whenever the sensor reads a new value. Anyway, we have to consider the high frequency at which the sensor reads new values. This approach would require calling the Artik API almost continuously. The best approach is sending data using a scheduler. With a scheduler, the Android Things app sends data at specific time intervals without overwhelming the Artik Cloud. In this way, we can adjust the frequency having more control on the app behavior and the bandwidth the app consumes. Let us modify MainActivity.java:

  1. Add the following method to this class:
        // Scheduler to send data//
        private void initScheduler() {
          ScheduledExecutorService scheduler=
          Executors.newSingleThreadScheduledExecutor();

         scheduler.scheduleAtFixedRate(new Runnable(...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Android Things Projects
Published in: Jun 2017Publisher: PacktISBN-13: 9781787289246

Author (1)

author image
Francesco Azzola

Francesco Azzola is an electronic engineer with over 15 years of experience in computer programming and JEE architecture. He is SCEA certified (Sun Certified Enterprise Architect), SCWCD, and SCJP. He is an Android and IoT enthusiast. He loves creating IoT projects using Arduino, Raspberry Pi, Android, and other platforms. He is interested in the convergence between IoT and mobile applications. Previously, he worked in the mobile development field for several years. He has created a blog called survivingwithandroid,where he shares posts about coding in Android and IoT projects.
Read more about Francesco Azzola