Plugin car.radio

car.radio

Manages the radio interface

Methods

cancelWatch

Stop watching for metadata updates
Parameters:
Name Type Description
watchId Number The watch ID as returned by car.radio.watchRadio() or car.radio.watchPresets().
Example
car.radio.cancelWatch(watchId);

getPresets

Get the presets for the current tuner

Optionally, a tuner name can be specified, returning presets for the specified tuner.

Parameters:
Name Type Argument Description
successCallback Function The function to call on success.
errorCallback Function <optional>
The function to call if there is an error.
tuner String <optional>
The tuner of the presets. If not specified, the active tuner is used.
Examples
 

//define your callback function(s)
function successCallback(presets) {
        //iterate through all the presets
        for (var i=0; i<presets.length; i++) {
            console.log("preset tuner = " + presets[i].tuner + "\n" +
                        "preset station = " + presets[i].station + "\n" +
                        "preset index = " + presets[i].index + "\n" +
                        "preset group = " + presets[i].group
            );
        }
}

function errorCallback(error) {
        console.log(error.code, error.msg);
}

//call the method
car.radio.getPresets(successCallback, errorCallback);
 REST

Request:
http://<car-ip>/car/radio/getPresets

Success Response:
{
        code: 1,
        data: [ 
            { 
                tuner: 'am', 
                station: '880', 
                index: 0, 
                group: 'am1', 
            }, { 
                tuner: 'am', 
                station: '1010', 
                index: 1, 
                group: 'am1', 
            },{
                ...    
            }
        ]
}

Error Response:
{
        code: -1,
        msg: "An error has occurred"
}

getStatus

Get the current station metadata
Parameters:
Name Type Argument Description
successCallback Function <optional>
The function to call on success.
errorCallback Function <optional>
The function to call if there is an error.
Examples
 

//define your callback function(s)
function successCallback(data) {
            console.log("tuner = " + data.tuner + "\n" +
                        "artist = " + data.artist + "\n" +
                        "genre = " + data.genre + "\n" +
                        "song = " + data.song + "\n" +
                        "station = " + data.station + "\n" +
                        "stationName = " + data.stationName + "\n" +
                        "hd = " + data.hd
            );
        }
}

function errorCallback(error) {
        console.log(error.code, error.msg);
}

//call the method
car.radio.getStatus(successCallback, errorCallback);
 REST

Request:
http://<car-ip>/car/radio/getStatus

Success Response:
{
        code: 1,
        data: {
            tuner: 'fm'
            artist: 'Bjork',
            genre: 'News & Entertainment',
            song: 'All is Full of Love',
            station: 91.5,
            stationName: 'CBC Radio 1',
            hd: false
        }
}

Error Response:
{
        code: -1,
        msg: "An error has occurred"
}

getTuners

Return the list of available tuners
Parameters:
Name Type Argument Description
successCallback Function The function to call on success.
errorCallback Function <optional>
The function to call if there is an error.
Examples
 

//define your callback function(s)
function successCallback(tuners) {
        //iterate through all the tuners
        for (var i=0; i<tuners.length; i++) {
            console.log("tuner name = " + tuners[i].tuner + "\n" +
                        "tuner type = " + tuners[i].type + "\n" +
                        "tuner range min = " + tuners[i].settings.rangeMin + "\n" +
                        "tuner range max = " + tuners[i].settings.rangeMax + "\n" +
                        "tuner range step = " + tuners[i].settings.rangeStep
            );
        }
}

function errorCallback(error) {
        console.log(error.code, error.msg);
}

//call the method
car.radio.getTuners(successCallback, errorCallback);
 REST

Request:
http://<car-ip>/car/radio/getTuners

Success Response:
{
        code: 1,
        data: [ 
            { 
                tuner: 'am', 
                type: 'analog', 
                settings: {
                    rangeMin: 880,
                    rangeMax: 1600,
                    rangeStep: 10
                }
            }, { 
                tuner: 'fm', 
                type: 'analog', 
                settings: {
                    rangeMin: 88.9,
                    rangeMax: 107.1,
                    rangeStep: 0.2
                }
            }
        ]
}

Error Response:
{
        code: -1,
        msg: "An error has occurred"
}

scan

Scan for available radio stations in the specified direction
Parameters:
Name Type Argument Description
direction String The direction to seek ('up' or 'down').
successCallback Function <optional>
The function to call on success.
errorCallback Function <optional>
The function to call if there is an error.
Examples
 

//define your callback function(s)
function successCallback() {
        console.log('scan was successfully called');
}

function errorCallback(error) {
        console.log(error.code, error.msg);
}

//call the method
car.radio.scan('up', successCallback, errorCallback);
 REST

Request:
http://<car-ip>/car/radio/scan?direction=up

Success Response:
{
        code: 1,
}

Error Response:
{
        code: -1,
        msg: "An error has occurred"
}

scanStop

