RESTful API Call From Cache to Particle.io Electron

RESTful API Call From Cache to Particle.io Electron

Tom Fitzgibbon | Multidata | 212-967-6700 x537 | tom@mul.com

Summary: Simple Blink Tutorial for Particle.io Electron Device from Cache

Electron device is a tiny ARM processor ($40-$60) that connects to Particle’s world wide leased 2G/3G network (about $3/mo) and runs off an included LiPo battery. Using Cache’s %Net.HttpRequest you can send/receive data, control hardware and read sensors.

Step by Step (about 1 hour)

1) Get the Electron from store.particle.io.

2) Set up the Electron from setup.particle.io.

3) Install an LED and resistor from setup instructions.

4) Test with build.particle.io using their code for “Web-Connected LED”.  You get your access_token from Settings and device number from Devices in Build and substitute in their code.  Edit the code to make sure you can light the LED from a browser before moving to step 5.

5) Setup an SSL configuration in your Cache via the SMP (System Management Portal) in Security/SSLTLS configurations. Just create a new SSLTLS configuration by entering a name (like TLS) and saving.

6) Run the following Cache code from an internet connected Mac or PC after substituting your access_token, device number and on/off in args. Do ^LED1 from Cache terminal.

LED1 ;simple blink test with Cache
 Set httprequest=##class(%Net.HttpRequest).%New()
 Set httprequest.SSLConfiguration="TLS"
 Set httprequest.Https=1
 Set httprequest.Server="api.particle.io"
 Do httprequest.InsertFormData("access_token”,”your access token here“)
 Do httprequest.InsertFormData("args”,”on”)
 Do httprequest.Post("/v1/your device number here/led")
 Do httprequest.HttpResponse.OutputToDevice()
 q

7) You can also test from a Linux Curl command:
curl https://api.particle.io/v1/devices/your device number/led -d access_token=your access_token -d args=on