Reader small image

You're reading from  Raspberry Pi Android Projects

Product typeBook
Published inSep 2015
Reading LevelBeginner
Publisher
ISBN-139781785887024
Edition1st Edition
Languages
Right arrow
Author (1)
Gökhan Kurt
Gökhan Kurt
author image
Gökhan Kurt

Gkhan Kurt has been trying to keep up with the the latest developments in technology and IT in his 15-year-long development career. For the past 4 years, he has been working at IFS Labs, one of the top innovation departments of the Swedish software industry. Currently, he is involved in the Internet of Things and has been developing prototype IoT implementations using Raspberry Pi. He has a master's of science degree from Chalmers University of Technology and a bachelors degree from the Middle East Technical University. You can connect with him on Twitter and on LinkedIn.
Read more about Gökhan Kurt

Right arrow

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 page is locked
Previous PageNext Page
You have been reading a chapter from
Raspberry Pi Android Projects
Published in: Sep 2015Publisher: ISBN-13: 9781785887024

Author (1)

author image
Gökhan Kurt

Gkhan Kurt has been trying to keep up with the the latest developments in technology and IT in his 15-year-long development career. For the past 4 years, he has been working at IFS Labs, one of the top innovation departments of the Swedish software industry. Currently, he is involved in the Internet of Things and has been developing prototype IoT implementations using Raspberry Pi. He has a master's of science degree from Chalmers University of Technology and a bachelors degree from the Middle East Technical University. You can connect with him on Twitter and on LinkedIn.
Read more about Gökhan Kurt