Created
May 12, 2017 22:25
-
-
Save BatslyAdams/a474b03b5c254a5ed439401dbdc9cba6 to your computer and use it in GitHub Desktop.
Dog Parker Example Code
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
'use strict'; | |
var clientFromConnectionString = require('azure-iot-device-http').clientFromConnectionString; | |
var Message = require('azure-iot-device').Message; | |
var connectionString = '<redacted>' | |
var client = clientFromConnectionString(connectionString); | |
var ip = require("ip"); | |
var mraa = require('mraa'); | |
var dog_present = new mraa.Gpio(1); | |
var door_open = new mraa.Gpio(2); | |
var uv_light = new mraa.Gpio(3); | |
dog_present.dir(mraa.DIR_IN); | |
door_open.dir(mraa.DIR_IN); | |
uv_light.dir(mraa.DIR_IN); | |
function getRandomInt(min, max) { | |
min = Math.ceil(min); | |
max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min)) + min; | |
} | |
// Create a message and send it to the IoT Hub every second | |
setInterval(function(){ | |
var data = JSON.stringify({ | |
ip_address: ip.address(), | |
dog_present: dog_present.read(), | |
door_open: door_open.read(), | |
uv_light: uv_light.read(), | |
temperature_front: getRandomInt(67,73), | |
temperature_rear: getRandomInt(67,73), | |
}); | |
var message = new Message(data); | |
client.sendEvent(message); | |
}, 2500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment