The values ​​of a string cant be separated

Hello good afternoon.
I have a sensor that detects the humidity and the temperature, the detection by levels, so, it prints 3 humidity values and 3 temperature values, but it prints it in a chain that only separates with a + sign. So we will use the command: strtok. And then with a set of while a variable is assigned to each of the values that were between the plus signs (+). I did it in the values of temperature and operation, but at the moment of doing it I do not leave. To check the result of the printing, the values of the sensors were obtained from the variables of the temperature parameters and apparently. Help

falla.PNG

#include <SDISerial.h>

#include "Arduino.h"


/*
I used a few devices with no problem using a MEGA 2560 as well as an UNO.
Sketch was built with Arduino 1.0.4, however I also tested it under 1.0.0
Place the SDISerial folder in    "<ARDUINO_ROOT>/libraries"
with the 5TE 
the WHITE wire is power. 
   - I hooked it up to the arduino 5v output pin, however you could also connect it to a pin and drive power only when you wanted it
the RED wire is the DATA_LINE.
   - you must hook it up to a pin that can process interrupts (see link below)
   
the remaining wire must be connected to ground
*/

//in order to recieve data you must choose a pin that supports interupts
#define DATALINE_PIN 2
#define INVERTED 1
#define BAUDRATE 1200

//see:   http://arduino.cc/en/Reference/attachInterrupt
//for pins that support interupts (2 or 3 typically)
char* templ1;//temperature level1
char* templ2;//temperature level2
char* templ3;//temperature level3

char* huml1;//moisture level1
char* huml2;//moisture level2
char* huml3;//moisture level3

char* value_temperature;
char* value_moisture;

SDISerial connection(DATALINE_PIN, INVERTED);

char output_buffer[125];

void setup(){
  connection.begin(); // start our SDI connection 
  Serial.begin(BAUDRATE); // start our uart
  Serial.println("OK INITIALIZED"); // startup string echo'd to our uart
  delay(3000); // startup delay to allow sensor to powerup and output its DDI serial string
  char* sensor_address = connection.sdi_query("?!", 1000);
  sprintf(output_buffer,"Sensor address: %s",sensor_address?sensor_address:"No Response");
  Serial.println(output_buffer);

  char* sensor_info = connection.sdi_query("1I!", 1000);
  sprintf(output_buffer,"Sensor info: %s",sensor_info ?sensor_info :"No Response");
  Serial.println(output_buffer);
}

void loop(){
   char* start_measurements_m = connection.sdi_query("1M!", 2000);
  sprintf(output_buffer,"start measurements Moisture: %s",start_measurements_m ? start_measurements_m :"No Response");
  //Serial.println(output_buffer);
  delay(2000);

  char* moisture = connection.sdi_query("1D1!", 2000);
  sprintf(output_buffer,"Sensor Data Soil Moisture: %s",moisture ? moisture :"No Response");
  Serial.println(output_buffer);

  char* start_measurements_t = connection.sdi_query("1M4!", 2000);
  sprintf(output_buffer,"Start Data Soil Temperature: %s",start_measurements_t ? start_measurements_t :"No Response");
  //Serial.println(output_buffer);
  delay(2000);

  char* temperature = connection.sdi_query("1D0!", 2000);
  sprintf(output_buffer,"Sensor Data Soil Temperature: %s",temperature ? temperature :"No Response");
  Serial.println(output_buffer);
  
  //AT+SAPBR=3,1,"Contype","GPRS";
  //AT+SAPBR=3,1,"APN","internet.itelcel.com";

 char* command = strtok(temperature, "+");
 int counter=1;
while (command != 0)
{
   
    // Find the next command in input string
    command = strtok(0, "+");
    if(counter==1){
      templ1=command;   
      }
    else if(counter==2){
      templ2=command;
    }
    else if(counter==3){
      templ3=command;
    }
    ++counter;
}

 char* command2 = strtok(moisture, "+");
 int counter1=1;
while (command2 != 0)
{
   
    // Find the next command in input string
    command2 = strtok(0, "+");
    Serial.println(command2);
    if(counter1==1){
      huml1=command2;   
      }
    else if(counter1==2){
      huml2=command2;
    }
    else if(counter1==3){
      huml3=command2;
    }
    ++counter1;
    Serial.println(command2);
}

Serial.println("temperatura");
Serial.println(templ1);
Serial.println(templ2);
Serial.println(templ3);

Serial.println("humedad");
Serial.println(huml1);
Serial.println(huml2);
Serial.println(huml3);


}

Thanks in advance

falla.PNG

