Menu

AndroidSample

Jim

Android Sample

This is a sample project that runs on an Android 4.x smartphone. It reads the brightness sensor and the GPS sensor of the Android phone and sends it to the m2mlabs server.

Please Note

The server url of the m2mlabs server for this sample must be available as a public static IP adress so that the mobile phone can connect to it. If you are running your m2mlabs server behind a firewall you will have to apply port forwarding to the firewall.

To just make a test drive please send an email to support@m2mlabs.com and we send you an apikey for our public demo machine.

Create Device on M2MLabs Server

  • go to the m2mLabs admin GUI. How to create device models, sensor models and devices is described in the Tutorial
  • create a sensor model with an attribute "brightness" of type number and "gpsdata" of type GpsData
  • create a device model with a sensor "LightSensor" and a sensor "GpsSensor" using the created sensor models
  • create a device

Install on Phone

Download the sample code from http://sourceforge.net/projects/m2mlabs/files/samples/samples.zip/download

Install from Source
  • download Android Studio from http://developer.android.com/sdk/index.html and follow the installation instructions
  • using the SDK manager install API V17 for Android 4.2.2 (latest Android 4 SDK)
  • select "Import project" and then select samples/android/SensorDemo
  • select "Build->Make Project" on Android Studio main menu
  • enable "USB debugging" on your mobile phone in "Settings->Developer options"
  • connect your mobile phone with USB cable
  • select "Run->run 'app'" on Android Studio main menu
  • you can additionally start the Android device monitor with "Tools->Android->Android Device Monitor" on Android Studio main menu to view the debug output
Install from APK
  • please make sure that you have enabled "Allow installation of apps from other sources than Play Store" in "Settings->Security"
  • install samples/android/SensorDemo/SensorDemo.apk on the mobile phone, please ignore eventual warnings that it is not installed officially from the Google Play Store

Configure the SensorDemo App

  • configure server url, apikey, update rate, device name and sensors to use. The server url is either an IP address or a server name without the "http://" in front of it. Press CONFIGURE on the app main screen and enter your data. Then please close and re-open the app.
    Android Sample
  • switch on sending data by moving the "Send Data" slider on the app main screen to "on"
  • check if data was received on the m2mlabs admin GUI or run the monitor. The usage of the monitor is described in the Monitor Tutorial

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.