Stop station scanning if in progress
Parameters:
Name Type Argument Description
successCallback Function <optional>
The function to call on success.
errorCallback Function <optional>
The function to call if there is an error.
Examples
 

//define your callback function(s)
function successCallback() {
        console.log('scanStop was successfully called');
}

function errorCallback(error) {
        console.log(error.code, error.msg);
}

//call the method
car.radio.scanStop(successCallback, errorCallback);
 REST

Request:
http://<car-ip>/car/radio/scanStop

Success Response:
{
        code: 1,
}

Error Response:
{
        code: -1,
        msg: "An error has occurred"
}

seek

Seek for the next radio station in the specified direction
Parameters:
Name Type Argument Description
direction String The direction to seek ('up' or 'down').
successCallback Function <optional>
The function to call on success.
errorCallback Function <optional>
The function to call if there is an error.
Examples
 

//define your callback function(s)
function successCallback() {
        console.log('seek was successfully called');
}

function errorCallback(error) {
        console.log(error.code, error.msg);
}

//call the method
car.radio.seek('up', successCallback, errorCallback);
 REST

Request:
http://<car-ip>/car/radio/seek?direction=up

Success Response:
{
        code: 1,
}

Error Response:
{
        code: -1,
        msg: "An error has occurred"
}

setPreset

Set the current station as a preset at the specified index

You can optionally specify a different station and tuner as a preset.

Parameters:
Name Type Argument Description
index Number The preset index.
group String The preset group.
station Number <optional>
The station to set as the preset. If this is not specified, the current station is used.
tuner String <optional>
The tuner of the presets. If not specified, the active tuner is used.
successCallback Function <optional>
The function to call on success.
errorCallback Function <optional>
The function to call if there is an error.
Examples
 

//define your callback function(s)
function successCallback() {
        console.log('preset was successfully set');
}

function errorCallback(error) {
        console.log(error.code, error.msg);
}

//call the method
car.radio.setPreset(0, 'am1', 1030, 'am', successCallback, errorCallback);
 REST

Request:
http://<car-ip>/car/radio/setPreset?index=0&group=am1&station=1030&tuner=am

Success Response:
{
        code: 1,
}

Error Response:
{
        code: -1,
        msg: "An error has occurred"
}

setStation

Tune to a specific station, optionally targeting a specific tuner

If the specified tuner is not the active tuner, then the station will be automatically selected the next time that tuner is set as active.

Parameters:
Name Type Argument Description
station Number The target station.
successCallback Function The function to call on success.
errorCallback Function <optional>
The function to call if there is an error.
tuner String <optional>
The tuner name. If not specified, the active tuner is used.
Examples
 

//define your callback function(s)
function successCallback() {
        console.log('station was successfully set');
}

function errorCallback(error) {
        console.log(error.code, error.msg);
}

//call the method
car.radio.setStation(88.5, successCallback, errorCallback);
 REST

Request:
http://<car-ip>/car/radio/setStation?station=88.5

Success Response:
{
        code: 1,
}

Error Response:
{
        code: -1,
        msg: "An error has occurred"
}

setTuner

Set the active tuner by name
Parameters:
Name Type Argument Description
tuner String The name of tuner to set as active.
successCallback Function <optional>
The function to call on success.
errorCallback Function <optional>
The function to call if there is an error.
Examples
 

//define your callback function(s)
function successCallback() {
        console.log('tuner was successfully set');
}

function errorCallback(error) {
        console.log(error.code, error.msg);
}

//call the method
car.radio.setTuner('fm', successCallback, errorCallback);
 REST

Request:
http://<car-ip>/car/radio/setTuner?tuner=fm

Success Response:
{
        code: 1,
}

Error Response:
{
        code: -1,
        msg: "An error has occurred"
}

watchPresets

Watch for preset updates
Parameters:
Name Type Description
callback Function The function to call when a change is detected.
Returns:
An ID for the added watch.
Type
  • Number
Example
function myCallback(presets) {
        //iterate through all the presets
        for (var i=0; i<presets.length; i++) {
            console.log("preset tuner = " + presets[i].tuner + "\n" +
                        "preset station = " + presets[i].station + "\n" +
                        "preset index = " + presets[i].index + "\n" +
                        "preset group = " + presets[i].group
            );
        }
}

var watchId = car.radio.watchPresets(myCallback);

watchRadio

Watch for metadata updates
Parameters:
Name Type Description
callback Function The function to call when a change is detected.
Returns:
An ID for the added watch.
Type
  • Number
Example
//define a callback function
function myCallback(metadata) {
        console.log("tuner = " + data.tuner + "\n" +
                    "artist = " + data.artist + "\n" +
                    "genre = " + data.genre + "\n" +
                    "song = " + data.song + "\n" +
                    "station = " + data.station + "\n" +
                    "stationName = " + data.stationName + "\n" +
                    "hd = " + data.hd
        );
}

var watchId = car.radio.watchRadio(myCallback);