45
Working with Sensors & Internet of Things Mobile Application Development 2016/17 Fall Mohan Liyanage [email protected] Satish Srirama [email protected] 1

Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

  • Upload
    lyminh

  • View
    241

  • Download
    3

Embed Size (px)

Citation preview

Page 1: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Working with Sensors

&

Internet of ThingsMobile Application Development 2016/17 Fall

Mohan Liyanage

[email protected]

Satish Srirama

[email protected]

1

Page 2: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Mobile sensing• More and more sensors are being incorporated

into today’s smartphones

• These sensors are enabling new applications

across a wide variety of domains, such as

healthcare, social networks, safety,

environment, etc.

Image Source -http://csce.uark.edu/~tingxiny/courses/5013sp14/reading/Lane2010SMP.pdf

2

Page 3: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

What is a Sensor ?

• A sensor is a physical or virtual object that can

sense events or changes in its environment,

and produce corresponding output

• Most of the times sensor output will be an

electrical/ optical pulse

3

Page 4: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Modern android mobile devices come

with a variety of built-in sensors • MIC

• Camera

• Temperature

• Location (GPS or Network)

• Orientation

• Accelerometer

• Proximity

• Pressure

• Light

Note: not every device has all kinds of sensors

Image Source -http://www.bosch-sensortec.com/en4

Page 5: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

The Android platform supports three

broad categories of sensors

• Motion sensors – These sensors measure acceleration forces and

rotational forces along X,Y,Z axes.

– Includes accelerometers, gravity sensors, gyroscopes, and rotational vector sensors.

• Environmental sensors – To measure various environmental parameters

• Ambient air temperature and pressure

• Illumination

• Humidity.

– Includes barometers, photometers, and thermometers, etc.

http://developer.android.com/guide/topics/sensors/sensors_overview.html#sensors-intro5

Page 6: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Categories of sensors – continued

• Position sensors

– Measure the physical position of a device

– Includes orientation sensors and magnetometers

Note: Some of these sensors are always hardware-

based (accelerometer, gyroscope, temperature ,

light, magnetometer) and some of these sensors

(gravity, linear acceleration, rotation vector )can be

either hardware-based or software-based (virtual).

6

Page 7: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Motion Sensors• Accelerometer

– Measures the acceleration force on

all three physical axes (X,Y,Z)

– Useful for monitoring device movement

like tilt, shake, rotation, or swingImage Source -http://tectrick.org/wp-

content/uploads/2014/10/What-is-an-

Accelerometer-sensor.png

Zompopo: Mobile Calendar Prediction Based on Human Activities Recognition Using the Accelerometer and Cloud

Services:Srirama, Satish Narayana, Huber Flores, and Carlos Paniagua. NGMAST IEEE, 2011 7

Page 8: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

• Gyroscope

– Measures a device's rate of rotation (angular

velocity)

– When the device is not rotating, the sensor values

will be zero

Image Source -http://www.embedds.com/connecting-gy521-gyroscope-

module-to-arduino/

Motion Sensors…

8

Page 9: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

• Magnetic Field

– Monitor changes in the earth's magnetic field on

X,Y,Z axes

– With the orientation sensor, you can determine

the position of a device

Image Source - http://gadgetstouse.com/gadget-tech/magnetic-feiled-sensor-necessity-navigation-

android-devices/10620

Position Sensors

9

Page 10: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Environmental Sensors

• Android provides four hardware-based

sensors to monitor

– Relative ambient humidity

– Illuminance

– Ambient pressure

– Ambient temperature

10

Page 11: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

• Proximity sensor

– Most proximity sensors are simply light sensors(IR)

that will detect "proximity“

– Reduce display power consumption by turning off

the LCD backlight

– Disable the touch screen to avoid accidental touch

events (the ear contact with the screen and

generating touch events while on a call)

11

Page 12: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Sensor Framework

• You can access the raw sensor data by accessing the

Android sensor framework

• Android’s sensors are controlled by external services

• The framework has provided call back to obtain

sensor dataApp SensorManager

Register Callback

Sensor Event

Sensor Event

SensorEventListener call back 12

Page 13: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Sensor Framework…• The Android sensor framework contains the following classes and

interfaces– SensorManager

• This class provides various methods for – Accessing and listing sensors

– Registering and unregistering sensor event listeners

SensorManager mSensorManager;

mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);

• ServiceManager provides access to Sensor Manager Service

– Sensor• A class representing a sensor

• Uses to create an instance of a specific sensor

Sensor mAccelerometer;

mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

13

Page 14: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

– SensorEvent• The system uses this class to create a sensor event object,

which holds information such as the sensor's type, raw sensor data, of a of a sensory event

– SensorEventListener• Provides two callback methods that receive notifications

(sensor events)

• When sensor accuracy change

public void onAccuracyChanged(Sensor sensor, int accuracy) {

// Do something here if sensor accuracy changes

}

