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

Sending the reboot command from your Android phone to the Pi


Until now, we have been receiving data from the Pi through BLE. Now, we will send commands to it using the same channel. We will implement a new write characteristic in the same service as our temperature and humidity read characteristics are, which were defined on the Pi. Using these new characteristics, we will send the reboot command to the Pi. Let's begin by editing the sensor.go file again and put the following code at the end of it:

s.AddCharacteristic(gatt.MustParseUUID("41fac9e0-c111-11e3-9246- 0002a5d5c51b")).HandleWriteFunc(
  func(r gatt.Request, data []byte) (status byte) {
   log.Println("Command received")
   exec.Command("sh", "-c", "sudo reboot").Output()
   return gatt.StatusSuccess
 })

Build and restart the BLE server using the following commands:

cd /home/pi/gopath/src/github.com/paypal/gatt
go build examples/server.go
sudo ./server

Now, test the characteristics mentioned previously using the BLE Scanner app. Whenever...

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