I want to use Spark.publish to publish a event every time the led (D7) on my Photon goes high and then low. Here is the existing code I am using to blink my led
Have a look at the docs and see if you can get that example working. Are you trying to do this with two devices, or on the same one?
Report back with your results, and we’ll go from there
That shouldn’t be a problem. If you take a look at the example in the docs, it should be a case of simply editing the eventName. After that, you can make changes for the LED to blink.
Give it a try, and report back
I’m afraid that won’t work since it doesn’t comply with the syntax required, Spark.subscribe("eventName", myHandler);
Please do take a look over here: http://docs.particle.io/photon/firmware/#spark-subscribe
Then, copy that example, and change the eventname.
Also, the delays in your latest two code examples are WAY too short. They need to be a minimum of 1000, or you will be penalised for publishing too quickly. You can find the rules regarding that over here: http://docs.particle.io/photon/firmware/#spark-publish
Also, a delay of 10 isn’t even visible to the human eye, so that doesn’t make any sense, regardless of penalties.
That code compiles without errors for me. Not that it was a surprise, considering you took the example code provided to you above, and just increased the length of the delays.
Some questions:
Do you know what the delays do?
Do you know how long those delays are?
Why do you need a delay greater than 1000?
And more importantly:
Have you read the docs regarding these subjects, i.e. publish/subscribe?
I’ve edited your post to properly format the code. Please check out this post, so you know how to do this yourself in the future. Thanks in advance! ~Jordy
Okay, at this point I have to ask: have you read any of my previous posts?
I have read yours, and I understand what you’re trying to do. I’m also giving you suggestions on how to achieve that. If you want me to write the code for you, then please, by all means say so, I’ll write it, and we’ll be done with it.
If you actually want to try something yourself, and maybe learn something, please, read my previous comments, and try the suggestions. They’re not that hard; it’s literally copy&paste.