Karotz NodeJS Plugin
A NodeJS Plugin to control your rabbit !
Introduction
First of all, you need to install the plugin by using npm :
$ npm install karotz
To use the plugin, you need :
- An account on the Karotz Platform.
- To create a new app. See this for help. Be carefull of the accesses you give to the app.
- Write the API key and the Secret key of the app somewhere.
- Load the app in your rabbit (Click the "Test!" button) and save the install ID.
For the whole explanation, see the wiki page.
Then, load the plugin :
var karotz = ; var installid = '12345' apikey = '12345' secret = '12345';
karotz.authentication(apikey, installid, secret, permanent, next)
You first need to authenticate your app to the Karotz Server. By doing this, the plugin receive an interactiveID from the Karotz Server.
An interactiveID is only valid 15min. So if you need to control your rabbit for a long time, set the permanent
params at true
for the plugin to ask for a new interactiveID every 14min.
Morevover, the plugin remember the last state of the led.
var karotz = ; var installid = '12345' apikey = '12345' secret = '12345'; karotz
Parameters :
apikey
: the apikey of your appinstallid
: the installid of your appsecret
: the secret key of your apppermanent
(boolean) : keep the connection alive or not ? If true, the plugin will ask for a new interactiveID every 14min.next
: the function to execute after the connection.
karotz.stop(stopPermanent, next)
Disconnect the Karotz. If you need to make other action with the Karotz after, you must re-authenticate the rabbit.
karotz
Parameters :
stoPermanent
: stop the loop of authenticationnext
: the function to execute after the connection.
karotz.sleep(next)
Make the rabbit sleeping (just led off and horizontal ears).
... karotz;
karotz.wakeup(next)
Wakeup the rabbit (he starts breathing).
... karotz;
karotz.config(sleepTimes, breathingLed, next)
Configure wake-up/sleep times and breathingLed.
... var sleep = '08' '00' '21' '00' //Sunday '08' '00' '21' '00' //Monday '08' '00' '21' '00' //etc. '08' '00' '21' '00' '08' '00' '21' '00' '08' '00' '21' '00' '08' '00' '21' '00'; var breathingLed = "2222FF"; karotz
karotz.callback(path, port, next)
Experimental
Listen at the given path. Could be use to listen at the callback url of the Karotz's app. See dev.karotz.com
Use it with karotz.multimedia()
and karotz.webcam()
.
You must listen to the callback
event.
... var path = 'photo';var port : 1234; //It will listen at http://myNodeJSServerIp:1234/photokarotz; //Event fired on callbackkarotz
Parameters :
url
(string) : the url to listenport
(int) : the portnext
: the function to chaine
Let's play !
karotz.ears(left, right, relative, reset, next)
Control the ears !
Each ear have 16 positions to make a loop.
... /* * Make something like that : * * | * | ___ * / \ * | ° | * | _ | * _ _ * */ var right : 8;var left : 0; karotz
... //reset to top karotz
Parameters :
left
(int) : the left earright
(int) : the right earrelative
(boolean) : is move is relative to current position ?reset
: reset the earsnext
: function to chain
karotz.led(action, object, next)
Control the led !
- Light
... //Led just change color karotz;
- Fade
... //Will fade from red to orange in 10 sec karotz;
- Pulse
... //Will blink red/white during 10 sec, then light red karotz;
- Off
... karotz;
Parameters :
action
(string) : action to do (pulse, fade or light)object
(object) : Objet containing the params according to http://dev.karotz.com/api/#Lednext
: function to chain
karotz.tts(action, lang, text, next)
And your Karotz speaks !
... //Say "I want a carrot" karotz;
... //Stop speaking karotz;
Parameters :
action
(string) : action to do (speak or stop)lang
(string) : lang (EN, FR, ...)text
(string) : the text to speechnext
: function to chain
karotz.multimedia(action, url, next)
Play and manage songs.
karotz;
Parameters :
action
(string) : action to do (play, pause, resume, stop, previous, next, record (may not work), allsong, folder, artist, genre, playlist)url
(string) : If action is "play", url of the song or path in the USB. If action is record, url to post the record (see karotz.callback() ).next
: function to chain
karotz.webcam(action, url, next)
Take a picture / a video (MJPEG stream).
For a video : can be displayed in a html page with <img src="http://api.karotz.com/api/karotz/webcam?action=video&interactiveid=1234567890 />
action
(string) : action to do (photo or video)url
(string) : if action is photo, the url the post the picture. (see karotz.callback() )next
: function to chain
karotz.configuration(next)
Return some Karotz config.
karotz
Parameters :
next
: function to chain
Events
You could listen to some events :
loop
: emit when the plugin re-authenticate the Karotz in permanent mode- 'errWithServers' : the rabbit is unreachable (try to unplug it a moment)
connected
disconnected
callback
: the server received a callbacksleep
wakeup
karotz; karotz; karotz; karotz; karotz;