• When sensor values changepublic void onSensorChanged(SensorEvent event) {

// Many sensors return 3 values, one for each axis.

float value1 = event.values[0];

…………….

// Do something with this sensor value.

}

14

Page 15: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

• Important : Make sure to disable any sensor when you don’t use or when the sensor activity pauses

protected void onPause() {

super.onPause();

mSensorManager.unregisterListener(this);

}

– The system will not disable sensors when the screen turns off.

– That leads to the battery will drain in a few hours

• You can register sensor listener when the activity resumed

protected void onResume() {

super.onResume();

mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);

}

15

Page 16: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Practice Identify which sensors are on the device

16

Page 17: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Reading accelerometer data

17

Page 18: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

@Override

public final void onSensorChanged(SensorEvent event) {

float x = event.values[0];

float y= event.values[1];

float z = event.values[2];

tv1.setText( "X : " +x+" Y : "+y+" Z : "+z);

}

@Override

protected void onResume() {

super.onResume();

mSensorManager.registerListener(this, mAcc,

SensorManager.SENSOR_DELAY_NORMAL);

}

@Override

protected void onPause() {

super.onPause();

mSensorManager.unregisterListener(this);

}

}

18

Page 19: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Working with the sensor simulator • Download the following files

https://www.dropbox.com/s/1g2udpvoiu2c0bc/S

ensorSimulatorSettings-2.0-rc1.apk?dl=0

https://www.dropbox.com/s/5vpjfrw8vmsq4p8/s

ensorsimulator-2.0-rc1.jar?dl=0

• Execute sensor simulator

– $ java –jar sensorsimulator-2.0-rc1.jar

19

Page 20: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

20

Page 21: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Communicate with the AVD• Install app in AVD

– adb install SensorSimulatorSettings-2.0-rc1.apk

(adb command in /android-sdk/platform-tools/)

– Set IP address in AVD

21

Page 22: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Practice

• Orientation indicator that displays the device

orientation as Left , Middle and Right

22

Page 23: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Mobile Sensing and Internet of Things

http://iotworldnews.com/2014/10/qualcomm-snaps-up-bluetooth-pioneer-csr-to-capitalise-on-iot/23

Page 24: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Internet of Things (IoT)

• International Telecommunication Union

defined IoT as

“A global infrastructure for the information

society enabling advanced services by

interconnecting (physical and virtual) things

based on existing and evolving, interoperable

information and communication technologies

”(ITU Internet report-2005)

24

Page 25: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

• European Research Cluster on the Internet of

Things defined IoT as:

“The Internet of Things allows people and

things to be connected Anytime, Anyplace, with

Anything and Anyone, ideally using Any

path/network and Any service.”

25

Page 26: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

• A thing,

– Can be a person with a heart monitor implant

– A farm animal with a biochip transponder

– An automobile that has built-in sensors

– Other natural or man-made objects

With unique identifier and the ability to

communicate over the internet without requiring

human interaction.

26

Page 27: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Why it is so important ?

• More connected devices than people

• Cisco believes the market size will be$19 trillion by 2025

27

Page 28: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Environment Protection• Great Barrier Reef in Australia

• Buoys equipped with sensors collect

biological, physical, and chemical data to

minimize and prevent reef damage

Source : Kip Compton, VP Internet of Things (IoT) Systems and Software Group The Internet of Things: What Does it Take to Make the Internet of Everything

Real? 28

Page 29: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Smart Home Scenario

Sensing as a Service Model for Smart Cities Supported by Internet of Things”, Charith Perera1, Arkady Zaslavsky, Peter Christen,

Dimitrios Georgakopoulos, TRANSACTIONS ON EMERGING TELECOMMUNICATIONS TECHNOLOGIES Trans. Emerging Tel. Tech. 2014

29

Page 30: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Smart Healthcare

• Medication in The United States

• Smart pill bottles remind patients to take their medication and records that the patient has taken the correct dosage

Source : Kip Compton, VP Internet of Things (IoT) Systems and Software Group The Internet of Things: What Does it Take to Make the Internet of Everything

Real? 30

Page 31: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Smart health

Dr. M, project KAIST31

Page 32: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Smart Agriculture• Red Tecnoparque Colombia has deployed a wireless sensors

network technology to monitor plantain crops in Lembo area, in Santa Rosa de Cabal region.

• Plantain crops has been monitored with different sensors as:– Digital Humidity & Temperature

– Soil moisture

– Soil temperature

– Trunk diameter

– Fruit diameter

– Pluviometer

– Solar radiation

• Some of the benefits :– Improving environmental and

agricultural sustainability.

– Organic waste management

– Crops traceability etc

Source : http://www.libelium.com/improving-banana-crops-production-and-agricultural-sustainability-in-colombia-using-sensor-networks/32

Page 33: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Where Mobiles can Fit?

• Most of the times IOT sensors do not have a

sufficient amount of energy and processing

power to connect directly to the internet

through Wi-Fi or mobile networks

• Especially when the sensors deploy sparsely, a

mobile device can work as a sink/relay to

