Home Source code

 

Bluetooth

 

Adruino source code below

blue.ino

Before you can run the Bluetooth app you will need to do a couple of prerequisite steps  First of all, the Bluetooth app communicates with a Bluetooth device.  In this example the Bluetooth device is HC-05 module that is connected to an Arduino.  If you do not know what an Arduino is, there are plenty of references on the web.  You will need the MAC address of HC-05 module and the only way to get this is to complete the breadboard and turn it on, unfortunately the MAC address is not written on the chip.  Then use the scan for bluetooth devices on your cell phone.  The MAC address will appear.  The MAC address is always 6 fields separated by ":".  For example  30:14:12:08:08:69  Once you have the MAC address you can change the source code of the Heximus bluetooth app.  The code to do this looks like this.  mac = "30:14:12:08:08:69"  You will also have to change the blue sketch provided on this website to match your Arduino sensors you are using.  The Heximus bluetooth app takes a slightly differenct approach to the database schema.  The database schema is defined in the Arduino blue sketch.  The heximus bluetooth app sends a query schema command to the Arduino.  The Arduino then reports back the database schema and the Heximus bluetooth app then creates the database and table if it does not already exist.  By opening a console or terminal window, you can find your new SQLite database by typing "ls *.db"   This is an industry standard SQLite database, you can copy the database to any platform that supports SQLite which is just about every platform known since SQLite is open source.

 

bluetooth.hex is the name of the Heximus source file.  blue.ino is the name of the Arduino sketch.   As you peruse the Heximus documentation you will see references to bt and hdb.  These are simply the names given to the object and are used throughout the documentation for consistency.

The Arduino reads the sensors and writes them to a circular buffer every "interval" time which is programmable with the .setInterval method.  The Heximus bluetooth application then reads the values via Bluetooth from the Arduino over to your cell phone or tablet.  This is setup with setTimer(1000 * 60 * 30,"refreshdata")  // call refreshdata label every 30 minutes , value in milliseconds The refreshdata function is called every 30 minutes in the above line.  When the data is read from the Arduino the circular buffer is cleared. There is also a peek method that reads the data without clearing the circular buffer. The blue Arduino sketch uses EEPROM to save the interval time so that in case of power failure, the Arduino will start back up with same interval time.  Now that you have the data stored on the cell phone/tablet SQLite database you can further process it.  Note that refreshdata above is simply a label/function call entry point.  You can call it anything you want.  You will just need a label in your program to match.

eg.

refreshdata:

bt.connect // connect to bluetooth

//bt.peekbuffer bb // get the data into bb, now a byte array, does not remove
bt.getbuffer bb // same as above, but removes data from arduino, bb now a byte buffer
// bb is now a packed byte buffer

// insertBuffer will decode the byte buffer using ardschema and insert new records
hdb.insertBuffer tablename, bb,ardschema  // send byte data and schema string array


bt.close // disconnect from bluetooth


return
 

You can use the Graph control to easily plot your data.  In this example the pressure which was derived by a BMP180 pressure sensor is dropping.

You can also set up a time span using the schedule control.