Serial communication

Dear all.

I have code as below.I have call function mentioned below. currently my code work like loop execute means whenever Serial_call() being called serial statement going to print.

These data i am going to interlink to scada system over wifi .I am planning to use below wifi device.

I have tested the code . the code works similar like serial communication.

I would like code , instead of sending data all time , i would like to say based on request i am expected data. for example if i send request Serial send saying data from 1 to 20 I should get only that frame of data

In my code Device_Id alone hardware config 1 to 24.if i send request device ID with length of data i should get particular frame length of data

I have attached output file for reference.I get data only after 10 samples. I would like to visible data all time with taking next moving sample. How can i do it

Take_Temp_Reading()
Take_HV_Reading()

void Serial_call()
{
  //  Device_ID=ID_Check();
  temp_int = Take_Temp_Reading();
  temp_int = (uint16_t)temp_int;
  SPD = SPD_Check();
  DISCONNECTOR =  DC_Status();

  Serial.print(Device_ID);
  Serial.print(",");
  Serial.print(Mod_current[0]);
  Serial.print(",");
  Serial.print(Mod_current[1]);
  Serial.print(",");
  Serial.print(Mod_current[2]);
  Serial.print(",");
  Serial.print(Mod_current[3]);
  Serial.print(",");
  Serial.print(Mod_current[4]);
  Serial.print(",");
  Serial.print(Mod_current[5]);
  Serial.print(",");
  Serial.print(Mod_current[6]);
  Serial.print(",");
  Serial.print(Mod_current[7]);
  Serial.print(",");
  Serial.print(Mod_current[8]);
  Serial.print(",");
  Serial.print(Mod_current[9]);
  Serial.print(",");
  Serial.print(Mod_current[10]);
  Serial.print(",");
  Serial.print(Mod_current[11]);
  Serial.print(",");

  Serial.print(Mod_current[23]);
  Serial.print(",");
  Serial.print(Mod_current[22]);
  Serial.print(",");
  Serial.print(Mod_current[21]);
  Serial.print(",");
  Serial.print(Mod_current[20]);
  Serial.print(",");
  Serial.print(Mod_current[19]);
  Serial.print(",");
  Serial.print(Mod_current[18]);
  Serial.print(",");
  Serial.print(Mod_current[17]);
  Serial.print(",");
  Serial.print(Mod_current[16]);
  Serial.print(",");
  Serial.print(Mod_current[15]);
  Serial.print(",");
  Serial.print(Mod_current[14]);
  Serial.print(",");
  Serial.print(Mod_current[13]);
  Serial.print(",");
  Serial.print(Mod_current[12]);
  Serial.print(",");

  Serial.print(temp_int);
  Serial.print(",");
  Serial.print(SPD);
  Serial.print(",");
  Serial.print(DISCONNECTOR);
  Serial.print(",");
  HV_Reading = Take_HV_Reading();
  Serial.println(HV_Reading);
  //  Serial.print(",");


}
void setup()
{
  wdt_enable(WDTO_8S);

  //analogReference(INTERNAL);

  pinMode(3, OUTPUT);
  pinMode(SO_enable, OUTPUT) ;// pin can enable/disable using digital IO 7 of arduino
  pinMode(S1_enable, OUTPUT) ;// pin can enable/disable using digital IO 6 of arduino
  pinMode(S2_enable, OUTPUT) ;// pin can enable/disable using digital IO 5 of arduino
  //  pinMode(Enablepin, OUTPUT) ;// pin can enable/disable using digital IO 4 of arduino
  pinMode(A0, INPUT) ;
  pinMode(A5, INPUT) ;
  //spd & DC STATUS
  pinMode(SPD_STATUS_PIN, INPUT);
  pinMode(DC_STATUS_PIN, INPUT);

   Serial.begin(57600);
}



void loop() {

  Device_ID = 1;
  Take_Reading();
  Serial_call();

}
int  Take_Temp_Reading()
{

  Temp_Total = Temp_Total - Temp_readings[Temp_index];
  Temp_readings[Temp_index] = analogRead(A5);
  Temp_Total = Temp_Total + Temp_readings[Temp_index];
  Temp_index = Temp_index + 1;

  if (Temp_index >= numReadings)
  {
    Temp_index = 0;
    Temp_Average = Temp_Total / numReadings;
  }
  temp = (Temp_Average * 5.0) / 1023.0;


  //  temp = float(analogRead(A5)) * 5.0 / 1024.0;
  temp_int = (int)(temp * 100.0);
  return (temp_int);
  // Serial.print("Temp"); Serial.println(temp);
}

int SPD_Check()
{

  SPD_STATUS = digitalRead(SPD_STATUS_PIN);
  return (SPD_STATUS);
}

int  DC_Status()
{

  DC_STATUS = digitalRead(DC_STATUS_PIN);
  return (DC_STATUS);

}



int   Take_HV_Reading()
{

  //int analog_int= analogRead(A4);

  total = total - readings[index];
  // read from the sensor:
  readings[index] = analogRead(A4);
  // add the reading to the total:
  total = total + readings[index];
  // advance to the next position in the array:
  index = index + 1;

  // if we're at the end of the array...
  if (index >= numReadings1)
  {
    index = 0;
    average = total / numReadings1;
  }

  HV_voltage = (average * 5.0) / 1023.0;

  if (HV_voltage <= 0.25)
  {

    Conv_HV_voltage = 0.0;
  }
  else
  {
    Conv_HV_voltage = 197.837837838 * HV_voltage + 10.8108108108;
  }
  HV_Reading = (uint16_t)(Conv_HV_voltage * 10);

  return (HV_Reading);
}


void Take_Reading() {

  for (int row = 0; row < 8; row++)
  {
    //   // get rid of me:
    digitalWrite(SO_enable, array[row][0]);
    digitalWrite(S1_enable, array[row][1]);
    digitalWrite(S2_enable, array[row][2]);
    delay(100);
    analog_1_pv[row] = ANALOG_SCALING * analogRead(A0);
    analog_2_pv[row] = ANALOG_SCALING * analogRead(A1);
    analog_3_pv[row] = ANALOG_SCALING * analogRead(A2);
    if ( (analog_1_pv[row] <= MINV_RANGE || (analog_1_pv[row] >= MAXV_RANGE) ))
    {
      Current_Value1[row] =  0.0;
    }
    else
    {
      Current_Value1[row] =  (analog_1_pv[row] * 12.5) - 31.25;

    }

    if (  (analog_2_pv[row] <= MINV_RANGE || (analog_2_pv[row] >= MAXV_RANGE) ))
    {
      Current_Value2[row] =  0.0;
    }
    else
    {
      Current_Value2[row] =  (analog_2_pv[row] * 12.5) - 31.25;

    }

    if (  (analog_3_pv[row] <= MINV_RANGE || (analog_3_pv[row] >= MAXV_RANGE) ))
    {
      Current_Value3[row] =  0.0;
    }
    else
    {
      Current_Value3[row] =  (analog_3_pv[row] * 12.5) - 31.25;

    }


    Mod_current[row] = (uint16_t)(Mul_Factor * Current_Value1[row]);
    Mod_current[row + 8] = (uint16_t)(Mul_Factor * Current_Value2[row]);
    Mod_current[row + 16] = (uint16_t)(Mul_Factor * Current_Value3[row]);


  }



}

New_code.zip (2.14 KB)