User Tools

Site Tools


oak:tutorials:localserver

This is an old revision of the document!


Oak on the Particle Local Server

You may chose to use your Oak with a local version of the Particle server. This is a guide for how to install the local server and setup an Oak to use it.

NOTE: You can also use many other cloud services for storing data, just look for any of them that have a ESP8266 Arduino library and they should work with the Oak - though you may need to remove the WiFi connection code in their examples because the Oak handles that automatically.

See this page for what the local server can and cannot do: https://github.com/spark/spark-server

Installing the Particle Local Server

OSX/Linux

  • Install Git (apt-get git, brew git, or similar)
  • Download zip file of the Particle (Spark) server: https://github.com/digistump/spark-server/archive/master.zip (Note this version has been modified to fix some bugs that Particle has not fixed yet.)
  • Unzip the download and open a command line window in that folder and then run the following commands:
npm install
node main.js

Windows

node main.js

The Particle local server should now be running!

Installing the Particle CLI Tool

  • With node installed in the last step you can install the Particle CLI tool with this command:
    npm install -g particle-cli
  • If you are on the Raspberry Pi, you will need to use the following command so that the serialport dependency is successfully compiled as there are no pre-compiled binaries for the Raspberry Pi/ARM platform:
    sudo npm install -g particle-cli --unsafe-perm --build-from-source

Setting up an Oak to use the Local Server

For an Oak to use the local server we'll need to do the following:

  1. Convert the server's public key to the DER format and then Base64 Encode it
  2. Set the Server Address and Server Public Key for the Oak to the those of the local server
  3. Set the Particle CLI tool to allow it to talk to the local server and connect
  4. Restart the Oak and allow it to connect

1. Convert the server's public key to the DER format and then Base64 Encode it

Run (from the same folder as the server):

openssl rsa -in  default_key.pub.pem -pubin -pubout -outform DER -out default_key.pub.der

and then use a base64 encoder (locally for best safety) or here for convenience: http://bin-hex-converter.online-domain-tools.com/

Upload the default_key.pub.der and get the hex encoded output, save this somewhere, you will need it in the next step.

2. Set the Server Address and Server Public Key for the Oak

Go to this page: http://digistump.com/oak/localserver.html

Then disconnect from the internet and connect your wifi to an updated Oak that is in config mode (see: http://digistump.com/wiki/oak/tutorials/connecting).

On that page enter the server address (IP or domain) and the hex encoded key you got above and hit submit.

Or POST the following JSON as a raw body to http://192.168.0.1/set

{"server-address":"IP OR DOMAIN HERE","server_address_type":0,"server-public-key":"HEX PUBLIC KEY FROM ABOVE"}

server_address_type = 0 for IP address, 1 for domain name

3. Copy the device Public Key to the Server

In the server folder create a core_keys folder if it does not exist.

While still connected to the Oak that is in config mode go to http://192.168.0.1/device-id - you should get a response like this:

{ "id":"ABCDEFGHJK","c":"1" }

Where “ABCDEFGHJK” is the device ID for this device - copy this without the quotes, you will need it to complete the rest of this step.

Now go to http://192.168.0.1/public-key - you should get a response like this:

{ "r": 0, "b":"AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ" }

Where “AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ” is a string of numbers and letters that make up the hex encoded public key for the device. Copy this string without the quotes into a text editor and save as DEVICE_ID.pub.der - where DEVICE_ID is the device id you got above.

Upload it here (or use another hex decoder): http://bin-hex-converter.online-domain-tools.com/ and hit decode, then click download as binary file. Rename that download to DEVICE_ID.pub.pem and place in the core_keys directory you created above.

4. Set the Particle CLI tool to allow it to talk to the local server

Source: https://docs.particle.io/support/troubleshooting/cloud-solutions/photon/ Run the following commands on a separate CMD prompt from the one running the server:

particle config local_oak apiUrl "http://DOMAIN_OR_IP:8080"

particle config local_oak 

particle setup 

This adds the local server ip to the cli tool, switches to using it, and creates an account on the local cloud.

5. Restart Oak so it connects

Stop and restart the server.

Repeat steps #2 and #3 for other Oaks you want on the same cloud.

Remove power from the Oak and then re-apply power. The Oak should now connect to the local server and you should see the connection in the local server command window.

See the Particle guides for more about what you can do with the local server, use the Particle-cli upload and compile options to push firmware.

oak/tutorials/localserver.1481261913.txt.gz · Last modified: 2016/12/08 21:38 by pfeerick