Olimexino Nano and SIM800H shield problem

Started by proton43, May 09, 2018, 06:57:04 PM

Previous topic - Next topic

proton43

Hello,
I am experiencing some problems with olimexino nano serial communication. I just can't properly receive at command response. I must send AT+CCLK? and receive line by line the response. When the current line has been processed, I just overwrite it in the array with the next one. I get this answer +CCLK: "YY/MM/DD.HH:MM:SS+TT" and TT is timezone correction, which I will not use and read. I have this code that in a very modified form worked before, but now I want it to read line and process it, then the next one.

Source code:
const long interval = 1000;
static long currentMillis;

byte searchcharpos = 0; //To determine where is the + in +CCLK in the char array

char serialdata[256]; //Array to store the chars before parsing

char rtcy1[3]; //Current year  Format: yy\0
char rtcm1[3]; //Current month  Format: mm\0
char rtcd1[3]; //Current day  Format: dd\0
char rtch1[3]; //Current hour  Format: hh\0
char rtcmm1[3]; //Current minute  Format: mm\0
char rtcs1[3]; //Current second  Format: ss\0

byte pointingfinger = 0;

char enabledtime = 0;

void setup() {
 Serial.begin(9600); //USB to Computer
 Serial1.begin(9600); //UART to Modem
 Serial1.print("ATE0\r"); //Disable echo
}

void loop() {
 delay(1000);
 if (enabledtime == 1) {
   if (Serial1.available () > 0) {

     
     
     if (serialdata[pointingfinger] == '+') {
       if (serialdata[pointingfinger + 1] == 'C' && serialdata[pointingfinger + 2] == 'C' && serialdata[pointingfinger + 3] == 'L' && serialdata[pointingfinger + 4] == 'K') {
         searchcharpos = pointingfinger;
       }
     }

     if (serialdata[pointingfinger] == '\n') {
       /*for (byte a = 0; a < 255; a = a + 1 ) {
         serialdata[a] = 0;
       }*/
       pointingfinger = 0;
       enabledtime = 0;
     }

     if (serialdata[pointingfinger] == '\r') {
       pointingfinger = 0;
       enabledtime = 0;
     }
serialdata[pointingfinger] = Serial1.read();
     serialdata[pointingfinger + 1] = 0;
     pointingfinger++;
   }
 }
 if (millis() - currentMillis >= interval) //This is done every second
 {
   Serial1.print("AT+CCLK?\r");
   rtcy1[0] = serialdata[searchcharpos + 8]; //getting first char with its offset
   rtcy1[1] = serialdata[searchcharpos + 9];
   rtcy1[2] = '\0';
   rtcm1[0] = serialdata[searchcharpos + 11];
   rtcm1[1] = serialdata[searchcharpos + 12];
   rtcm1[2] = '\0';
   rtcd1[0] = serialdata[searchcharpos + 14];
   rtcd1[1] = serialdata[searchcharpos + 15];
   rtcd1[2] = '\0';
   rtch1[0] = serialdata[searchcharpos + 17];
   rtch1[1] = serialdata[searchcharpos + 18];
   rtch1[2] = '\0';
   rtcmm1[0] = serialdata[searchcharpos + 20];
   rtcmm1[1] = serialdata[searchcharpos + 21];
   rtcmm1[2] = '\0';
   rtcs1[0] = serialdata[searchcharpos + 23];
   rtcs1[1] = serialdata[searchcharpos + 24];
   rtcs1[2] = '\0';
   Serial.println("=========");
   Serial.print(serialdata[searchcharpos]); //previously I had a for loop here, but I thought it was messing with the algorithm
   Serial.print(serialdata[searchcharpos + 1]);
   Serial.print(serialdata[searchcharpos + 2]);
   Serial.print(serialdata[searchcharpos + 3]);
   Serial.print(serialdata[searchcharpos + 4]);
   Serial.print(serialdata[searchcharpos + 5]);
   Serial.print(serialdata[searchcharpos + 6]);
   Serial.print(serialdata[searchcharpos + 7]);
   Serial.print(serialdata[searchcharpos + 8]);
   Serial.print(serialdata[searchcharpos + 9]);
   Serial.print(serialdata[searchcharpos + 10]);
   Serial.print(serialdata[searchcharpos + 11]);
   Serial.print(serialdata[searchcharpos + 12]);
   Serial.print(serialdata[searchcharpos + 13]);
   Serial.print(serialdata[searchcharpos + 14]);
   Serial.print ("=========");
   //Serial1.print("AT+CCLK?\r"); //ask for the time
   //delay(50);
   Serial.println("");
   Serial.println("=====");
   Serial.println(millis());

   Serial.println("YEAR: ");
   Serial.print(rtcy1[0]);
   Serial.println(rtcy1[1]);
   Serial.println("MONTH: ");
   Serial.print(rtcm1[0]);
   Serial.println(rtcm1[1]);
   Serial.println("DAY: ");
   Serial.print(rtcd1[0]);
   Serial.println(rtcd1[1]);
   Serial.println("HOUR: ");
   Serial.print(rtch1[0]);
   Serial.println(rtch1[1]);
   Serial.println("MINUTE: ");
   Serial.print(rtcmm1[0]);
   Serial.println(rtcmm1[1]);
   Serial.println("SECOND: ");
   Serial.print(rtcs1[0]);
   Serial.println(rtcs1[1]);

   enabledtime = 1;

   currentMillis = millis();
 }
}


And the output:


LK
DAY:
"
HOUR:
4/
MINUTE:
1/
SECOND:
1,
=========

OK

+CCLK: =========
=====
123279
YEAR:
+C
MONTH:
LK
DAY:
"
HOUR:
4/
MINUTE:
1/
SECOND:
1,
=========

OK

+CCLK: =========
=====
124281
YEAR:
+C
MONTH:
LK
DAY:
"
HOUR:
4/
MINUTE:
1/
SECOND:
1,
=========

OK

+CCLK: =========
=====
125285
YEAR:
+C
MONTH:
LK
DAY:
"
HOUR:
4/
MINUTE:
1/
SECOND:
1,
=========

OK

+CCLK: =========
=====
126287
YEAR:
+C
MONTH:
LK
DAY:
"
HOUR:
4/
MINUTE:
1/
SECOND:
1,


I need your assistance with this!

I can post the full code if needed. (This is the full code, but it will be embedded in the bigger program.)

Thanks in advance!

P. S. I'm not using the library for a reason, first I think it doesn't have all the functions I need and second I want to make my program optimised.