This program is given as a sample exercise. It has all the functionality to be used on a BLE Nano device and to connect to SimpleChat application for Android/ iOS from RebBearLab. The aim of the exercise is to read a voltage and then to convert as good as possible the appropriate temperature in Celsius degrees. AI5 pin is considered for reading the voltage for the termistor. The ADC of AI5 is called every second. The function to be updated : update_measurements() from main.cpp file.

Dependencies:   BLE_API mbed nRF51822

Fork of nRF51822_DataLogger_with_Chat by Valentin Tanasa

Files at this revision

API Documentation at this revision

Comitter:
tanasaro10
Date:
Sat Oct 08 10:30:15 2016 +0000
Parent:
11:baafa4f7a15e
Commit message:
Version ready for use to exercise.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
myData.h Show annotated file Show diff for this revision Revisions of this file
myFunctions.cpp Show annotated file Show diff for this revision Revisions of this file
read_me.md Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri May 06 18:14:18 2016 +0000
+++ b/main.cpp	Sat Oct 08 10:30:15 2016 +0000
@@ -21,17 +21,17 @@
  *    The application works with the BLEController iOS/Android App.
  *    Type something from the Terminal to send
  *    to the BLEController App or vice verse.
- *    Characteristics received from App will print on Terminal.
  *      Read read_me.md file for more informations about the extended feature
  */
 
 
 #include "ble/BLE.h"
-//#include "LowPowerTicker.h"
 #include <myData.h>
 #include <Gap.h>
-//#include "ble_flash.h"
 #include "ble_flash.c"
+#include "BatteryService.h"
+
+BLE ble;
 
 #define BLE_UUID_TXRX_SERVICE            0x0000 /**< The UUID of the Nordic UART Service. */
 #define BLE_UUID_TX_CHARACTERISTIC       0x0002 /**< The UUID of the TX Characteristic. */
@@ -41,9 +41,9 @@
 
 #define MyASSERT(cond , serialpc, errVal) assert_error_app((bool)cond, serialpc, (uint16_t)errVal, __LINE__, __FILE__)
 
-BLE  ble;
+Serial pc(USBTX, USBRX);
 
-Serial pc(USBTX, USBRX);
+uint8_t batteryLevel=100;
 
 // The Nordic UART Service
 static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
@@ -51,16 +51,20 @@
 static const uint8_t uart_rx_uuid[]   = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
 static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71};
 
-static const int8_t txPower = 0xCD;
+static const int8_t txPower = 0x1E;
+BatteryService *batteryService = NULL;
 
-uint8_t txPayload[TXRX_BUF_LEN] = {0, p28};
+uint8_t txPayload[TXRX_BUF_LEN] = {0,};
 uint8_t rxPayload[TXRX_BUF_LEN] = {0,};
+char myBuf[TXRX_BUF_LEN];
+uint16_t len;
 
 static uint8_t rx_buf[TXRX_BUF_LEN];
 static uint8_t rx_len=0;
 
 static uint32_t gTimeInstant = 1; // TimerTick Resolution, in seconds
 
+
 bool g_bIsConnected = false;
 bool g_bIsAdvertising = false;
 bool g_bConnDisabled = false;
@@ -68,22 +72,21 @@
 static myDataLog_t g_MyData;
 uint8_t g_MyDataIdx=0;
 
+
+
 // pins connected for measuring
+
 DigitalOut led(LED1);
-PwmOut buzzer(p15);
-InterruptIn event(p29); // button
-AnalogIn VP3(A3);
-AnalogIn VP4(A4);
-AnalogIn VP5(A5);
-AnalogIn* VP[3]= {&VP3,&VP4,&VP5};
-#define NUM_OF_READINGS (4u)
-myPayload_t g_currMeasures; // last measurements
+// voltage for the termic resistor
+AnalogIn Vin(A5);
+
+myPayload_t g_currMeasures2; // last measurements
 
 Timeout timeout_err; // timeout for buzz on error
 Ticker periodicActions;
-
+bool bNewSample = false;
 mdatetime_manager_t g_myDateTimeVar;
-
+uint8_t gBatteryValue=0;
 GattCharacteristic  txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
 
 GattCharacteristic  rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
@@ -92,6 +95,17 @@
 
 GattService         uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *));
 
