Author Topic: Control OAK from web  (Read 7922 times)

panicroom

  • Newbie
  • *
  • Posts: 4
Control OAK from web
« on: January 30, 2016, 11:30:56 pm »
Seems like the latest firmware it's quite stable so i decided to start playing with my oak.

One of the major advantages of this tiny board is the wifi connectivity and also the ability to control it through Particle's API.

I'm using documentation for Particle's photon as it seems to be very similar (actually identical).

Below is code on how to control a pin through a web request.

Flash this code with the help of arduino software:

int ledToggle(String command) {
    if (command=="on") {
    Particle.publish("ON","OAK3");
    digitalWrite(2, HIGH);
        return 1;
    }
    else if (command=="off") {
    Particle.publish("OFF","OAK3");
    digitalWrite(2, LOW);
        return 0;
    }
    else {
        return -1;
    }
}
void setup(){
   Particle.function("led",ledToggle);
   pinMode(2, OUTPUT);
}

void loop(){
}


Monitor the progress through Particle dashboard. I noticed that it takes up to 5 minutes to compile and flash OAK so be patient.

Once you see that flash status is successful you can control OAK with a REST request:
You can find your device id from from https://dashboard.particle.io/user/devices
Access token can be found from https://build.particle.io at settings section (bottom left)

curl https://api.particle.io/v1/devices/[device-id]/led/?access_token=[access token] -d params=on
curl https://api.particle.io/v1/devices/[device-id]/led/?access_token=[access token] -d params=off

« Last Edit: January 30, 2016, 11:36:10 pm by panicroom »

smaw51

  • Newbie
  • *
  • Posts: 4
Re: Control OAK from web
« Reply #1 on: March 20, 2016, 05:30:12 pm »
What terminal do you use? I've been trying to send and receive stuff from my oak and have not been able to figure it out. I have my device id and access token and have been trying to follow the wiki but still can not find where send the on/off commands to the oak.


Thanks

memo07

  • Newbie
  • *
  • Posts: 1
Re: Control OAK from web
« Reply #2 on: March 25, 2016, 06:11:10 pm »
What terminal do you use? I've been trying to send and receive stuff from my oak and have not been able to figure it out. I have my device id and access token and have been trying to follow the wiki but still can not find where send the on/off commands to the oak.


Thanks

It works for me using windows terminal! you just need to install cURL package, you can find info here http://stackoverflow.com/questions/9507353/how-do-i-install-set-up-and-use-curl-on-a-windows and download the package directo from here https://curl.haxx.se/download.html

or if you are using linux just install the package

touliloup

  • Newbie
  • *
  • Posts: 14
Re: Control OAK from web
« Reply #3 on: April 25, 2016, 03:39:24 am »
Hi,

for super simple debug you can use the particle web interface:
http://suda.github.io/particle-web-interface/

This simple interface list all published variable and function. Allowing you to call the function with parameter  :)



More info here:
https://github.com/suda/particle-web-interface

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Control OAK from web
« Reply #4 on: May 01, 2016, 12:21:28 am »
Nice find touliloup! Will have to give that one a try :)

Another tool I have used in addition to curl is the particleCLI, as that is specifically mean to work with particle, so has some easy shorthand like device name, etc.