Publishing Current Epoch Time using Particle Publish

I’m trying to publish the current epoch time using Particle.publish(Time.now()); but I keep getting this error `test.cpp:1:1: error: ‘Particle’ does not name a type

^

make[1]: *** […/build/target/user/platform-6test.o] Error 1
make: *** [user] Error 2`

I don’t know why you get that particular error, but Particle publish takes a String or const char* as the argument (or arguments), not an integer which is what Time.now() returns. Have a look at the docs.

hmm. I have looked on the docs and you are right. https://docs.particle.io/reference/firmware/photon/#now- I’m stuck. What should I do?

If you’re sending data with a Particle publish, you should have two arguments. The first one is the event name, and the second one is the data. You can use sprintf to convert a number to a char*, or you can use String(value) to convert an integer to a String.

    char message[64] = "";
    sprintf(message, "Time= not sure what to put here ;
    Particle.publish("Time", message);

I have little (read no) experience with C or C++. I’m still stuck.

Then you need to learn C at least, or there’s no way for you to successfully program your Particle device. We can help with problems that arise, but this forum is not the right place to learn C. You will be continually frustrated if you don’t learn the basics of programming. Do you have experience with any programming language?

2 Likes

Javascript, HTML, CSS (and some python) are the languages I know but again I don’t have much experience with low level languages like C or C++.

Google: sprintf format specifier C++