I’ve been having issues getting the code that worked on my Cores to work on my new Photons. I’ve found the problem to be that the Photon crashes if it has more than two subscriptions and receive an event.
I wrote the following code to show the error:
void handleLED1(const char* event, const char* data){
digitalWrite(D0, HIGH);
delay(1000);
digitalWrite(D0, LOW);
}
void handleLED2(const char* event, const char* data){
digitalWrite(D1, HIGH);
delay(1000);
digitalWrite(D1, LOW);
}
void handleLED3(const char* event, const char* data){
digitalWrite(D2, HIGH);
delay(1000);
digitalWrite(D2, LOW);
}
void handleLED4(const char* event, const char* data){
digitalWrite(D3, HIGH);
delay(1000);
digitalWrite(D3, LOW);
}
void setup() {
Spark.subscribe("led1", handleLED1);
Spark.subscribe("led2", handleLED2);
Spark.subscribe("led3", handleLED3);
Spark.subscribe("led4", handleLED4);
pinMode(D0, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
}
void loop() {
Spark.process();
}
There is a LED connected to each of D0-D3 and the code wats for the events led1
, led2
, led3
and led4
and ights the LED for one second upon recieving this event.
The code works just as you would expect on the Core, the LEDs turn on for a second and life goes on, but on the Photon the following happens:
Code as above:
The events led1
, led2
and led3
makes the LED light up for one second, turn of and then the Photon crashes and blinks SOS. The event led4
causes no reaction.
led4
subscription commented out:
The events led1
, led2
and led3
causes the same behavior as above.
led3
and led4
subscription commented out:
Works as expected. The LEDs turn on for a second and the device does not crash.
It seems the crash occurs upon exit of the event handling routine. The Photon only crashes after the LED has turned off. If you increase the delay it will also delay the crash, so I’m pretty sure it is upon exit.
The documentation clearly says that both the Core and the Photon should be able to handle up to 4 events, but the Photon obviously can’t.
The code was written in the online Build IDE and flashed to the devices OTA.
I cant see any reason why this should not work on both devices. Since it works perfectly on the Core I can only assume this is a firmware bug on the Photon. Has anyone else found this problem?