Publishing data to google sheets

My problem is I want to send
SENSOR DATA and TIMESTAMP together in one string for publishing it on the google sheets using IFTTT.

But as per documentation, we can only send Event name and Data associated with it.But I have to send two different data under one event name.So what I did was, I converted both the data’s into one string and used that String variable to publish,
But I got an error showing that
"cannot pass objects of non-trivially-copyable type ‘class String’ through ‘…’ "

My code goes like this

char event[50];
String rubyclock;         

void loop{

            rubyclock=Time.timeStr();
            sprintf(event,"%s %f",rubyclock,tempC);
            Particle.publish("event",String(event)); 
         }

I need a solution for this, please help me.I want to send both TIMESTAMP and sensor data in one event.So how can I convert

When passing a String object to sprintf() you need to convert that to a standard C string.

e.g.

sprintf(event,"%s %f",(const char*)rubyclock,tempC);
// or
sprintf(event,"%s %f",rubyclock.c_str(),tempC);
2 Likes

thank you for your sweet response sir,
But I got an error after using the change what you sent

invalid user-defined conversion from ‘String’ to ‘char*’ [-fpermissive]

Maybe reading what I wrote exactly might help :wink:

1 Like

the function Time.timestr() returns “String”.

So what I did was I declared a variable “rubyclock” that would hold this returned String value.Then passed that string value to sprintf.Whether what I have done is right or wrong?

Hmm, why did you not just use the code I provided?

I suggest one thing and you try something else and then ask why it didn’t work - what would you make of that when done to you?

Sir,
I used your code only.But I got the error

"invalid user-defined conversion from ‘String’ to ‘char*’ [-fpermissive] ".

So I dont’t know where to change what.Please help me I am struck here

Please post your full code

ok sir,

// This #include statement was automatically added by the Particle IDE.

#include <photon-thermistor.h>
 
 float tempC;
 int redled1=D0;
 int greenled1=D1;
 String event;
 
 Thermistor *thermistor;
 void setup() {
 Serial.begin(9600);
 pinMode(redled1,OUTPUT);
 pinMode(greenled1,OUTPUT);
 
 
 thermistor = new Thermistor(A0, 10000, 4095, 10000, 25, 3923, 5, 20);

 //--------------------Particle.functions -----------------------//
  
 // Particle.function("limit",threshold);
 //Particle.function("lower",lowerthreshold);
 
 
 digitalWrite(redled1,LOW);
 digitalWrite(greenled1,LOW);
}



void loop() {

  tempC = thermistor->readTempC();
  Serial.print(tempC);
  Serial.println("'C");
  Serial.println(Time.timeStr());
 // Particle.publish("temp", String(tempC));
  delay(5000);
  String rubyclock=Time.timeStr();
  //sprintf(event,"%s %f",rubyclock,tempC);
  sprintf(event,"%s %f",rubyclock.c_str(),tempC);
  Particle.publish("event", String(event));
 
 
  
}

int threshold(String command){
    if(String(tempC) > String(command))
    {
       digitalWrite(redled1,HIGH);
       digitalWrite(greenled1,LOW);
       return 1 ;
    }
    
     if(String(tempC)<= String(command))
    {
       digitalWrite(greenled1,HIGH);
       digitalWrite(redled1,LOW);
       Serial.println(command);
       delay(1000);
       return 0;
    }
    
}

Here in this code what I am doing is , sending “sensor data” and “time of sense” and publishing using one event

In your original code you had char event[50]; and in this new version String event; - how should one have guessed that unsolicited change?

sorry sir, I updated that later.

Now what should I do

Go back to char event[50] then it will work

Yes sir, now I checked it worked.

Thank you so much Sir.:slight_smile:

That could have been solved a lot quicker tho’

3 Likes

Thank you Sir ,

I have a doubt in sending timestamp values to google sheets.Which function should I use to get current Timestamp.

I need to the store Timestamp along with the corresponding sensor value when there is no WiFi connectivity and later publish to google sheets when WiFi connection available.This is my problem and I had written code for this problem.
But finding difficult whether which ‘time function’ should I use to get the Timestamp for saving purpose.

Have you checked the docs for the time functions yet?

Yes Sir ,but now I understood how to use them.Thank you for the help Sir.

Please keep suggest and correct me Sir when I make mistake