Messages from photon are being published correctly and also the android output is displaying that it is receiving the messages, but the problem is that onEvent() in the handler is crapping out after being only called once or twice.
Any thoughts on this? I searched around the forums, docs, and github and haven’t been able to find out why.
Code:
private ParticleEventHandler statusHandler = new ParticleEventHandler() {
@Override
public void onEvent(String eventName, ParticleEvent event) {
System.out.println("dataPayload=" + event.dataPayload);
}
@Override
public void onEventError(Exception e) {
e.printStackTrace();
}
};
Async.executeAsync(myDevice, new Async.ApiProcedure<ParticleDevice>() {
@Override
public Void callApi(ParticleDevice particleDevice) throws ParticleCloudException, IOException {
particleDevice.subscribeToEvents("status", statusHandler);
return null;
}
@Override
public void onFailure(ParticleCloudException exception) {
exception.printStackTrace();
}
});
Output:
D/EventsDelegate: Created event subscription with ID 1 for URI https://api.particle.io/v1/devices/xx/events/status
D/AuthenticatedSseEventSourceImpl: entering org.kaazing.net.sse.impl.AuthenticatedSseEventSourceImpl.streamOpened
D/AuthenticatedSseEventSourceImpl: entering org.kaazing.net.sse.impl.AuthenticatedSseEventSourceImpl.messageReceived: {"data":"0","ttl":"60","published_at":"2017-02-27T20:19:06.924Z","coreid":"xx"}
I/System.out: dataPayload=0
D/AuthenticatedSseEventSourceImpl: entering org.kaazing.net.sse.impl.AuthenticatedSseEventSourceImpl.messageReceived: {"data":"1","ttl":"60","published_at":"2017-02-27T20:19:12.032Z","coreid":"xx"}
I/System.out: dataPayload=1
D/AuthenticatedSseEventSourceImpl: entering org.kaazing.net.sse.impl.AuthenticatedSseEventSourceImpl.messageReceived: {"data":"0","ttl":"60","published_at":"2017-02-27T20:19:15.033Z","coreid":"xx"}
D/AuthenticatedSseEventSourceImpl: entering org.kaazing.net.sse.impl.AuthenticatedSseEventSourceImpl.messageReceived: {"data":"1","ttl":"60","published_at":"2017-02-27T20:19:17.031Z","coreid":"xx"}
D/AuthenticatedSseEventSourceImpl: entering org.kaazing.net.sse.impl.AuthenticatedSseEventSourceImpl.messageReceived: {"data":"0","ttl":"60","published_at":"2017-02-27T20:19:19.031Z","coreid":"xx"}
D/AuthenticatedSseEventSourceImpl: entering org.kaazing.net.sse.impl.AuthenticatedSseEventSourceImpl.messageReceived: {"data":"1","ttl":"60","published_at":"2017-02-27T20:19:20.031Z","coreid":"xx"}
D/AuthenticatedSseEventSourceImpl: entering org.kaazing.net.sse.impl.AuthenticatedSseEventSourceImpl.messageReceived: {"data":"0","ttl":"60","published_at":"2017-02-27T20:19:22.040Z","coreid":"xx"}
1 & 2. Tried emulators with API 21, 24, and 25, same problem. Also tried on physical devices nexus 5x and 6p running API 25
3. Time log shows event happening only every couple of seconds, well outside the timeframe of the limit of 1 event /sec or a burst of 4 events. (I’m manually opening and closing a reed switch on my desk)
4. Check out the code i posted in the gist.
Logcat isn’t spilling out anything more than what I posted.
Also the photon code is irrelevant, console.particle.io log’s and also logcat are showing everything correctly -with the exception of the event handler not being called (which is my problem)
I was unable to reproduce it so I made cloudsdk version with a bit more logging. If you are willing please try a build I shared and post your log/output.
Ok we managed to narrow it down to next not being called. It looks like next should be called from one place only, I added couple log outputs there in this build, probably quits loop which constantly reads event data however I don’t see why it would do that yet.
Good job @Hammy, from what I see it stops event listening loop on onEvent crash. I made this build to test fix (it should pass any crash from onEvent to onEventError). You can also use try catch in onEvent with current release.