Sha256: 23b5a153a81a2336fc83afa7d2e73ea84057c9ecbef287e91cc485af7277629c

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

var myhttp = require('http');
var querystring = require('querystring');

(function (exports) {

    exports.getBBInfo = function (host, myip, myserial, callback, callback_error) {

        if (host.indexOf(":") > -1) {

            var hn = host.substr(0, host.indexOf(":"));

            var port = host.substr(host.indexOf(":") + 1);

        } else {

            var hn = host;
            var port = 80;
        }

        var postdata = querystring.stringify({

            "beaglebone[ipaddress]": myip,

                "beaglebone[serialnumber]": myserial,

            commit: "Update Beaglebone"

        });

        var options = {
            hostname: hn,
            port: port,
            path: "/connect/" + myserial,
            method: "POST",
            headers: {
                'content-type': 'application/x-www-form-urlencoded'
            }
        }


        var request = myhttp.request(options, function (res) {

            var body = "";

            res.setEncoding("utf8");

            res.on('data', function (chunk) {
                body += chunk;
            });

            res.on('end', function () {
                var myResponse = JSON.parse(body);

                if (myResponse) {

                    if (typeof myResponse.table === "undefined") {

                        callback(myResponse);

                    } else {

                        callback(myResponse.table);

                    }
                } else {
                    callback({});
                }
            });


        }).on('error', function (e) {

            callback_error(e.message);

        });

        request.write(postdata);
        request.end();

    }



})(typeof exports == 'undefined' ? this['dialadeviceweb'] = {} : exports);

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dial_a_device_node-0.0.154 dial-a-device-web.js
dial_a_device_node-0.0.153 dial-a-device-web.js