Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@takayuky
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takayuky/811e3a144f98bfd7308f to your computer and use it in GitHub Desktop.
Save takayuky/811e3a144f98bfd7308f to your computer and use it in GitHub Desktop.
Slack経由で家の外からエアコンをon, offできる装置を、Raspberry Piで作ってみた。(しかも御坂美琴ちゃんが応答してくれる) ref: http://qiita.com/KAKY/items/55e6c54fa2073cdc0bbe
<?php
#POSTリクエスト確認用
#ob_start();
#var_dump($_POST);
#$post = ob_get_contents();
#ob_end_clean();
#file_put_contents("/tmp/dump.txt", $post);
$data = array(
"off" => array(
"regex" => "/\Aオフ\z/u",
"operation" => "off",
"text" => ["エアコンのスイッチ切っといたわよ!べ、別にあんたのためじゃないんだからね!", "ほら、エアコン切っておいたわよ。家出る前にちゃんと確認しなさいよね!"]
),
"heater" => array(
"regex" => "/\A暖房オン\z/u",
"operation" => "24hot",
"text" => ["あんたが風邪引かないように、暖房入れておいたわ。感謝しなさい!", "早く帰ってきなさい、暖房入れて待ってるから...//"]
),
"cooler" => array(
"regex" => "/\A冷房オン\z/u",
"operation" => "25cool",
"text" => ["今日もあっついわねー、ほら、冷房かけといたわよ。", "クーラーかけとくわ。帰ってきたら一緒にアイスでも食べましょ!"]
)
);
?>
<?php if ($_POST["token"] != "<YOUR TOKEN>"): ?>
<h2>無効なトークンです</h2>
<?php elseif ($_POST["user_id"] == "USLACKBOT"): ?>
{"text":""}
<?php elseif ($_POST["user_id"] != "<YOUR USER ID>"): ?>
{"text":"この操作は⚪︎⚪︎にしか許されてないの。ゴメンね(>_<)"}
<?php else: ?>
<?php foreach ($data as $k => $v): ?>
<?php if (preg_match($v['regex'], $_POST['text'])): ?>
<?php exec("irsend SEND_ONCE sakai-air " . $v['operation'], $output, $return_var); ?>
<?php if ($return_var === 0): ?>
<?php $t = $v['text']; ?>
{"text":"<?php echo $t[array_rand($t)]; ?>"}
<?php else: ?>
{"text":"エラーが発生したみたい...確認お願いするわね。"}
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
# Please make this file available to others
# by sending it to <lirc@bartelmus.de>
#
# this config file was automatically generated
# using lirc-0.9.0-pre1(default) on 2015
#
# contributed by <% YOUR NAME %>
#
# brand: <% BRAND %>
# model no. of remote control: <% MODEL No. %>
# devices being controlled by this remote: <% DEVICE %>
#
begin remote
name aircon
flags RAW_CODES
eps 30
aeps 100
gap 200000
toggle_bit_mask 0x0
begin raw_codes
name off
3458 1739 416 454 412 1322 409 459 409 459 408 476 391 455 431 436 408
465 413 448 407 477 396 453 412 454 413 450 415 1322 409 457 414 455 410
456 411 457 411 455 410 460 411 451 412 1326 410 1320 411 1330 404 453
......
name on
3465 1733 417 452 414 1322 410 454 411 458 418 445 413 454 421 447 411 496
370 454 429 442 418 445 413 456 416 461 396 1327 408 457 413 454 414 452
412 457 416 449 412 454 412 456 411 1326 409 1325 408 1324 435 431 412 452
......
end raw_codes
end remote
lines = File.open(ARGV[0]).readlines #行ごとに配列として読み込み
lines_without_first = lines.slice(1..-1) #先頭の行は不必要なので省く
puts lines_without_first.map{|line|line.split(" ")[1]}.join(" ") #整形して表示
{text:"@message@"}
...
pi ALL=(ALL) NOPASSWD: ALL
www-data ALL=NOPASSWD:/bin/sh #この行を追加
$ irsend SEND_ONCE aircon on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment