Question about using array with sprintf() to send file to sd and to cloud


hi,

i ask help. want extend code. writing temperature values array ( example char pageadd[128] ) sprintf.
than sending cloud , sd card:
code: [select]

sprintf(pageadd,"/update?key=xxxxxxxxxxxxx&field1=%i&field2=%i&field3=%i&field4=%i&field5=%i",temp0,temp1,temp2,temp3,temp4);
if(!getpage(server,pageadd)) serial.print(f("fail "));
else serial.print(f("pass "));


defining logfile , sending sd:

code: [select]

int logfile(char* sdate, char* stime, int temp0, int temp1, int temp2, int temp3, int temp4) {

  file fh = sd.open("xyz.txt",file_write);
  if(!fh) {
    serial.println(f("open fail"));
    return 0;
  }

  sprintf(pageadd,"%s,%s,%i,%i,%i,%i,%i;",sdate,stime,temp0,temp1,temp2,temp3,temp4);

  fh.println(pageadd);
  fh.close();
  return 1;



this cloud cannot handle more 8 fields 1 sending. send update key 5 values.

do have use array instead of pageadd example? lenght ok, should empty before new sending? confused.
or have sprintf defined like:
code: [select]

sprintf(pageadd,"/update?key=yyyyyyyyyyyyyy&field1=%i&field2=%i&field3=%i&field4=%i&field5=%i",temp5,temp6,temp7,temp8,temp9);


thank you!

if use sprintf() twice same buffer array second use overwrite first , add null terminator @ appropriate place.  example
code: [select]
int bb1 = 12345;
int bb2 = 678;
char buffer[10];

void setup()
{
  serial.begin(115200);
  sprintf(buffer, ">%d<", bb1);
  serial.println(buffer);

  sprintf(buffer, ">%d<", bb2);
  serial.println(buffer);
}

void loop()
{
}


Arduino Forum > Using Arduino > Programming Questions > Question about using array with sprintf() to send file to sd and to cloud


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support