+void at_timeout_err()
+{
+    // stop buzz
+   
+}
+
+void alarm(){
+    
+    //timeout_err.attach(&at_timeout_err, 2);
+}
+
 void sendRadioMsg(const uint8_t* buf, uint16_t length)
 {
     uint8_t retVal;
@@ -119,11 +133,6 @@
     g_bIsAdvertising = false;
 }
 
-void at_timeout_err()
-{
-    // stop buzz
-    buzz_int(&buzzer, 0,0);
-}
 void connectionUpdate(connection_update_t option)
 {
     if (g_bConnDisabled == false) {
@@ -158,9 +167,8 @@
         }
     }
 }
-void write_data_to_flash(uint32_t *tick)
+void write_data_to_flash(uint32_t *tick, myPayload_t * currMeasures)
 {
-    uint32_t retVal=0;
     uint8_t page_num=0;
 
     if (g_MyDataIdx==0) {
@@ -168,26 +176,29 @@
         connectionUpdate(eStartAdvertising);
         // time and date used to initialize the g_MyData variable
         memcpy(&g_MyData.startData.datetime,&g_myDateTimeVar.currentDateTime, sizeof(mdate_time_t));        
-        memcpy(&g_MyData.startData.data,&g_currMeasures, sizeof(myPayload_t));
+        memcpy(&g_MyData.startData.data,currMeasures, sizeof(myPayload_t));
     } else {
         // it should be logged here the time difference from last record...
         g_MyData.myData[g_MyDataIdx-1].minutes = (uint16_t)(*tick*gTimeInstant / 60);
         g_MyData.myData[g_MyDataIdx-1].seconds = (*tick*gTimeInstant% 60);
-        memcpy(&g_MyData.myData[g_MyDataIdx-1].data,&g_currMeasures, sizeof(myPayload_t));
+        memcpy(&g_MyData.myData[g_MyDataIdx-1].data,currMeasures, sizeof(myPayload_t));
     }
     *tick = 0;
 
-    if (g_MyDataIdx==(MAXBUFFER-5)) {
+    if (g_MyDataIdx==(MAXBUFFER-3)) {
         //initiate disconnection
         connectionUpdate(eDisconnect);
     }
 
     if (g_MyDataIdx == MAXBUFFER) {
         // write2Flash the current page num
+        //connectionUpdate(eDisconnect);
+        
         page_num=flash_currPage();
         // write2Flash the current page data
-        retVal=ble_flash_page_write(page_num, (uint32_t*)&(g_MyData), 251u);
-        pc.printf("retValWr: %d, Pg:%d, Min: %d \r\n",retVal, page_num,g_myDateTimeVar.currentDateTime.minutes);
+        ble_flash_page_write(page_num, (uint32_t*)&(g_MyData), 251u);
+        memset(&g_MyData,0,sizeof(myDataLog_t));
+        //pc.printf("retValWr: %d, Pg:%d, Min: %d \r\n",retVal, page_num,g_myDateTimeVar.currentDateTime.minutes);
         flash_go_nextPage();
     }
     g_MyDataIdx = (g_MyDataIdx+1)%(MAXBUFFER+1);
@@ -196,11 +207,9 @@
 
 void on_error_radioMsg()
 {
-    char myBuf[TXRX_BUF_LEN];
-
     sprintf(myBuf,"%s","WrongSyntax");
-    buzz_int(&buzzer,5,3);
-    timeout_err.attach(&at_timeout_err, 2);
+    //buzz_int(&buzzer,5,3);
+    //timeout_err.attach(&at_timeout_err, 2);
     sendRadioMsg((uint8_t*)&myBuf[0], 12);
 }
 
@@ -215,89 +224,155 @@
     memcpy((uint32_t*)&initialData, p_curr_addr, 6*sizeof(uint32_t));
     pdate = &initialData.startData.datetime;
     pc.printf("20%2d_%2d_%2d H:%2d P:%4x\r",pdate->year, pdate->month, pdate->day, pdate->hours, p_curr_addr);
-    pc.printf("%2d:%2d;%3d;%3d;%3d \r",pdate->minutes, pdate->seconds, initialData.startData.data.light, initialData.startData.data.gndV, initialData.startData.data.temp);
-    pc.printf("%2d:%2d;%3d;%3d;%3d;%2d\r",initialData.myData.minutes, initialData.myData.seconds, initialData.myData.data.light, initialData.myData.data.gndV, initialData.myData.data.temp);
+    pc.printf("%2d:%2d;%3d;%3d;%3d;\r",pdate->minutes, pdate->seconds, initialData.startData.data.x, initialData.startData.data.y, initialData.startData.data.z);
+    pc.printf("%2d:%2d;%3d;%3d;%3d;%3d\r",initialData.myData.minutes, initialData.myData.seconds, initialData.myData.data.x, initialData.myData.data.y, initialData.myData.data.z,initialData.myData.data.temp);
     p_curr_addr += 6;
 
     for (i=0; i<49; i++) {
         memcpy((uint32_t*)&dataOut, p_curr_addr, 5*sizeof(uint32_t));
-        pc.printf("%2d:%2d;%3d;%3d;%3d;%2d\r",dataOut[0].minutes, dataOut[0].seconds, dataOut[0].data.light, dataOut[0].data.gndV, dataOut[0].data.temp, i);
-        pc.printf("%2d:%2d;%3d;%3d;%3d\r",dataOut[1].minutes, dataOut[1].seconds, dataOut[1].data.light, dataOut[1].data.gndV, dataOut[1].data.temp);
+        pc.printf("%2d:%2d;%3d;%3d;%3d;%3d\r",dataOut[0].minutes, dataOut[0].seconds, dataOut[0].data.x, dataOut[0].data.y, dataOut[0].data.z,dataOut[0].data.temp);
+        pc.printf("%2d:%2d;%3d;%3d;%3d;%3d\r",dataOut[1].minutes, dataOut[1].seconds, dataOut[1].data.x, dataOut[1].data.y, dataOut[1].data.z,dataOut[1].data.temp);
         p_curr_addr += 5;
     }
 }
 
-int update_measurements()
-{
-    int retVal;
-    static myPayload_t prevMeasures=(myPayload_t) {
-        0, 0, 0, 0, 0
-    };
+int sign(int nr){
+    int retVal=0;
+    if (nr>0) retVal=1;
+    else if (nr<0) retVal=-1;
+    
+    return retVal;    
+}
+
+float read_real_value(void){
+    uint32_t wrk,reg0,reg1,reg2;
+    reg0 = NRF_ADC->ENABLE;     // save register value
+    reg1 = NRF_ADC->CONFIG;     // save register value
+    reg2 = NRF_ADC->RESULT;     // save register value
+    NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
+    NRF_ADC->CONFIG = (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos) |
+                      (ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) |
+                      (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) |
+                      (ADC_CONFIG_PSEL_Disabled << ADC_CONFIG_PSEL_Pos) |
+                      (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos);
+    NRF_ADC->EVENTS_END  = 0;
+    NRF_ADC->TASKS_START = 1;
+    while (!NRF_ADC->EVENTS_END) {;}
+    wrk = NRF_ADC->RESULT;      // 10 bit result
+    NRF_ADC->ENABLE = reg0;     // recover register value
+    NRF_ADC->CONFIG = reg1;     // recover register value
+    NRF_ADC->RESULT = reg2;     // recover register value
+    NRF_ADC->EVENTS_END  = 0;
+    return ((float)wrk / 1024 * 1.2 * 3.0);            
+}
 
-    g_currMeasures = (myPayload_t) {
-        VP[0]->read_u16(), VP[2]->read_u16(), VP[1]->read_u16(), led, 0
-    };
-    retVal = memcmp(&g_currMeasures,&prevMeasures,sizeof(myPayload_t));
-    memcpy(&prevMeasures,&g_currMeasures,sizeof(myPayload_t));
-    return retVal;
+uint8_t read100(void)
+{ 
+    float wrk_vdd, v0p= 2.7 ,v100p= 3.3;
+    wrk_vdd = read_real_value();
+    /*if (wrk_vdd <= v0p){
+        return 0;
+    } else if (wrk_vdd >= v100p){
+        led = 0;
+        return 100;        
+    } */
+    led = 1;
+    wrk_vdd = (wrk_vdd - v0p) / (v100p - v0p);
+    return (uint8_t)(wrk_vdd * 100); 
 }
 
+void update_measurements()
+{
+    uint32_t resistance;
+    int32_t tempValue;
+
+    // use Vin.read() o read the voltage from the AI5 pin    
+    // fell free to the fill code in this function ....
+    // aditionally you can declare globals variables at the begining of the file or in myData.h
+    
+    
+    
+      
+    
+    // print on the bluetooth communication the value of Temperature computed in Celsius degrees
+    sprintf(myBuf,"T:%3d.%2d;%d;\r", tempValue/100,tempValue%100,resistance);
+    len = 20;
+    sendRadioMsg((uint8_t *)myBuf, len);                                            
+}
+
+
 void at_eachInstant()
 {
     static uint32_t tick=0;
-    int retVal;
+    //const uint8_t sizeB= 3*sizeof(uint16_t);
+    //static myPayload_t prevMeasures2=(myPayload_t) { 0, 0, 0, 0};
 
     // update time
     update_time(&g_myDateTimeVar, gTimeInstant);
-
+    //sendRadioMsg("Tick\r", 5);
+    batteryService->updateBatteryLevel(read100());
     //update measurements
-    retVal = update_measurements();
-
+    if (g_bIsConnected==true){
+        update_measurements();
+    }
+    if (g_LogActive==true){       
     // if there are changes in data save
-    if ((retVal!=0)&&(g_LogActive==true)) {
-        write_data_to_flash(&tick);
+        //g_currMeasures2.temp = Temp.read_u16();
+        //if (memcmp(&prevMeasures2, &g_currMeasures2, sizeB)!=0)
+        if (bNewSample == true)
+        //if (update_measurements()==1)
+        {            
+            bNewSample = false;
+            write_data_to_flash(&tick, &g_currMeasures2);
+            //memcpy(&prevMeasures2,&g_currMeasures2,sizeB);
+            //
+            //write_data_to_flash(&tick, &g_currMeasures2);
+        }
+    tick++;
     }
-    tick++;
 }
 
+
 // Radio commands decode
 void decode(uint8_t * buffer, uint16_t length)
 {
-    uint16_t len;
-    char myBuf[TXRX_BUF_LEN];
-
     switch (buffer[0]) {
-        case 'i': {// Analog Input Read Request
+        case 'r': {// Read Operations
             switch (buffer[1]) {
                 case '0': {
                     // display all inputs
-                    sprintf(myBuf,"All:%3d,%3d,%3d,%2d", g_currMeasures.light,g_currMeasures.gndV,g_currMeasures.temp,g_currMeasures.led_on);
-                    len = 18;
+                    sprintf(myBuf,"Id1:%d,%d,%d,%d\r\n", g_currMeasures2.x,g_currMeasures2.y,g_currMeasures2.z,g_currMeasures2.temp);
+                    len = 20;
                     break;
                 }
                 case '1': {
-                    sprintf(myBuf,"Input 1 = %3d", g_currMeasures.light);
-                    len = 13;
+                    sprintf(myBuf,"Id2:%d,%d,%d\r\n", g_currMeasures2.x,g_currMeasures2.y,g_currMeasures2.z);
+                    len = 20;
                     break;
                 }
                 case '2': {
-                    sprintf(myBuf,"Input 2 = %3d", g_currMeasures.gndV);
-                    len = 13;
+                    sprintf(myBuf,"V:%2.3f\r\n", read_real_value());
+                    len = 11;
                     break;
                 }
                 case '3': {
-                    sprintf(myBuf,"Input 3 = %3d", g_currMeasures.temp);
-                    len = 13;
+                    sprintf(myBuf,"T = %3d\r\n", g_currMeasures2.temp);
+                    len = 10;
                     break;
                 }
-                case '4': {
-                    sprintf(myBuf,"Input 4 = %2d", g_currMeasures.led_on);
-                    len = 12;
+                case '4':{
+                   // sprintf(myBuf,"F1=%2d\r\n",FILTER_COEF1);
+                    len = 7;
+                    break;
+                }
+                case '5':{
+                    //sprintf(myBuf,"Acc=%2d\r\n",gAccAmp);
+                    len = 8;
                     break;
                 }
                 default: {
-                    sprintf(myBuf,"All:%3d,%3d,%3d,%2d", g_currMeasures.light,g_currMeasures.gndV,g_currMeasures.temp,g_currMeasures.led_on);
-                    len = 18;
+                    sprintf(myBuf,"Nothing \r\n");
+                    len = 10;
                     break;
                 }
             }
@@ -315,18 +390,24 @@
             }
             sendRadioMsg((uint8_t *)myBuf, len);
             break;
-        }
-        case 's': {// buzzer
-            if (((buffer[1]>'9')||(buffer[1]<'0'))||((buffer[2]>'9')||(buffer[2]<'0'))) {
-                MyASSERT(true,&pc, buffer[1]); // notify on serial interface
-                on_error_radioMsg();  // notify on radio
-                break;
-            } else {
-                buzz_int(&buzzer, (buffer[1]-'0'),(buffer[2]-'0'));
-                sprintf(myBuf,"%s:%f","S",buzzer.read());
-                len= 7;
+        }        
+        case 'i':{ // Insert data values
+            switch (buffer[1]){
+                case 'f':{                    
+                    memcpy(myBuf,&buffer[2],2);
+                    //FILTER_COEF1=atoi(myBuf); // TODO check if it is a number                                          
+                    break;
+                }
+                case 'a':{
+                    memcpy(myBuf,&buffer[2],2);
+                    //gAccAmp = atoi(myBuf);
+                    break;
+                }
+                
+                default: {
+                   // on_error_radioMsg();  // notify on radio
+                }
             }
-            sendRadioMsg((uint8_t *)myBuf, len);
             break;
         }
         case 'd':
@@ -385,13 +466,25 @@
                     len = 12;
                     sendRadioMsg((uint8_t *)myBuf, len);
                     g_LogActive = true;
+                    
                     break;
                 }
                 case '3': { // stop measuring
+                    //measureSampling.detach();
                     sprintf(myBuf,"Stop Meas");
                     len = 11;
                     sendRadioMsg((uint8_t *)myBuf, len);
                     g_LogActive = false;
+                    ble_flash_page_write(flash_currPage(), (uint32_t*)&(g_MyData), 251u);
+                    memset(&g_MyData,0,sizeof(myDataLog_t));
+                    flash_go_nextPage();
+                    break;
+                }
+                case '4':{ 
+                    break;
+                }
+                case '5':{ // read one measure
+                                    
                     break;
                 }
                 default: {
@@ -551,23 +644,29 @@
     ble.onDisconnection(disconnectionCallback);
     ble.onConnection(connectionCallback);
     ble.onDataWritten(WrittenHandler);
-    event.rise(&button);
-
+    //event.rise(&button);
+    
+    
+    //event.rise(&accInt1);
     pc.baud(19200);
     pc.printf("SimpleChat Init \r\n");
-
+    
+    //mma1 = Adafruit_MMA8451();
+    //mma2 = Adafruit_MMA8451();
+    //init_Acc();
+    
     pc.attach( uartCB , pc.RxIrq);
     // setup advertising
     ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
     ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
     ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
-                                     (const uint8_t *)"MyBleVT", sizeof("MyBleVT") - 1);
+                                     (const uint8_t *)"BleTp", sizeof("BleTp") - 1);
     ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
                                      (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid));
     //ble.accumulateAdvertisingPayload(GapAdvertisingData::TX_POWER_LEVEL,(const uint8_t *)txPower, sizeof(txPower));
     ble.setTxPower(txPower);
     // 100ms; in multiples of 0.625ms.
-    ble.setAdvertisingInterval(160);
+    ble.setAdvertisingInterval(320);
     /*
     // activate radio notifications - usefull for flashwrite
     void (*ptrFunc)(bool);
@@ -576,9 +675,12 @@
     //ble.onRadioNotification(ptrFunc);
     */
     ble.addService(uartService);
+    batteryService = new BatteryService(ble, batteryLevel);
     ble.startAdvertising();
-    pc.printf("Advertising Start \r\n");
-    periodicActions.attach(&at_eachInstant,gTimeInstant);
+    pc.printf("Advertising Start \r\n");   
+    periodicActions.attach(&at_eachInstant,gTimeInstant);    
+    gBatteryValue = read100();
+
     while(1) {
         ble.waitForEvent();
     }
--- a/myData.h	Fri May 06 18:14:18 2016 +0000
+++ b/myData.h	Sat Oct 08 10:30:15 2016 +0000
@@ -5,7 +5,7 @@
 #define MAX_WORD_PAGE_DATA 254u // to be computed as round_next_int(MAXBUFFER*sizeof(myDataL_t)+sizeof(myData_t))
 
 #define MAX_PAGE_NUM (NRF_FICR->CODESIZE - 1) // 255
-#define MIN_PAGE_NUM 155u
+#define MIN_PAGE_NUM 180u
 
 
 typedef struct{
@@ -32,11 +32,10 @@
 } connection_update_t;
 
 typedef struct {
-    uint16_t light;
-    uint16_t gndV;
+    int16_t x;
+    int16_t y;
+    int16_t z;
     uint16_t temp;
-    bool led_on;
-    bool led2_on;    
 } myPayload_t;
 
 
--- a/myFunctions.cpp	Fri May 06 18:14:18 2016 +0000
+++ b/myFunctions.cpp	Sat Oct 08 10:30:15 2016 +0000
@@ -65,9 +65,15 @@
         }
         myDateTimeVar->newDateTime.hours = (myDateTimeVar->currentDateTime.hours + (tseconds / 3600+myDateTimeVar->newDateTime.minutes/60))%24;
         if (myDateTimeVar->newDateTime.hours < myDateTimeVar->currentDateTime.hours){
-            myDateTimeVar->newDateTime.day = (myDateTimeVar->currentDateTime.day + 1)%(eNrDaysPerMonth[myDateTimeVar->currentDateTime.month+1]+1);
+            myDateTimeVar->newDateTime.day = (myDateTimeVar->currentDateTime.day + 1)%(eNrDaysPerMonth[myDateTimeVar->currentDateTime.month-1]+1);
+            if (myDateTimeVar->newDateTime.day == 0){
+                myDateTimeVar->newDateTime.day ++; 
+            }
             if (myDateTimeVar->newDateTime.day < myDateTimeVar->currentDateTime.day ){
-                myDateTimeVar->newDateTime.month = (myDateTimeVar->currentDateTime.month+ 1)%13+1;
+                myDateTimeVar->newDateTime.month = (myDateTimeVar->currentDateTime.month+ 1)%13;
+                if (myDateTimeVar->newDateTime.month ==0){
+                        myDateTimeVar->newDateTime.month++;
+                    }
                 if (myDateTimeVar->newDateTime.month< myDateTimeVar->currentDateTime.month){
                     myDateTimeVar->newDateTime.year = (myDateTimeVar->currentDateTime.year+ 1);
                 }
--- a/read_me.md	Fri May 06 18:14:18 2016 +0000
+++ b/read_me.md	Sat Oct 08 10:30:15 2016 +0000
@@ -1,7 +1,7 @@
 # nRF51822_SimpleChat Extended With Data Measurements & Logger
 This repo is derived from the initial SimpleChat Application and is build for BLE Nano Device, used in peripheral mode.
 This Application scan and measures some inputs and save them in flash with timestamp. A RTC has been implemented.
-Using chat application (available for smart phones) some commands can be send to BLE Nano in order to perform some tasks.
+Using chat application (available for smartphones) some commands can be send to BLE Nano in order to perform some tasks.
 Other types of commands can be send via serial interface from a PC, especially data extraction from flash.
 
 #Usage/Description:
@@ -28,8 +28,7 @@
 #Hardware Connections
 The BLE Nano Device is connected to some peripheral components as follows:
 * Light Sensor ( A3 input)
-* Temperature Sensor (A4 input)
-* Gnd Voltage (or anything else) (A5 input)
+* Temperature Sensor (A5 input)
 * Buzzer (D6 output)
 * Push Button (D5 input)
 [*] Optional: MKUSB 20 Board (for Voltage Supply and for Serial Communication with a PC)
@@ -38,10 +37,8 @@
 From RedBear Chat Application following messages are valid:
 * Any message that not start with 'x' is echoed with 'R:' as prefix, and also is send via Serial Interface to PC
 * Any message that start with 'x' is interpreted as command:
-    * xi0 / xi* except {1,2,3,4} => prints the analog inputs and one digital input (the led status) as uint16 values
-    * xi1 /xi2 / xi3 / xi4 =>prints the uint16 value for light, temp, gndV, led status
+      * xr1 /xr2 / xR3 / xr4 =>prints tvarious inputs
     * xl => toggle led status
-    * xs[0-9][0-9] => buzzer; depending on digits, a digital pwm signal is send to buzzer; to deactivate: xs00
     * xtg => returns the current time
     * xti[0-9]{6} => insert time - exp: xti181004 means: 18H10M and 4 seconds
     * xdg => returns the current date
@@ -61,7 +58,7 @@
     * xcs => Stop Radio Advertising (should be used when Advertising is active)
 
 Other Commands:
-    * button push => closes the connection/advertising and turn off the led. If push again reset the previous conditions;
+   
 
 # References
 The mbed BLE API is meant to be used in projects on developer.mbed.org. Please see examples and sample project files there.