Showing posts with label raspberry pi. Show all posts
Showing posts with label raspberry pi. Show all posts

Wednesday, April 29, 2015

Configuring the Ibeacon to Detect other BLE(Bluetooth 4.0) Devices with Raspberry Pi and Python

The Ibeacon from Ziruz Technologies is not just simply an Ibeacon, it can also be configured to detect other Bluetooth Low Energy(BLE) devices. And more recently, one AT command has been added to make the Ibeacon detect other Ibeacons, but the HM10 module will need a firmware upgrade so that the new command will be available for use.

We can use the previous setup we used in my previous article(Configuring Ibeacons using Raspberry Pi B+ and Python) so that all we need to do is create a python program. And here is the python program I used to scan other BLE devices:
import serial
import time
port = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=3.0)
port.write("AT+RENEW")
rcv = port.readline() 
print rcv
rcv = ""
port.write("AT+RESET")
rcv = port.readline() 
print rcv
rcv = ""
port.write("AT+ROLE1")
rcv = port.readline() 
print rcv
rcv = ""
port.write("AT+IMME1")
rcv = port.readline() 
print rcv
rcv = ""
port.write("AT+SHOW1")
rcv = port.readline() 
print rcv
rcv = ""
while True:
    port.write("AT+DISC")
    rcv = port.readline() 
    print rcv
    rcv = ""
    time.sleep(10)

The AT+DISC will scan all BLE devices and will just return the MAC address, the newest firmware version has the command AT+DISI? and this command will return the UUID, RSSI, Major, Minor, Measured Power and the MAC Address. The command AT+DISI? is available with firmware version V539, to check the version of the firmware use AT+VERS?

If your current Ibeacon does not support the latest version, you can update the firmware by following this procedure.

Sunday, April 19, 2015

Configuring Ibeacons using Raspberry Pi B+ and Python

CP2104 Module is the perfect way not only to configure the ibeacons by connecting it to the usb port as described in my previous post (How to connect Ibeacon V2.0 to a PC with CP2104 USB 2.0 to TTL Converter) but can also be used to check the battery charge level of the ibeacon's battery as well by checking the brightness of the led on the module while the ibeacon is connected. But I have run out of stock and these modules are not readily available, so once they're gone, they're gone. But I have learned that the raspberry pi which is a small pc and can be used like an arduino can be an excellent substitute. Raspberry is readily available so configuring the ibeacon should not be a problem.

Here's how to use the raspberry to configure the Ibeacon:
1. The Connection. Connect the ibeacon module(HM10) to the UART/Serial port of the raspberry pi, see illustration below:

2. Raspberry Pi Set-up. The raspberry pi will still need to be set up because by default, the uart port serves as another gateway for controlling the computer remotely, so all bootup sequences and messages are being transmitted on the port, but all we need is to configure the  uart port to configure the ibeacon so we will need to eliminate this unwanted data. Here is how to do it:
  1. Modify the file /boot/cmdline.txt by removing console keyword related to the serial port. Typically the file looks like this: "
    dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 ....". Just remove the part in bold letters.
  2. The next step is to modify the file /etc/inittab by commenting the line "
    T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100". You could just add "#" at the beginning of the line.

    Restart the raspberry pi
Further reading:  RPi Serial Connection

3. The Python Code.  And finally we are ready to configure the ibeacon. I used the following python code to achieve this:
import serial

port = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=3.0)

while True:
    port.write("AT+RENEW")
    rcv = port.readline() 
    print rcv
    rcv = ""
    port.write("AT+RESET")
    rcv = port.readline() 
    print rcv
    rcv = ""
    ....
 Just follow the rest of the configuration process as described below:

 

for more detailed instructions you may check this website .

The ibeacon should respond to every command sent by the python program.