App for BLE Nano to monitor the power consumption for a specific location, by intercepting the led flashes of a standard power meter. It counts and log the flashes for each second. It works with RedBear App for smart phone (Simple Chat App).
Dependencies: BLE_API lib_mma8451q mbed nRF51822
Fork of nRF51822_DataLogger_with_Chat by
read_me.md@12:27e9c3db28b9, 2016-08-14 (annotated)
- Committer:
- tanasaro10
- Date:
- Sun Aug 14 14:57:09 2016 +0000
- Revision:
- 12:27e9c3db28b9
- Parent:
- 10:c7d53e4e0602
First release for counting and logging power impulses of a power meter. Useful to track the power consumption for a specific location.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tanasaro10 | 12:27e9c3db28b9 | 1 | # nRF51822_SimpleChat Extended With Data Measurements & Logger for Power Consumption Monitoring |
tanasaro10 | 12:27e9c3db28b9 | 2 | This repo is derived from the initial SimpleChat Application and it is build for BLE Nano Device, used in peripheral mode. |
tanasaro10 | 12:27e9c3db28b9 | 3 | The aim of this app is to count the flashing red LED of a power consumption meter. |
tanasaro10 | 12:27e9c3db28b9 | 4 | This Application scan every 10 msec and measures AI port A5 to which a photoresistor is connected. Each 1 second the system save the collected data |
tanasaro10 | 12:27e9c3db28b9 | 5 | (if there is something to save) into flash with timestamp added. A RTC has been implemented. |
tanasaro10 | 12:27e9c3db28b9 | 6 | Using chat application (available for smart phones) some commands can be send to BLE Nano in order to perform some tasks. Also some real time measurement |
tanasaro10 | 12:27e9c3db28b9 | 7 | are displayed on the phone app. |
tanasaro10 | 9:303d3628986a | 8 | Other types of commands can be send via serial interface from a PC, especially data extraction from flash. |
tanasaro10 | 9:303d3628986a | 9 | |
tanasaro10 | 9:303d3628986a | 10 | #Usage/Description: |
tanasaro10 | 9:303d3628986a | 11 | After flashing or power on, the ble device will start to advertise and also its local time counter starts. While initializing, application |
tanasaro10 | 9:303d3628986a | 12 | will search through all flash pages, last data previosly written. From this pages will retrieve the last data and time available. |
tanasaro10 | 9:303d3628986a | 13 | A Timer Tick (period set to 1 second) is used for updating RTC and for data measurements. When the application starts the data will not be saved |
tanasaro10 | 12:27e9c3db28b9 | 14 | in flash until a command is given to start (xf2 + enter). When started, it is recommended after connecting to ble device to set the time and date; |
tanasaro10 | 12:27e9c3db28b9 | 15 | After the date and time updated, activate measurement logging (command: xf2 +enter). |
tanasaro10 | 9:303d3628986a | 16 | |
tanasaro10 | 12:27e9c3db28b9 | 17 | Please be aware that from time to time the connection is stopped by the application in order to perform a flash writing procedure. |
tanasaro10 | 12:27e9c3db28b9 | 18 | This is due to fact that writing to flash is safe when radio connection is off. When g_MyDataIdx is between 248..251, connection should remain closed. |
tanasaro10 | 9:303d3628986a | 19 | |
tanasaro10 | 9:303d3628986a | 20 | The Application can use somewhere around 100 flash pages (100K). This means, if data is sampled each second, the pages will start |
tanasaro10 | 12:27e9c3db28b9 | 21 | to overwrite after 251*104 seconds = 7.25 hours. Anyway the data is inserted into logger if there is a measurement different than 0. |
tanasaro10 | 12:27e9c3db28b9 | 22 | Therefore the time the flash memory can log is bigger than 7.25 hours. |
tanasaro10 | 9:303d3628986a | 23 | |
tanasaro10 | 9:303d3628986a | 24 | When retrieving the data log via serial, the format is as follows: |
tanasaro10 | 9:303d3628986a | 25 | -> page starts with: |
tanasaro10 | 9:303d3628986a | 26 | 2016_ 4_22 H: 7 => year, month, day, and hour |
tanasaro10 | 12:27e9c3db28b9 | 27 | 26:51;10;=> minutes: seconds; A5 (no info about digital inputs) |
tanasaro10 | 9:303d3628986a | 28 | -> following rows up to the next page: |
tanasaro10 | 12:27e9c3db28b9 | 29 | 0: 5;12; => minutes: seconds - time delta (time elapsed since last measurement); A5; |
tanasaro10 | 9:303d3628986a | 30 | |
tanasaro10 | 9:303d3628986a | 31 | #Hardware Connections |
tanasaro10 | 9:303d3628986a | 32 | The BLE Nano Device is connected to some peripheral components as follows: |
tanasaro10 | 12:27e9c3db28b9 | 33 | * Light Photo Sensor ( A5 input). This sensor must be placed on the top of the LED that it monitors, and must be completely covered |
tanasaro10 | 12:27e9c3db28b9 | 34 | (to avoid other light source disturbances) |
tanasaro10 | 9:303d3628986a | 35 | [*] Optional: MKUSB 20 Board (for Voltage Supply and for Serial Communication with a PC) |
tanasaro10 | 9:303d3628986a | 36 | |
tanasaro10 | 9:303d3628986a | 37 | # Supported Commands |
tanasaro10 | 9:303d3628986a | 38 | From RedBear Chat Application following messages are valid: |
tanasaro10 | 9:303d3628986a | 39 | * Any message that not start with 'x' is echoed with 'R:' as prefix, and also is send via Serial Interface to PC |
tanasaro10 | 9:303d3628986a | 40 | * Any message that start with 'x' is interpreted as command: |
tanasaro10 | 12:27e9c3db28b9 | 41 | * xr* * = {0-7} => prints some data parameters or data measurements as follows: |
tanasaro10 | 12:27e9c3db28b9 | 42 | * xr0 ->NH (last number of hits per second) and TNH (total number of hits, from the moment of Power On) |
tanasaro10 | 12:27e9c3db28b9 | 43 | * xr1 ->maxV,photoVoltage.read(),minV : Highest Voltage measured on AI5, Current Measurement of AI5 and the lowest reading. |
tanasaro10 | 12:27e9c3db28b9 | 44 | (maximum and minimum are computed at the start of BLE, until the xf2 command is given (start of collecting data). |
tanasaro10 | 12:27e9c3db28b9 | 45 | These values are used to set the median Voltage used to identify a transition from low to high and vice-versa. |
tanasaro10 | 12:27e9c3db28b9 | 46 | * xr2 -> prints the value of g_MyDataIdx (a value now between 0..251) representing the steps until a new page will be written |
tanasaro10 | 12:27e9c3db28b9 | 47 | in flash with new data; It also print the current flash page that will be written (between 151 and 255) |
tanasaro10 | 12:27e9c3db28b9 | 48 | * xr3 -> prints the voltage of the RedBear power supply (if it is on battery it will be a lower value than 3.3V). USefull to see how |
tanasaro10 | 12:27e9c3db28b9 | 49 | discharged the battery is; |
tanasaro10 | 12:27e9c3db28b9 | 50 | * xr4 -> prints the voltage of the AI5 (current photoresistor drop voltage) and the median voltage used to counter the transition from |
tanasaro10 | 12:27e9c3db28b9 | 51 | low to high and vice-versa; |
tanasaro10 | 12:27e9c3db28b9 | 52 | * xl => toggle led status (LED1, on the bottom side of the BLE Nano) |
tanasaro10 | 9:303d3628986a | 53 | * xtg => returns the current time |
tanasaro10 | 9:303d3628986a | 54 | * xti[0-9]{6} => insert time - exp: xti181004 means: 18H10M and 4 seconds |
tanasaro10 | 9:303d3628986a | 55 | * xdg => returns the current date |
tanasaro10 | 9:303d3628986a | 56 | * xdi[0-9]{6} => insert date - exp: xti160424 means: 2016 Y, 04 Month, 24 Day |
tanasaro10 | 12:27e9c3db28b9 | 57 | * xf1 => prints the value of g_MyDataIdx (a value now between 0..251) representing the steps until a new page will be written |
tanasaro10 | 12:27e9c3db28b9 | 58 | in flash with new data; It also print the current flash page that will be written (between 151 and 255) |
tanasaro10 | 12:27e9c3db28b9 | 59 | * xf2 => activate measurements logging; |
tanasaro10 | 12:27e9c3db28b9 | 60 | * xf3 => deactivate measurements logging and save the last data in the flash region; |
tanasaro10 | 12:27e9c3db28b9 | 61 | |
tanasaro10 | 12:27e9c3db28b9 | 62 | * xim => eg ximXY =>introduce a value for median Voltage. This value will be computed as median = XY/10; |
tanasaro10 | 12:27e9c3db28b9 | 63 | |
tanasaro10 | 9:303d3628986a | 64 | From PC serial interface (with MKUSB 20 Board), following commands apply: |
tanasaro10 | 9:303d3628986a | 65 | * xf[0-9] => request printing on serial of a specific flash page ( 0 - current page; 1 - previous page, etc) |
tanasaro10 | 9:303d3628986a | 66 | * xd => request dump of all recorded logs (starting with current page) |
tanasaro10 | 12:27e9c3db28b9 | 67 | * xg => prints the value of g_MyDataIdx (a value now between 0..251) representing the steps until a new page will be written |
tanasaro10 | 9:303d3628986a | 68 | in flash with new data; |
tanasaro10 | 9:303d3628986a | 69 | * xca => open Radio Advertising (should be used when the Advertising is Off) |
tanasaro10 | 9:303d3628986a | 70 | * xcc => Close Radio connection (should be used when Connection is in Connected state) |
tanasaro10 | 9:303d3628986a | 71 | * xcs => Stop Radio Advertising (should be used when Advertising is active) |
tanasaro10 | 9:303d3628986a | 72 | |
tanasaro10 | 9:303d3628986a | 73 | Other Commands: |
tanasaro10 | 12:27e9c3db28b9 | 74 | - |
tanasaro10 | 9:303d3628986a | 75 | |
tanasaro10 | 9:303d3628986a | 76 | # References |
tanasaro10 | 9:303d3628986a | 77 | The mbed BLE API is meant to be used in projects on developer.mbed.org. Please see examples and sample project files there. |
tanasaro10 | 9:303d3628986a | 78 | A good starting point are these pages: |
tanasaro10 | 9:303d3628986a | 79 | * [mbed BLE Homepage](http://developer.mbed.org/teams/Bluetooth-Low-Energy/) for all things BLE |
tanasaro10 | 9:303d3628986a | 80 | * [mbed BLE Getting Started Guide](http://developer.mbed.org/forum/team-63-Bluetooth-Low-Energy-community/topic/5262/) a wonderful primer on using BLE with mbed |
tanasaro10 | 9:303d3628986a | 81 | * [mbed BLE API page](http://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/docs/tip/) for the API in generated by doxygen |
tanasaro10 | 9:303d3628986a | 82 | |
tanasaro10 | 9:303d3628986a | 83 | For this Application: |
tanasaro10 | 9:303d3628986a | 84 | * [redBEar Ble Nano] (http://redbearlab.com/blenano/) |
tanasaro10 | 9:303d3628986a | 85 | * [Project Blog - to be updated](http://tanasaro10.blogspot.ro/) |