Difference between revisions of "BluetoothLE WiFi and Raspian"

From csn
Jump to navigation Jump to search
Line 59: Line 59:
  
 
Scan on your phone, play with and try changing the values while reading: https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md
 
Scan on your phone, play with and try changing the values while reading: https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md
 +
 +
=== Challenge ===
 +
 +
The following code will report the temp of the CPU. Can you get this temperature value into the beacon:
 +
 +
<pre>
 +
import RPi.GPIO as GPIO
 +
import time
 +
import os
 +
import sys
 +
import signal
 +
import subprocess
 +
 +
temp = os.popen('vcgencmd measure_temp').readline()
 +
print temp
 +
temp= temp.replace("temp=","").replace("'C\n","")
 +
print temp
 +
 +
while True:
 +
    temp = os.popen('vcgencmd measure_temp').readline()
 +
    print temp
 +
    temp= temp.replace("temp=","").replace("'C\n","")
 +
    print temp
 +
    time.sleep(3)
 +
 +
<pre>
  
 
== Scanning for Bluetooth LE Devices ==
 
== Scanning for Bluetooth LE Devices ==

Revision as of 03:32, 22 May 2020

Sending Bluetooth LE Beacons

In this first activity, we will show you how you can craft a Bluetooth LE beacon using the Raspberry Pi.

Start by logging into your Raspberry Pi and then check that Bluez is installed:

sudo apt install bluez

We are going to use the Raspberry Pi to transmit an Eddystone beacon.

Lets look at the available commands:

hciconfig -h

Lets bring up the Bluetooth device on our Raspberry Pi using below command:

sudo hciconfig hci0 up

Then, lets set the Bluetooth interface to advertise but not be connectable:

sudo hciconfig hci0 leadv 3

Beacons containing URLs

Now we will construct and send the Bluetooth LE beacon:

sudo hcitool -i hci0 cmd 0x08 0x0008 1c 02 01 06 03 03 aa fe 14 16 aa fe 10 00 03 6D 75 72 64 6F 63 68 2E 65 64 75 2E 61 75 00 00 00
[Linux commands        ]  OFG   OCF  [Len] [Flag+L] [UUID + ? ] [TypeIF] [URL+TX] [This is the URL based Payload                    ]

This will create a Bluetooth low energy beacon that points to murdoch.edu.au

We will read this BTLE becon on our smartphone. Download and open the Bluetooth app linked to below based on your phone:

Pickup the Eddystone beacon and visit the URL.

Challenge

Go here https://www.rapidtables.com/convert/number/ascii-hex-bin-dec-converter.html and then reverse engineer the string above. You know it points to murdoch.edu.au. Can you change the hcitool string to point to your own site, or your favourite website?

Can you point it to Little Salmon Bay on Rotnest (https://www.google.com/maps/place/Little+Salmon+Bay/@-32.0333166,115.5377011,14.65z/data=!4m5!3m4!1s0x2a2d5a5442996ffd:0x9032cfa0949b90f8!8m2!3d-32.0246369!4d115.5250543)

The maximum characters that can be transmitted are 16, so you will want to look at a URL shortener like:

*https://tinyurl.com/

Please also read the following link to workout how .com is really encoded.

Beacons containing Sensor data

Try the following:

sudo hcitool -i hci0 cmd 0x08 0x0008 1c 02 01 06 03 03 aa fe 14 16 aa fe 20 00 03 01 02 03 04

Scan on your phone, play with and try changing the values while reading: https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md

Challenge

The following code will report the temp of the CPU. Can you get this temperature value into the beacon:

import RPi.GPIO as GPIO
import time
import os
import sys
import signal
import subprocess

temp = os.popen('vcgencmd measure_temp').readline()
print temp
temp= temp.replace("temp=","").replace("'C\n","")
print temp

while True:
    temp = os.popen('vcgencmd measure_temp').readline()
    print temp
    temp= temp.replace("temp=","").replace("'C\n","")
    print temp
    time.sleep(3)


Scanning for Bluetooth LE Devices

Use Bluetooth Low Energy to scan the environment around you with: hcitool -i hci0 lescan