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

Get Raspberry Pi Android Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.