Error opening event stream, code 400

I get the above error when my iOS app starts subscription for any event from any of my devices, at this line:

self.eventListenerID_A = [[SparkCloud sharedInstance] subscribeToAllEventsWithPrefix:nil handler: Electron_publication_handler ];

I want to just show events published by my Electron.
The Particle iPhone app shows the event coming from Electron ok.

Here’s my code within viewDidLoad()…

    SparkEventHandler Electron_publication_handler = ^(SparkEvent *event, NSError *error) 
{
	printf("\n%s: E L E C T R O N   P U B L I C A T I O N ", __FUNCTION__ );	
	if (!error)
	{
		dispatch_async(dispatch_get_main_queue(), ^{
			printf("\n");	NSLog(@"got event with name %@ and data %@",event.event,event.data);
		});
	}
	else
	{
		printf("\n");	NSLog(@"Error occured: %@",error.localizedDescription);
	}
        
};
printf("\n%s: Start subscription.", __FUNCTION__ );
   									//  subscribeToMyDevicesEventsWithPrefix
self.eventListenerID_A = [[SparkCloud sharedInstance] subscribeToAllEventsWithPrefix:nil handler: Electron_publication_handler ];
printf("\n%s: init Electron_publication_handler done.\n", __FUNCTION__ );

Is your title the complete error message? If not, please post the whole message

Pretty much. But here’s the complete log:

-[SparkViewController viewDidLoad]: init Electron_publication_handler…
-[SparkViewController viewDidLoad]: Start subscription.
-[SparkViewController viewDidLoad]: init Electron_publication_handler done.2016-11-30 09:44:52.047812 AsMan x28[494:292600] Error opening event stream, code 400
2016-11-30 09:44:53.312927 AsMan x28[494:292601] Error opening event stream, code 400
2016-11-30 09:44:54.524640 AsMan x28[494:292601] Error opening event stream, code 400
2016-11-30 09:44:55.770904 AsMan x28[494:292601] Error opening event stream, code 400
2016-11-30 09:44:56.956943 AsMan x28[494:292617] Error opening event stream, code 400
2016-11-30 09:44:58.236075 AsMan x28[494:292601] Error opening event stream, code 400

I have not set up any OAUTH stuff.

Does your app have a valid access token?

Also, don’t you want to use subscribeToMyDevicesEventsWithPrefix:? The one you’re using, subscribeToAllEventsWithPrefix:, will get all public events from everybody since you’re passing nil for the prefix.

I believe it has access token. I can login to cloud ok and read Electron’s particle.variable ok.

I wouldn’t be able to do that if there was a token problem, right?

Where in the process should this SparkEventHandler subscription handler be initialized?
I’ve tried it in viewDidLoad(), and I’ve tried it within the loginWithUser callback.

Should initialization of SparkEventHandler be immediately before setting id eventListenerID ?

Is there an example?

Particle community to the rescue!

That was the problem, Ric. Now, handler init’d in viewDidLoad is picking up publications from Electron, which is absolutely totally cool to finally see.

I need this in order to implement GPS data buffering down in the asset tracker Electron for when either mobile (iPhone) or Electron is offline… Lots o’ fun!