creating string with variables to place in an array

Thanks to Paul S and Cattledog i was able to get a jump on this, but im still fumbling on what i thought would be the easier step

Using an Arduino a Mega and CC3000, i am attempting to post multiple streams to m2X, which requires an ISO 8601 time stamp in an array.

I am thinking i should probably use a character array, but how do i have variables in a character array? When i read tutorials and other posts, people seem to shy from strings, but im not sure what else to do?

the m2x header is as follows per their example:

const char *streamNames[] = { "temperature", "humidity" };
int counts[] = { 2, 1 };
const char *ats[] = { "2013-09-09T19:15:00Z",
                      "2013-09-09T19:15:10Z",
                      "2013-09-09T19:15:20Z"};
double values[] = { 10.0, 20.0, 7.5 };

*not entirely sure what the double values are??

Anyway, using this section of code i should be able to construct whatever variable will sit inside of the brackets instead of those constants:

Serial.print(hour());
   printDigits(minute());
   printDigits(second());
   Serial.print(' ');
   Serial.print(month());
   Serial.print("/");
   Serial.print(day());
   Serial.print("/");
   Serial.print(year());
   Serial.println();
   Serial.print("Unix Time ");
   Serial.println(now());
   Serial.println();

the whole m2x example follows:

#include <jsonlite.h>
#include <SPI.h>
#include <WiFi.h>

#include "M2XStreamClient.h"

char ssid[] = "<ssid>"; //  your network SSID (name)
char pass[] = "<WPA password>";    // your network password (use for WPA, or use as key for WEP)

int status = WL_IDLE_STATUS;

char feedId[] = "<feed id>"; // Feed you want to push to
char m2xKey[] = "<M2X access key>"; // Your M2X access key

const char *streamNames[] = { "temperature", "humidity" };
int counts[] = { 2, 1 };
const char *ats[] = { "2013-09-09T19:15:00Z",
                      "2013-09-09T19:15:10Z",
                      "2013-09-09T19:15:20Z"};
double values[] = { 10.0, 20.0, 7.5 };

WiFiClient client;
M2XStreamClient m2xClient(&client, m2xKey);

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while(true);
  }

  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();
}

void loop() {
  int response = m2xClient.postMultiple(feedId, 2, streamNames,
                                        counts, ats, values);
  Serial.print("M2x client response code: ");
  Serial.println(response);

  if (response == -1) while(1) ;

  delay(5000);
}

the "ats" is used in one of the last lines
(note, about 10lines of wifi related code deleted from end)

thanks so much for the help i've recieved thus far from here. It has been immensely helpful for me to get started and gain an understanding.

I'm sorry but I don't understand your question or problem, can you make it more clear?

A char array is a string, which should not be confused with a String, which is an object of the String class.

On most arduinos, a double is the same thing as a float, it's different only for the Arduino Due (better precision).

I'm not sure if this is what you need, but here's an example of how to put the time elements, pulled from an RTC into system time, into an iso8601 format character array using sprintf.

sprintf is a bit of a memory hog, and if you have problems you may need to use other methods to populate the elements of the array.

I've left in the T and the Z from your example and I've null terminated the array. I don't know if your application requires it.

#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>

void setup() {
  Serial.begin(9600);
  setSyncProvider(RTC.get);//put rtc time into system time
  
  //YYYY-MM-DD iso 8601
  //hh:mm:ss iso8601
  
char buffer[21];
sprintf(buffer,"%d-%02d-%02dT%02d:%02d:%02dZ\0",year(),month(),day(),hour(),minute(),second());
Serial.println(buffer);
}

void loop() {}

guix:
I'm sorry but I don't understand your question or problem, can you make it more clear?

A char array is a string, which should not be confused with a String, which is an object of the String class.

On most arduinos, a double is the same thing as a float, it's different only for the Arduino Due (better precision).

In the first code section, i need to replace the constant date codes in *ats with some a variable(s) so that the m2x server will be able to recognize the time.

From what i think i am seeing in cattledog's post, i should be able to place "buffer" in the *ats array in the header in the first post. i'll report back when i get a chance to try it out tonight.