I have a string formattedDate. When I am trying to give sprintf(payload,"{\"timestamp\":\"%s\",\"temperature\":%f,\"humidity\":%f}",formattedDate,t,h); Its not printing the date and time.

  • Are you certain that formattedDate contains data?
    – Majenko
    Aug 6 '19 at 12:31
  • 2
    is formattedDate a String? then use formattedDate.c_str()
    – Juraj
    Aug 6 '19 at 12:31
  • When I use this I am able to print date and time --> Serial.println(formattedDate);
    – Sahithi
    Aug 7 '19 at 3:55
  • Actually, I am trying to send DHT11 data to AWS cloud. I am able to send temperature and humidity. I want time also to get imported for visualization. I am using NTP for date and time, so included the NTP libraries and this is working --> formattedDate = timeClient.getFormattedDate(); Serial.println(formattedDate); --> But i want it to print in JSON format. So I am printing like this sprintf(payload,"{\"timestamp\":%s,\"temperature\":%f,\"humidity\":%f}",formattedDate,t,h); But here i am unable to print date and time some random boxes and question marks are being printed.
    – Sahithi
    Aug 7 '19 at 4:05
  • 1
    println has a version for String sprintf doesn't
    – Juraj
    Aug 7 '19 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.