Back in November I had some fairly simple code installed on two spark cores, basically LED state mirroring. This was working. Now when I try to test the same code again prior to developing the theme, I find it no longer works. The local LED lights when the local button is pressed, but it’s as if the two cores are no longer subscribed to each other because the remote LED does not react.
I did find that my access token had silently expired, and I thought I had solved the problem when I generated a new one, but unfortunately that hasn’t changed a thing.
Is there an error log I could view somewhere to debug?
You could try this link to see if your events are properly published: https://api.spark.io/v1/devices/events/?access_token=ACCESTOKEN_HERE
After that, I’d suggest flashing a testing program, which does nothing more than subscribing, to see if that’s still good. When that’s working, you can try something bigger?
Would you mind trying to publish them without ‘private’, and subscribe without ‘MY_DEVICES’, and see how that goes? There have been some issues reported with private publishing/subscribing.
It demonstrates working public and private subscribes, and will work across multiple cores (just tested it for good measure). Pub/Sub / privacy is definitely not broken, but it’s possible something isn’t behaving like you’d expect. I’ll review your code and see if anything jumps out.
It looks like your code is doing some things that will cause problems, here’s an excerpt from your file:
void setup() {
pinMode(receiveLedPin, OUTPUT); //Set the pin controlling the Core2-dependent LED as an OUTPUT
pinMode(sendLedPin, OUTPUT); //Set the pin controlling the local pushbutton-dependent LED as an OUTPUT
pinMode(inputPin, INPUT); //Set the pin connected to the pushbutton as an INPUT
digitalWrite(sendLedPin, LOW); //Ensure the local LED is set to off to begin with
digitalWrite(receiveLedPin, HIGH); //Ensure the local LED is set to off to begin with
Spark.publish("Core1Toggle", "State", 0, PRIVATE); //Set up Spark.publish() so that the state of the local LED is published to the Spark Cloud PRIVATELY
Spark.subscribe("Core2Toggle", ledTwoToggle, MY_DEVICES); //Set up Spark.subscribe() so that the state of Core1's Led is recorded and handled by ledTwoToggle
}
void loop() {
val = digitalRead(inputPin); //read value of pushbutton
if (val == LOW) { //if clause activated if pushbutton pressed and thus inputPin reads LOW
sendLedVal = !sendLedVal; //if clause activated if pushbutton pressed and thus inputPin reads LOW
digitalWrite(sendLedPin, sendLedVal ? HIGH : LOW); //write the appropriate HIGH/LOW to the sendLed pin to turn it ON/OFF
Spark.publish("Core1Toggle", sendLedVal ? "ON" : "OFF"); //publish the state to the Spark Cloud as ON/OFF
delay(250); //primitive button debouncing
}
}
For starters, you’re calling Spark.publish before your spark.subscribe call during your setup, and this will cause a race condition. If both your cores startup at the same time, those events will go into the void before your cores have subscribed to anything, and you’ll miss that message.
You also need to make sure your subscription type (MY_DEVICES, vs. ALL), matches the privacy of your publish (PRIVATE, vs. ALL). Right now a “MY_DEVICES” only subscription won’t catch a non-private publish, but that’s something I want to change because I think that can be a bit confusing.
The first takes a real long time and finally comes back with something like “ok”. The latter comes back with “No match”.
I’m trying to see if my spark.publish is working okay or not, since my program’s Spark.subscribe doesn’t seem to see it. Does 'No match" mean I’m not getting anything published? Or that the access code is wrong, although I copied and pasted that from my Web IDE.
This should work with your browser just fine - unless you’re using a stubborn one like IE which always wants to download rather than display the events (at least on my machine)
I use Chrome.