Last active
May 2, 2019 01:41
-
-
Save WilliamBerryiii/b6001c23247afdbfc31e1a6f28407f09 to your computer and use it in GitHub Desktop.
Getting Started with Webtask.io for IoT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var connectCallback = function (err) { | |
if (err) { | |
logCommand('Could not connect: ' + err); | |
completed(log); | |
} else { | |
logCommand('Client connected'); | |
var msg = new Message('some data from my device'); | |
client.sendEvent(msg, function (err) { | |
if (err) { | |
logCommand(err.toString()); | |
completed(log); | |
} else { | |
logCommand('Message sent'); | |
completed(log); | |
} | |
}); | |
} | |
}; | |
client.open(connectCallback); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var clientFromConnectionString = require('azure-iot-device-amqp').clientFromConnectionString; | |
var Message = require('azure-iot-device').Message; | |
var connectionString = 'HostName={iot_host_name}.azure-devices.net;DeviceId={demo_device_name};SharedAccessKey={device_sas_token}'; | |
var client = clientFromConnectionString(connectionString); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var log = []; | |
var logCommand = function (statement) { | |
log.push(Date.Now() + ": " + statement); | |
}; | |
var completed = function() { cb (null, log); }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = | |
function (cb) { | |
var clientFromConnectionString = require('azure-iot-device-amqp').clientFromConnectionString; | |
var Message = require('azure-iot-device').Message; | |
var connectionString = 'HostName=wberry-demo-iot-hub.azure-devices.net;DeviceId=demo_device;SharedAccessKey=QgoivZb0/hzYgn9Fpe4581KzBsZBdLcv+Mwhc5q7g6Q='; | |
var client = clientFromConnectionString(connectionString); | |
var log = []; | |
var logCommand = function (statement) { | |
log.push(Date.Now() + ": " + statement); | |
}; | |
var completed = function() { cb (null, log); }; | |
var connectCallback = function (err) { | |
if (err) { | |
logCommand('Could not connect: ' + err); | |
completed(log); | |
} else { | |
logCommand('Client connected'); | |
var msg = new Message('some data from my device'); | |
client.sendEvent(msg, function (err) { | |
if (err) { | |
logCommand(err.toString()); | |
completed(log); | |
} else { | |
logCommand('Message sent'); | |
completed(log); | |
} | |
}); | |
} | |
}; | |
client.open(connectCallback); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = | |
function (cb) { | |
var logs = ""; | |
cb(null, logs); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\source\webtask> wt logs | |
[18:50:04.289Z] INFO wt: connected to streaming logs (container=wt-{GUID}-0) | |
[18:50:33.705Z] INFO wt: new webtask request {task_identifier} | |
[18:50:33.732Z] INFO wt: HostName={iot_hub}.azure-devices.net;DeviceId=demo_device;SharedAccessKey={device_SAS_Key} | |
[18:50:34.420Z] INFO wt: finished webtask request {task_identifier} with HTTP 200 in 530ms | |
[18:50:34.433Z] INFO wt: Client connected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment