Wednesday, April 29, 2015

A Closer Look at How Ibeacons Consume Power

A lot of people think that if its a low energy device would automatically mean the device will consume less energy and therefore, battery life will be longer. This is partially true but grossly incomplete so one can't just conclude from only one set of data. Several factors could affect the device power consumption other than its Low Energy Rating, so this is my main goal to clarify certain concerns about battery life of the ibeacon.

There are a number of factors that affect the battery life, and these are the chip itself, its firmware, the pcb design, error in the device's configuration, environmental temperature, the housing, and so on and so forth. First lets have a look at an ideal condition where the environment is perfect and predictable so that we can easily create formula at how the device can consume power. In a perfect environment we can easily say that Battery Life(in Days) =  Transmission Rate(mSeconds) * Rated Transmission Count where Rated Transmission Count = Battery Rating(in mAH) / Current Draw per Transmission where Current Draw per Transmission = Power Consumption per Transmission(in dBm converted into µWatts) / Voltage.

Sample Computation:
1) Battery Rating = 260mAH
2) Device Rated Transmission Power = -23dBm = 3.33µW(AT+POWE3)
3) Transmission Rate = 564mseconds(AT+ADVI5)
3) Voltage Applied to the iBeacon = 3.3V

Current Draw per Transmission = 3.33 µW / 3.3V = 0.1 µA (assuming that 3.3v is constant)
Rated Transmission Count = 260 mAH / 0.1 µA = 2600000
Battery Life = 564mseconds * 2600000 / 86400 = 16.97 days
The ibeacon consumes 0.18mA during sleep mode, to compute the battery life:
Total Transmission Current Draw Per Hour = 0.1 µA * 564mseconds * 3600 = 0.203mA
Using the formula from digikey:
Net Battery Life = (((260 mAH / (0.18 mA+0.203mA)) * 0.7)/24 = 13.86 days(estimate only)

Please note that Battery Rating in mAH is not actually the amount of electrical energy stored by the battery, it is the maximum current that can be drawn from the battery continuously in one hour. So we will just assume that the battery has already been fully discharged after an hour of giving off 260mA.

These formulae is based on perfect conditions, but because of some other factors that I enumerated above, these result could vary by as much as 50%(with the exception of the error in the device's configuration that could result up to 1000%)when all other factors are considered in the calculation.

I could not site a reputable link that there was indeed a scientific study to confirm my observation, it was based solely on my actual experience with electronic devices that I have worked on the past 5 years.

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.

Saturday, April 18, 2015

Using Ibeacons with Internet of Things(IoT) Devices

It's the 22nd century, it is the time when technology has improved so much that made living healthy and happy accompanied by convenience improved so much too. But there are certain issues like knowing in real time the food inventories inside the refrigerator for busy hardworking moms and dads that has yet to be addressed by technology even though these issues can be easily solved nowadays with the help of Ibeacons and Internet of Things(IoT) enabled Devices.
source:Smart Fidge

Let's have a look at the problems of storing foods and the current issues:

  1. Without proper monitoring, some foods inside the fridge gets rotten.
  2. Some of the foods even if not yet rotten, are already expired.
  3. You got surprised visits from friends or relatives.
  4. You know that your fresh milk needs to be replenished but you forgot because you are busy.
  5. Mom asked you to buy a rare vinegar but you forgot again
  6. You happen to drop by after an office hour in a huge grocery store, you are tired and exhausted and you find it too difficult to find the product that you are supposed to buy.
Here's how technology make things convenient:
  1. Get an IoT enabled refrigerator, it is a smart machine fully equipped with barcode scanners and connects to an inventory apps. You may choose to have this monitored by your personal food supplier and what they do is if they detected that you need to replenish your milk, they will either notify you and if you approve, they will instantly deliver the product to your door or you may eliminate the process of approving, and you just pay them on a monthly basis. 
  2. You found out that having a personal food supplier is too advance and that you enjoy going to the grocery to buy them by yourself but you are busy and needs some form of assistant to remind you. But luckily, grocery stores use ibeacons and they have an app that can also access the contents of the smart fridge, so if you happen to pass by the grocery, the app will instantly remind you that you need to replenish your fresh milk.
  3. Obviously, the smart fridge can detect if there are rotten or expired stocks and sends an alarm to your smart phone and  if you haven't taken any action, the grocery store or your personal food supplier can detect this and will send a reminder.
Aren't these ideas cool?