collect the sensor data and upload them to

the backend servers

33

Page 34: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Mobile Sensing with Non-integrated

sensors• Mobile phones can collect data from external

sensors and upload them to the backend

servers or provide data directly to the end

users(Mobile Host)

• ZebraNet, BikeNet , urban sensing, etc.

http://www.cs.ubc.ca/~krasic/cpsc538a/summaries/29/ZebraNet.htm

http://sensorlab.cs.dartmouth.edu/news.html34

Page 35: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Arduino Sensor kit• Basic prototype board with the Arduino Mega

ADK microcontroller and the sensor shield

Microcontroller

Sensor shield 35

Page 36: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Demo-1

Reading ambient temperature

Setup

• Mega ADK microcontroller

• Bluetooth module and temperature sensor

• App to communicate with the Arduino

36

Page 37: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Bluetooth low energy(BLE) shield

Mega ADK microcontroller

& sensor shield

Android APP

37

Page 38: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

How does it work?

– Temperature sensor generates an analog signal

according to the temperature variance

– Microcontroller do the A/D conversion and

forward data to the Bluetooth module

Arduino code

38

Page 39: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

• Bluetooth module transmits data to the Android

device over the established connection

• The Android app reads data over the established BLE

connection, processed and present to the end user

39

Page 40: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Demo-2• Arduino Home Automation

– Running a small web server on the Arduino board

which provides controlling home appliances

through the Web interface

40

Page 41: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Homework 4

• Develop an Android application using Google Maps API

• You need to draw the path on the map from your residence to your current location (for example, institute of computer science -J Liivi 2). You should mark the start location(your residence ) using red marker { } with the hard corded map coordinates.

• Refer this link for more information https://developers.google.com/maps/documentation/android/start

41

Page 42: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Sample output

Submission deadline is 13 October 2016

42

Start point

(hard coded)

End point

(device GPS)

Dynamic path

Page 43: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

Home Assignment 2

• An object moves from left to right (and vice-

versa) based on the orientation of the device

43

Page 44: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

• A touch event makes the object to jump over an obstacle

• Submission deadline is 20th October 2016

44

Page 45: Working with Sensors Internet of Things - Kursused ... microcontroller and the sensor shield Microcontroller Sensor shield 35 Demo-1 Reading ambient temperature Setup • Mega ADK

References/Suggested readings

• J. Mass, C. Chang, S. N. Srirama: Workflow Model Distribution or Code Distribution? Ideal Approach for Service Composition of the Internet of Things, 13th IEEE International Conference on Services Computing (SCC 2016), June 27- July 2, 2016, pp. 649-656. IEEE.

• C. Chang, S. N. Srirama, M. Liyanage: A Service-Oriented Mobile Cloud Middleware Framework for Provisioning Mobile Sensing as a Service, The 21st IEEE International Conference on Parallel and Distributed Systems (ICPADS 2015), December 14-17, 2015, pp. 124-131. IEEE.

• C. Chang, S. N. Srirama, J. Mass: A Middleware for Discovering Proximity-based Service-Oriented Industrial Internet of Things, 12th IEEE International Conference on Services Computing (SCC 2015), June 27 - July 2, 2015, pp. 130-137. IEEE.

• C. Chang, S. Loke, H. Dong, F. Salim, S. N. Srirama, M. Liyanage, S. Ling: An Energy-Efficient Inter-organizational Wireless Sensor Data Collection Framework, The IEEE 22nd International Conference on Web Services (ICWS 2015), June 27 - July 2, 2015, pp. 639-646. IEEE.

• B. Zhou, A. Dastjerdi, R. Calheiros, S. N. Srirama, R. Buyya: A Context Sensitive Offloading Scheme for Mobile Cloud Computing Service, 8th IEEE International Conference on Cloud Computing (CLOUD 2015), June 27 - July 2, 2015, pp. 869-876. IEEE.

• M. Liyanage, C. Chang, S. N. Srirama: Lightweight Mobile Web Service Provisioning for Sensor Mediation, 4th International Conference on Mobile Services (MS 2015), June 27 - July 2, 2015, pp. 57-64. IEEE. (Won Best Paper Award)

• S. N. Srirama, A. Ostovar: Optimal Resource Provisioning for Scaling Enterprise Applications on the Cloud, The 6th IEEE International Conference on Cloud Computing Technology and Science (CloudCom-2014), December 15-18, 2014, pp. 262-271. IEEE.

• C. Chang, S. N. Srirama, S. Ling: SPiCa: A Social Private Cloud Computing Application Framework, The 13th International Conference on Mobile and Ubiquitous Multimedia (MUM 2014), November 25-28, 2014, pp. 30-39. ACM.

• J. Mass, S. N. Srirama, H. Flores, C. Chang: Proximal and Social-aware Device-to-Device Communication via Audio Detection on Cloud, The 13th International Conference on Mobile and Ubiquitous Multimedia (MUM 2014), November 25-28, 2014, pp. 143-150. ACM.

45