Skip to content

Instantly share code, notes, and snippets.

@hi1280
Created January 29, 2018 14:28
Show Gist options
  • Save hi1280/08d8a4327cf5d47cabed2e9e8b927459 to your computer and use it in GitHub Desktop.
Save hi1280/08d8a4327cf5d47cabed2e9e8b927459 to your computer and use it in GitHub Desktop.
AWS IoTからのメッセージを受け取って、赤外線を送信するプログラム
exports.execs = {
'tv-on': 'sudo irsend SEND_ONCE TV KEY_PLAY',
'tv-input-change': 'sudo irsend SEND_ONCE TV KEY_SELECT',
'tv-channel-down': 'sudo irsend SEND_ONCE TV KEY_CHANNELDOWN',
'tv-channel-up': 'sudo irsend SEND_ONCE TV KEY_CHANNELUP',
'tv-volume-down': 'sudo irsend SEND_ONCE TV KEY_VOLUMEDOWN',
'tv-volume-up': 'sudo irsend SEND_ONCE TV KEY_VOLUMEUP',
'tv-up': 'sudo irsend SEND_ONCE TV KEY_UP',
'tv-down': 'sudo irsend SEND_ONCE TV KEY_DOWN',
'tv-left': 'sudo irsend SEND_ONCE TV KEY_LEFT',
'tv-right': 'sudo irsend SEND_ONCE TV KEY_RIGHT',
'tv-enter': 'sudo irsend SEND_ONCE TV KEY_ENTER',
'tv-back': 'sudo irsend SEND_ONCE TV KEY_BACK',
'tv-degital': 'sudo irsend SEND_ONCE TV KEY_D',
'tv-bs': 'sudo irsend SEND_ONCE TV KEY_B',
'light-on': 'sudo irsend SEND_ONCE LIGHT KEY_PLAY',
'light-off': 'sudo irsend SEND_ONCE LIGHT KEY_STOP',
'light-up': 'sudo irsend SEND_ONCE LIGHT KEY_UP',
'light-down': 'sudo irsend SEND_ONCE LIGHT KEY_DOWN',
'video-on': 'sudo irsend SEND_ONCE VIDEO KEY_PLAY',
'video-channel-down': 'sudo irsend SEND_ONCE VIDEO KEY_CHANNELDOWN',
'video-channel-up': 'sudo irsend SEND_ONCE VIDEO KEY_CHANNELUP',
'video-input-change': 'sudo irsend SEND_ONCE VIDEO KEY_SELECT'
}
const awsIot = require('aws-iot-device-sdk');
const config = require('./config');
var child_process = require("child_process");
const device = awsIot.device({
keyPath: <YourPrivateKeyPath>,
certPath: <YourCertificatePath>,
caPath: <YourRootCACertificatePath>,
clientId: <YourUniqueClientIdentifier>,
host: <YourCustomEndpoint>
});
device.on('connect', function () {
console.log('connect');
Object.keys(config.execs).forEach((key) => {
device.subscribe(key);
});
});
device.on('message', function (topic, payload) {
console.log('message', topic, payload.toString());
child_process.exec(config.execs[topic], (err, stdout, stderr) => {
if (err) {
console.log(err.message);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment