Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Raspberry Pi Android Projects

You're reading from   Raspberry Pi Android Projects Create exciting projects by connecting the Raspberry Pi to your Android phone

Arrow left icon
Product type Paperback
Published in Sep 2015
Publisher
ISBN-13 9781785887024
Length 138 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Gökhan Kurt Gökhan Kurt
Author Profile Icon Gökhan Kurt
Gökhan Kurt
Arrow right icon
View More author details
Toc

Adding a sensor service to Bluetooth Low Energy


We will add a new service to the already existing example from Gatt. This new service will publish two new characteristics to begin with: one for humidity and the other for temperature measurements. We will read the measurements the same way using the techniques we've discussed in Chapter 2, Server Management with Pi. To read these measurements, we will create two new files with content similar to the sense.py file that we discussed Chapter 2, Server Management with Pi. Let's create two files under the home directory, and name them humidity.py and temperature.py. The temperature.py file has the following content:

#!/usr/bin/python

import sys
import Adafruit_DHT

humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, 4)
print str(temperature)

The humidity.py file has similar content. The only difference is that it prints out the humidity part of the measurement instead of the temperature:

#!/usr/bin/python

import sys
import Adafruit_DHT...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image