Event name with slash

I have implemented a distributed set of sensors all communicating with publishing / subscribing to event names with a consistent namespace in the event names. Basically they look like sensor/temperature/request. Both the publish and subscribe events work swimmingly, but now that I’m developing a JS front-end I’m seeing 404 errors when trying to get the web browser to subscribe to the event names as they are above.

When I do onEvent for ‘sensor’ and ‘sensor/’ it works but when I add ‘sensor/temperature’ it with the 404 error. Is there any workaround for this?

If you subscribe to ‘sensor’, you should get all events with that name. Since the eventname is part of the SSE, you can filter them on the JS side(?)

@Moors7 thanks for the reply. While I could do that, I’d prefer to not have to process every event, just the ones that match the event path I specify. I’m just hoping there is some way to do this.

I wouldn’t know of a way to do that off the top of my head. Personally I’d go with the method I described above, since that requires only one listener. You can use if/else or switch/case statements to filter out the events you’re interested in. I don’t think that it would hurt too bad, performance-wise.
For alternatives, I’m going to refer you to the likes of @bko who undoubtedly knows more about these things than I do.

in this handler, similarly I’m only interested in the first response from my gmail webhook, it always has my gmail unread count. If there is dozens of returns, I only care to handle the one with the /0 added to the response:

void webhookHandler(const char *event, const char *data)
  DEBUG_PRINTLN("Responding to webhook...");
  DEBUG_PRINTLN(event);  // just for debugging to see how the webhook was actually called
  DEBUG_PRINT("Webhook is ");
  DEBUG_PRINT(strlen(data));  // debug payload length
  DEBUG_PRINT(" bytes and contains: ");
  if (strstr(event, "my_gmail/0"))  //<<<<<<<<<<<<<<<<<<<<<<<<<<< here
    gotGmailFeed(event, data);
  else if(strstr(event, "current_weather"))
    gotWeather(event, data);
  else if (strstr(event, "forecast_weather"))
    gotForecast(event, data);
  else if (strstr(event, "sun_time"))
    gotSunTime(event, data);

I’m subscribing with hooks that contain the Photon’s ID:

  String responseTopic = System.deviceID();
  Particle.subscribe(responseTopic, webhookHandler, MY_DEVICES);

the webhook appends its identification to the core’s ID:

    "event": "my_gmail",
    "url": "https://<USERNAME>:<PASSWORD>@mail.google.com/mail/feed/atom/",
    "requestType": "POST",
	"headers": null,
	"query": null,
	"responseTemplate": null,
	"responseTopic": "{{SPARK_CORE_ID}}_my_gmail",
	"json": null,
	"auth": null,
	"coreid": null,
	"deviceid": null,
	"mydevices": true
1 Like

Hi @drukz

I am not sure why you would be getting a 404 from the event endpoint–I thought you could write “sensor/temperature/anything-I-want-up-to-some-length-limit” etc. I cannot seem to get a 404 out of particle subscribe, for instance.

Maybe something else is going wrong with your code in this case–have you tried poking around with a debugger? Or you could try the CLI and particle subscribe or even curl.