Manipulating and Splitting incoming I2C string to be sent along

Hey everyone I am working with a difficult string coming in From a LoRa device via I2C and I need to split it apart into 5 different segments and them forward them off to Thingsboard …the partial code is below

snprintf(mqttPub, sizeof(mqttPub), "{\"ipstring\":%s}",ipstring);
Serial.println(mqttPub);

Particle.publish("Sensor_Data",mqttPub);
    //===============
 //Serial.println(mqttPub);
    // Send payload
psClient.publish("v1/devices/me/telemetry", mqttPub);               // Topic, payload
 blinkLED();

  //cnt=0;
  //pub=1;
 
  
}

void serverConnect(void)
{
    while (!psClient.connected())
    {
        Serial.println("serverConnect(): Attempting to connect to Thingsboard server");
        if (psClient.connect("Photon", TOKEN, NULL))                    // ClientID, User, PW
        {
            Serial.println("serverConnect(): Connected");
            return;
        }
        else
            Serial.println("serverConnect(): Connection failed, retry in 3 seconds");
        delay(3000);
    }
}

The output form the LoRa device is this {“ipstring”:101592_23_512_42496_50432}

@jade7272, you can do a search for “strtok” which is the perfect tool for parsing strings. You will find lots of examples in the community.

http://www.cplusplus.com/reference/cstring/strtok/

Thanks having a look now

@jade7272, as @ScruffR might point out, you can also use scanf():

http://www.cplusplus.com/reference/cstdio/scanf/

2 Likes

Thanks Guys …This will help …Just need to put in special characters in the incoming string to separate and send along