Book Image

Raspberry Pi Android Projects

By : Gökhan Kurt
Book Image

Raspberry Pi Android Projects

By: Gökhan Kurt

Overview of this book

Table of Contents (13 chapters)
Raspberry Pi Android Projects
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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...