Cylon.js For Imp
This repository contains the Cylon adaptor for the Electric Imp (https://electricimp.com/) platform.
Want to use Ruby on robots? Check out our sister project Artoo (http://artoo.io)
Want to use the Go programming language to power your robots? Check out our sister project Gobot (http://gobot.io).
How to Install
Install the module with:
$ npm install cylon cylon-imp
You'll also need to setup your Imp, for this you can go here: Electric Imp Getting Started
Once you have completed the Getting Started process and have a connected Imp, you need to go to the Electric Imp IDE page and create a new model that you can attach your Imp to. You can check how that process works in detail on the Electric Imp IDE docs
How to Use
Blink LED: Digital GPIO
var Cylon = ;Cylonstart
How to Connect
We need to setup the Agent code and Device code so we can control the Imp over the internet. First we need to setup the agent that will serve as the endpoint URL for our Imp.
Setting up the Agent
Inside the Electric Imp IDE, on the left side (for the default layout), you'll find the Agent section, you need to paste the following code:
// Log the URLs we needserver.log("Agent URL: " + http.agenturl());saved_response <- null;functionfunction// register the HTTP handlerhttp.onrequest(requestHandler);// register device response listener for digital and analog readsdevice.on("response", responseHandler);
This will allow use to send commands to the Imp, specify modes, setup pins and consotrl I2C devices. You can also find this code in the utils section of this repo.
Setting up the Device firmware
Same as with the Agent code we do this inside the Electric Imp IDE, but now on the right side viewport, there you'll see the Device section, same as before paste the following code:
// create a global variabled called led and assign pin9 to itpins <-;functionfunctionfunctionfunctionfunctionfunctionfunctionagent.on("digitalWrite", digitalWrite);agent.on("digitalRead", digitalRead);agent.on("analogWrite", analogWrite);agent.on("analogRead", analogRead);agent.on("pwmWrite", pwmWrite);agent.on("i2cWrite", i2cWrite);agent.on("i2cRead", i2cRead);
This will execute code in your Imp device when you make calls to the Agent using the agent URL, you can check how to do this in the following section.
Your Imp device is one click away of being ready to communicate and execute code, just click on the
Build and Run button
on the top of the IDE and you should be ready to go.
Talking to your imp through the Agent URL
In order to use Cylon to communicate with your Imp we'll need the agent URL. You can find this URL right above the Agent viewport of the IDE, alternatively you can look for it in the log after you click
Build and Run.
Once you have this url, which should like something along the lines of
https://agent.electricimp.com/45QYZvoB41bu, you can pass it along the adaptor parameters in your Cylon code.
This is how you setup the connection using the agent url in Cylon:
var Cylon = ;Cylonstart
We're busy adding documentation to our web site at http://cylonjs.com/ please check there as we continue to work on Cylon.js
For our contribution guidelines, please go to https://github.com/hybridgroup/cylon/blob/master/CONTRIBUTING.md .
For the release history, please go to https://github.com/hybridgroup/cylon-imp/blob/master/RELEASES.md .
Copyright (c) 2014-2015 The Hybrid Group. Licensed under the Apache 2.0 license.