Connect directly to a Spark Photon REST API

I connected my newly arrived Photon’s to my WIFI accespoint and followed the tutorials. I created the REST example from http://docs.particle.io/photon/examples/. Which is working fine with the following URL:
https://api.particle.io/v1/devices/your-device-ID-goes-here/led?access_token=your-access-token-goes-here

However I would like to connect directly to the Photon without an internet connection. So something like http://PHOTON_HOSTNAME/… I searched through the community and found this thread: Tutorial: Local Cloud 1st Time instructions [01 Oct 15] . Is that the solution for my problem? Or is there an easier solution?

The local cloud should work. TCP/IP and UDP are also available. The local cloud should be the easiest transition though, depending on what you’re trying to achieve,

Ok, I just want to call a REST endpoint on the Photon to turn some LED’s on or off. So there is no way to directly call the Photon for instance with an IP address? It’s necessary to use the local cloud option?

Hi @johan, you don’t need the local cloud to implement a HTTP server on the photon. All that’s needed is a WiFi connection to a router.

In coming months we will implement AP mode on the photon, so the Photon itself will be the access point and your devices can connect directly to it without needing an intervening router.

Cheers :smile:
mat.

1 Like

I’ve setup the localcloud and I can see my Photon (actually the spark-server app mentions “Core online!” :)).

However I can’t connect to the Photon. I have uploaded the led example https://docs.particle.io/guide/getting-started/examples/photon/#control-leds-over-the-39-net to the Photon. It works when I use the Particle cloud, but how do I connect to the Photon with the local cloud?

What URL should I use instead of the URL for the Particle cloud: ‘https://api.particle.io/v1/devices/your-device-ID-goes-here/led?access_token=your-access-token-goes-here’?

Ok, I'm a bit further, apparently there is something wrong with my access token. But I have no idea what.

I figured out my acces token:

$ particle config identify
Current profile: localcloud_profile
Using API: http://192.168.178.15:8080
Access token: XYZ

I start 'node main.js' and in another window call the API:

$ curl http://192.168.178.15:8080/v1/devices?access_token=c442acbe41aaa40bdd708ecc444297d0e06a572f
{
  "code": 400,
  "error": "invalid_grant",
  "error_description": "The access token provided is invalid."
}

The output of the local server is:

Your server IP address is: 192.168.178.15
server started { host: 'localhost', port: 5683 }
Connection from: 192.168.178.20, connId: 1
on ready { coreID: 'ABC',
  ip: '192.168.178.20',
  product_id: 6,
  firmware_version: 65535,
  cache_key: '_0' }
Core online!
192.168.178.15 - - [Wed, 16 Sep 2015 17:50:19 GMT] "GET /v1/devices?access_token=XYZ HTTP/1.1" 400 109 "-" "curl/7.30.0"

Any idea what I'm doing wrong?

Nah, your accesstoken is perfectly fine. For the Particle Cloud. Since you're running the local cloud, you shouldn't be using that one though.

Have a read through these topics:

1 Like

Thanks for the tip, but I already followed those tutorials. However I repeated some of the steps and now it’s working. Apparently I forget one or more of the steps. It would be nice if there was a simpler setup without so many steps :).

1 Like