I can't find a problem with your parsing routines, and when I run your program with specified data strings as input it outputs correctly. I think the fact that it just stops printing indicates a memory problem. I'd look very carefully to see if one of the sprintf statements is overrunning the 125 character buffer. Writing outside of memory that you own can lead to strange problems.

//#include <SDISerial.h>
//#include "Arduino.h"
//in order to recieve data you must choose a pin that supports interupts
#define DATALINE_PIN 2
#define INVERTED 1
//#define BAUDRATE 1200

//see:   http://arduino.cc/en/Reference/attachInterrupt
//for pins that support interupts (2 or 3 typically)
char* templ1;//temperature level1
char* templ2;//temperature level2
char* templ3;//temperature level3

char* huml1;//moisture level1
char* huml2;//moisture level2
char* huml3;//moisture level3

char* value_temperature;
char* value_moisture;

//SDISerial connection(DATALINE_PIN, INVERTED);

char output_buffer[125];

void setup() {
  // connection.begin(); // start our SDI connection
  //Serial.begin(BAUDRATE); // start our uart
  Serial.begin(115200);
  Serial.println("OK INITIALIZED"); // startup string echo'd to our uart
  delay(3000); // startup delay to allow sensor to powerup and output its DDI serial string
  //char* sensor_address = connection.sdi_query("?!", 1000);
  //sprintf(output_buffer,"Sensor address: %s",sensor_address?sensor_address:"No Response");
  //Serial.println(output_buffer);
  Serial.println("Sensor address: 1");

  //char* sensor_info = connection.sdi_query("1I!", 1000);
  //sprintf(output_buffer,"Sensor info: %s",sensor_info ?sensor_info :"No Response");
  // Serial.println(output_buffer);
  Serial.println("Sensor info: 113SENTEK DD MTS104DD015142");
}

void loop() {
  //char* start_measurements_m = connection.sdi_query("1M!", 2000);
  //sprintf(output_buffer,"start measurements Moisture: %s",start_measurements_m ? start_measurements_m :"No Response");
  //Serial.println(output_buffer);
  //delay(2000);

  //char* moisture = connection.sdi_query("1D1!", 2000);
  char* moisture = "1+0.094927+0.108734+0.057404";
  sprintf(output_buffer, "Sensor Data Soil Moisture: %s", moisture ? moisture : "No Response");
  Serial.println(output_buffer);

  //char* start_measurements_t = connection.sdi_query("1M4!", 2000);
  //sprintf(output_buffer,"Start Data Soil Temperature: %s",start_measurements_t ? start_measurements_t :"No Response");
  //Serial.println(output_buffer);
  //delay(2000);

  //char* temperature = connection.sdi_query("1D0!", 2000);
  char* temperature = "1+23.47698+23.27770+23.7529";
  sprintf(output_buffer, "Sensor Data Soil Temperature: %s", temperature ? temperature : "No Response");
  Serial.println(output_buffer);

  //AT+SAPBR=3,1,"Contype","GPRS";
  //AT+SAPBR=3,1,"APN","internet.itelcel.com";

  char* command = strtok(temperature, "+");
  int counter = 1;
  while (command != 0)
  {
    // Find the next command in input string
    command = strtok(0, "+");
    if (counter == 1) {
      templ1 = command;
    }
    else if (counter == 2) {
      templ2 = command;
    }
    else if (counter == 3) {
      templ3 = command;
    }
    ++counter;
  }

  char* command2 = strtok(moisture, "+");
  int counter1 = 1;
  while (command2 != 0)
  {
    // Find the next command in input string
    command2 = strtok(0, "+");
    Serial.println(command2);
    if (counter1 == 1) {
      huml1 = command2;
    }
    else if (counter1 == 2) {
      huml2 = command2;
    }
    else if (counter1 == 3) {
      huml3 = command2;
    }
    ++counter1;
    Serial.println(command2);
  }

  Serial.println("temperatura");
  Serial.println(templ1);
  Serial.println(templ2);
  Serial.println(templ3);

  Serial.println("humedad");
  Serial.println(huml1);
  Serial.println(huml2);
  Serial.println(huml3);

  while(1);
}

cattledog:
I can't find a problem with your parsing routines, and when I run your program with specified data strings as input it outputs correctly. I think the fact that it just stops printing indicates a memory problem. I'd look very carefully to see if one of the sprintf statements is overrunning the 125 character buffer. Writing outside of memory that you own can lead to strange problems.

Change from sprintf to snprintf and see what the output is. snprintf will limit (by setting the length correctly) the length of the final string. If it is cropped using snprintf then sprintf is going longer than the char[] length.