Alan Moment
  • Introduction
  • 智慧家庭
    • Fibaro 系統整合便宜的 IP Cam
  • Life
    • 用AWS Glacier做最後的冷資料備份
    • 如何在macOS修改影音檔日期
  • 3D Printer
    • Atom2.5EX 之血淚組裝
    • 列印經驗紀錄
      • SpoolHolder
    • 製圖經驗
      • Turntable
      • 重製Atom3散熱風扇
    • 線材經驗
      • PETG
        • 首測
  • Kubernetes
    • 使用Kops建立Kubernetes
    • 使用HelmV2
    • Kubernetes的技術問題排解技巧
  • PHP
    • 管理PHP Library的利器Composer
    • PHP安裝JSON
    • Phalcon首發
    • Gearman Job Worker for PHP
    • Laravel 首發 !!!
    • Data Encrypt & Decrypt
  • Python
    • Django + Python 開發環境建置
  • Android
    • Android zipcode library of maven
    • Android use foreign object of OrmLite
    • ProgressBar while loading ListView of Android
    • AsyncTask download image by the Android
    • Use Thread control Android UI
    • Android Universal Image Loader
  • Ruby on Rails
    • Install rmagick on the Windows of Ruby on Rails
    • Ruby on Rails deploy on Heroku
    • Ruby on Rails 小問題
  • React
    • Ditched AngularJS for React
  • Tessel
    • 很潮的 Tessel
    • Connect to Slack on Tessel
    • Baby Help on Tessel
  • Node.js
    • CentOS 安装 Node.js 0.8.5
  • OOAD
    • Injection Principle Design Pattern
  • Linux
    • SSH免密碼登入遠端電腦
    • Apache與Tomcat的結合
    • The bash auto build
  • Hadoop
    • CentOS 5.5 + Hadoop 0.20
    • CentOS 5.5 + Hbase 0.94.8
    • Hadoop + Hbase 叢集環境
    • Hadoop 溝通橋梁之 Thrift 0.7
    • 使用MapReduce之替代方案Hive
    • 使用Sqoop將MySQL資料匯入Hbase
  • Database
    • 吃足苦頭的Mssql
  • IDE
    • Netbeans console中文亂碼解決方法
    • 用NetBeans開發Ruby On Rails
  • Agile
    • 淺談我的Agile
  • 協作工具
    • 建置專屬自己的Github之Gitlab
    • Gitlab 4.1 upgrade to Gitlab 6.0超偷懶方法
    • Install Phabricator and run on the Gitlab
    • Phabricator 基本應用
    • Phabricator review code應用
    • Redmine之基本建置與Scrum應用
    • Omnibus Gitlab 7 基礎操作
    • Git Push Notify to Slack on Gitlab
    • phabricator-extensions-Sprint 無法抓到正確的 Story Points
  • 其他
    • 慶祝Octopress開張
    • 走在時尚的尖端! Ghost
    • 大搬家
    • 網頁教學初體驗
    • 網路攻擊很猖狂
Powered by GitBook
On this page
  • 申請 Slack
  • Tessel Wifi
  • Wifi 斷線

Was this helpful?

  1. Tessel

Connect to Slack on Tessel

Previous很潮的 TesselNextBaby Help on Tessel

Last updated 3 years ago

Was this helpful?

申請 Slack

因為 非常方便且好用,所以我第一個想到要串接的對象就是它,接連幾天的測試,已經能透過 Tessel 發送訊息至 Slack Channel。

首先得先擁有一組 Slack 的帳號與 Channel,再設置 Incoming WebHooks。

便可取得 Webhook Url

Tessel Wifi

先讓 Tessel 連接家中的 Wifi

$ tessel wifi -n 'Alan 的 AirPort Time Capsule' -p 'PASSWORD'
TESSEL! Connected to TM-00-04-f000da30-00544741-1ca82586.
INFO Connecting to "Alan 的 AirPort Time Capsule" with wpa2 security...
INFO Acquiring IP address.
..
INFO Connected!

IP        192.168.1.46
DNS       168.95.192.1
DHCP      192.168.1.1
Gateway   192.168.1.1

wifi-control.js

var https = require('https');

wifi.on('connect', function(data) {

  console.log("connect emitted", data);

  var json = JSON.parse('{"text":"This is a line of text in a channel.\nAnd this is another line of text."}');
  var postData = 'payload=' + JSON.stringify(json);

  var options = {
      hostname: 'hooks.slack.com',
      port: 443,
      path: '/services/T030MA704/B04MARY2F/clicTENx48f4h5v9OePzePkH',
      method: 'POST',
      headers: {
          'Content-Type': 'application/x-www-form-urlencoded',
          'Content-Length': postData.length
      }
  };

  // Setup the request.  The options parameter is
  // the object we defined above.
  var req = https.request(options, function(res) {
      res.setEncoding('utf-8');
      var responseString = '';

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

      res.on('end', function() {
          console.log(responseString);
      });
  });

  req.on('error', function(e) {
      console.log('something error.');
  });

  req.write(postData);
  req.end();

}

因為 Slack 是透過 https 發送,所以這邊得使用 https.request 來傳遞封包。 運行 Wifi-control.js 測試是否可以正常傳送至 Slack Channel。

$ tessel run wifi-control.js
TESSEL! Connected to TM-00-04-f000da30-00544741-1ca82586.
INFO Bundling directory /Users/alan/Documents/tessel-code
INFO Deploying bundle (8.87 MB)...
INFO Running script...
connect emitted {
dns : 168.95.192.1,
ip : 192.168.1.46,
event : status,
connected : 1,
dhcp : 192.168.1.1,
ssid : Alan 的 AirPort Time Capsule,
gateway : 192.168.1.1
}
ok

測試可以正常收到囉!!

如此就可以應用在各種需要通知的狀況上,太棒了!

Wifi 斷線

要如何讓 Tessel 斷開 wifi 呢,只要下這行指令:

$ tessel wifi -d
TESSEL! Connected to TM-00-04-f000da30-00544741-1ca82586.
Erasing saved wifi profiles
Erased wifi profiles

太方便了...

May 3rd, 2015 1:41:16am

依照 Tessel 在官網上 的範例,修改一下程式碼:

Wifi
Slack