顯示具有 html 標籤的文章。 顯示所有文章
顯示具有 html 標籤的文章。 顯示所有文章

2017年8月14日 星期一

Arduino smart home ac remote

想要玩arduino很久了,總算有時間來試一下。參考了網路上的資訊,從完全沒摸過到寫程式燒錄到arduino,還有網頁http request的研究,總算最後是完成了。花了三天的時間,很有成就感也很累,在炎炎夏日還蠻實用的。

幾個過程中的重點:

arduino:

  • 匯入程式庫後compile才成功,不能自己用貼上.h的方式
  • Could not connect to YunServer 146 Connection refused的問題在我去除while (!Serial);後有顯著的改善
  • 目前紅外線LED的遙控距離還是太短,考慮增加電阻
  • 使用readuntil到?時會中斷(應該是timeout),所以目前是拿掉,之後再看有沒有辦法解決
  • 網頁資料是使用serial,我改用rest的方式,所以在資料取得方式上有些不同


web:


  • header必須要用Status: 200而非HTTP/1.1 200 OK,後者會導致content type無法變成text/html
  • arduino rest api protection要關閉,是為了讓網頁執行時不會hit到CORS(cross-origin resource sharing)的問題。狀況是這樣,因為使用了authrization所以會變成非簡單要求,發出OPTION request後因為我們建置的並非正式webserver所以response為空沒辦法加入header(arduino寫的程式必須要先能夠碰到REST)因此被擋(無法回傳access-allow-origin: *),使用datatype: jasonp並沒有辦法解決問題。沒使用authrization前是401,使用後是400。



參考資料
自己
smart home ac
http://cc.beingo.net/archives/2234
https://m.mobile01.com/topicdetail.php?f=731&t=4135366&p=1
http://cms.35g.tw/coding/arduino-remote-daikin-3/
http://cms.35g.tw/coding/arduino-remote-daikin-2/
http://cms.35g.tw/coding/arduino-remote-daikin/

arduino yun
https://forum.arduino.cc/index.php?topic=191895.0
https://forum.arduino.cc/index.php?topic=227213.0
http://yehnan.blogspot.tw/2014/04/arduino-yunbridgeconsoleprocess.html
https://www.arduino.cc/en/Tutorial/Bridge
https://arduino.stackexchange.com/questions/10257/sending-values-to-an-arduino-yun-across-different-networks
http://yehnan.blogspot.tw/2014/04/arduino-yunbridgeyunserveryunclient.html
http://yehnan.blogspot.tw/2013/01/arduinods18b20.html
http://yehnan.blogspot.tw/2013/05/arduino.html
http://yehnan.blogspot.tw/2016/04/arduino-yunwi-fi.html
https://forum.arduino.cc/index.php?topic=192936.0

CORS
http://www.ruanyifeng.com/blog/2016/04/cors.html
https://blog.m157q.tw/posts/2016/09/07/cross-origin-resource-sharing/
https://developer.mozilla.org/zh-TW/docs/Web/HTTP/Access_control_CORS

ajax
http://blog.techbridge.cc/2017/05/20/api-ajax-cors-and-jsonp/
https://babaawesam.com/2014/11/06/control-input-output-of-arduino-yun-with-ajax/
http://www.cnblogs.com/Mainz/p/3506956.html
http://shiyousan.com/post/635433082130309661

phpmyadmin create sql
http://www.complete-concrete-concise.com/web-tools/creating-a-mysql-database-using-ampps

HTML
http://www.w3school.com.cn/tags/tag_doctype.asp

字元與字串
http://dhcp.tcgs.tc.edu.tw/c/p009.htm

Basic Auth
https://stackoverflow.com/questions/5507234/how-to-use-basic-auth-with-jquery-and-ajax
https://stackoverflow.com/questions/3571090/basic-authentication-with-jquery-ajax-request-and-jsonp
https://stackoverflow.com/questions/27904082/using-http-basic-authentication-with-ajax-call

php windows工作排程
http://mrbignose.blogspot.tw/2010/05/php-windows-php.html

2015年2月3日 星期二

phpmailer

參考資料
http://belleaya.pixnet.net/blog/post/27410978-%5B%E6%95%99%E5%AD%B8%5D-php-%E5%88%A9%E7%94%A8-phpmailer-%E9%80%8F%E9%81%8E-gmail-%E5%AF%84%E4%BF%A1
http://blog.jsdan.com/php-%E4%BD%BF%E7%94%A8phpmailer%E9%80%8F%E9%81%8Egmail%E5%AF%84%E4%BF%A1/
http://who-know.com/use-phpmailer-to-send-emails-via-gmail-smtp/
while try catch自動分行讀取
http://kris-14.blogspot.tw/2009/12/php-txt.html
http://phpwrite.blogspot.tw/2010/05/php5try-catch.html
fopen 檔案路徑寫法
http://www.php.net/manual/en/function.fopen.php
輸入及呼叫
http://www.dami.tw/2013/11/11phpcode.html
http://www.php5.idv.tw/html.php?mod=article&do=show&shid=54
http://www.php5.idv.tw/html.php?mod=article&do=show&shid=68
http://stackoverflow.com/questions/15890627/phpmailer-body-with-variables
php重複定義
http://witmax.cn/php-cannot-redeclare-class.html
html註解
http://ant4html.blogspot.tw/2008/11/blog-post.html
php運行時間限制以及後台運行
ignore_user_abort(true);
set_time_limit(0);
http://www.ptt.cc/man/PHP/DEAA/M.1359052474.A.47F.html
http://www.blueshop.com.tw/board/FUM20041006152627A9N/BRD2012020312083365R.html
http://www.allenj.net/archives/1910
http://blog.wu-boy.com/2007/06/php-%E5%96%84%E7%94%A8-ignore_user_abort-%E5%87%BD%E5%BC%8F/
http://www.isdee.com/notes/ecshop_phpmailer.html
http://hi.baidu.com/yxl7808/item/00b9ca9c85628ae62916471d
http://sourceforge.net/p/phpmailer/discussion/81620/thread/6819cd16/
清除收件者欄位
由於預設是用addaddress()所以當跑迴圈時會重複寄送
因此需使用clearaddresses()並且不能用unset(), unset只是暫時重設,下次再呼叫時會讀取unset前之數值
http://www.wibibi.com/info.php?tid=236
http://chan15.blogspot.tw/2011/11/phpmailer.html
textarea
使用input只有一行,因此一般的留言板都應該使用textarea
另外input可以設定長度跟高度,雖然還是只能輸入一行
http://stackoverflow.com/questions/4391344/how-can-i-set-the-size-of-the-box-of-a-form
http://crazy.molerat.net/learner/cpuroom/programmer/reading.php?filename=1010407112825.dov
http://www.php-example.com/2011/05/php-html-form-textarea-example.html
斷行處理
http://chensh.loxa.edu.tw/php/X_8.php
http://www.jollen.org/php/jollen_php_book_79_textarea.html
http://itgroup.blueshop.com.tw/ann71727/ann71727?n=convew&i=6032

2014年1月13日 星期一

sendemail.exe發送html格式郵件

這是google的頁庫存檔,連結已無法存取,留個紀錄。

本文主要讨论Python如何使用sendEmail发(垃圾)邮件?
     Linux用户常用sendmail发送电子邮件,当您看了本文后可能会改用sendEmail去发送邮件了,呵呵。

1 下载sendEmail

       sendEmail有Linux和windows版本软件包,依据自己的平台选择下载好了
      登录上边的网址找到:
   

     Download

Official Release: sendEmail-v1.56.tar.gz    (29kb Sep 29th, 2009)    Changelog    Screen Shot

Windows Download:
Free sendEmail.exe for Windows. To use simply run sendEmail.exe from a console / command line.
sendEmail-v156-notls.zip   (677kb Sep 29th, 2009)   No TLS support 
sendEmail-v156.zip   (1.4mb Sep 29th, 2009)   TLS supported 

RPM Package: sendEmail rpm
选择适合自己的下载好了

2 安装sendEmail

  sendEmail不需要安装直接解压到某目录即可直接使用。
    (Linux用户) tar -zxvf sendEmail-x-y-z.tar.gz
 本文选择windows平台sendEmail软件包,下载后解压到c:\sendEmail目录下。


3 sendEmail命令帮助

   sendEmail软件是命令行软件,需要在Dos(shell)下执行使用。

[jeapedu]# sendEmail --help

sendEmail-1.56 by Brandon Zehm <caspian@dotconf.net>

Synopsis:  sendEmail -f ADDRESS [options]

Required:
-f ADDRESS                from (sender) email address
* At least one recipient required via -t, -cc, or -bcc
* Message body required via -m, STDIN, or -o message-file=FILE

Common:
-t ADDRESS [ADDR ...]     to email address(es)
-u SUBJECT                message subject
-m MESSAGE                message body
-s SERVER[:PORT]          smtp mail relay, default is localhost:25

Optional:
-a   FILE [FILE ...]      file attachment(s)
-cc  ADDRESS [ADDR ...]   cc  email address(es)
-bcc ADDRESS [ADDR ...]   bcc email address(es)
-xu  USERNAME             username for SMTP authentication
-xp  PASSWORD             password for SMTP authentication

Paranormal:
-b BINDADDR[:PORT]        local host bind address
-l LOGFILE                log to the specified file
-v                        verbosity, use multiple times for greater effect
-q                        be quiet (i.e. no STDOUT output)
-o NAME=VALUE             advanced options, for details try: --help misc
-o message-content-type=<auto|text|html>
-o message-file=FILE         -o message-format=raw
-o message-header=HEADER     -o message-charset=CHARSET
-o reply-to=ADDRESS          -o timeout=SECONDS
-o username=USERNAME         -o password=PASSWORD
-o tls=<auto|yes|no>         -o fqdn=FQDN

Help:
--help                    the helpful overview you're reading now
--help addressing         explain addressing and related options
--help message            explain message body input and related options
--help networking         explain -s, -b, etc
--help output             explain logging and other output options
--help misc               explain -o options, TLS, SMTP auth, and more

      测试用例

     我(sender@163.com)要给他/她(receiver@sina.com)发电子邮件,邮件的主题是"subjectTitle",邮件的内容是说句“hello”,带了附件attach.txt文件,我邮箱sender@163.com的密码是“123456”,则使用sendEmail的命令如下:
 sendEmail -f sender@163.com -t receiver@sina.com -s smtp.163.com -xu sender@163.com -xp 123456 -u subjectTitle -m hello -a attach.txt
          注:本示例在windows平台下测试,需手动使用dos即运行->cmd->cd c:/sendEmail目录(假设下载文件解压到本目录)

   -f    后指定在邮箱里显示谁发的邮件
   -t    后指定发给谁
   -s   指定发送smtp服务器,本例用163的smtp服务器
   -xu 后需指定smtp服务器上的授权帐号(sender@163.com),
         实际上就是用参数xu后边的邮箱来真正发送邮件
   -xp 后则是smtp服务器上的授权帐号(sender@163.com)所对应的密码,
         smtp服务器要检查合法性
   -u   邮件主题
   -m  邮件正文内容
   -a   邮件携带附件(attach.txt)
      各位网友在自我测试时,需对应替换。比如想用“se@163.com(密码abcdef)”发邮件给"re@sina.com",邮件主题“hello”,邮件内容"world",携带附件"b.txt",我来替换一下如下:
 sendEmail -f se@163.com -t re@sina.com -s smtp.163 -xu se@163.com -xp abcdef -u hello -m world -a b.txt



4 编写发送邮件程序

    写个Python程序来用用吧:发几百封邮件给他/她/Ta.程序名sm.py,请保存在sendEmail.exe同一目录下。
import os

from = "sender@163.com"
to = "reveiver@sina.com"
subject = "say hello"
msg = "I like you"
attachfile = "a.txt"
c = 0
while c < 498:
 os.system("sendEmail.exe -f "+from+" -t "+to+" -xu "+from+" -xp 123456 -u "+subject+" -s smtp.163.com -a "+attachfile+" -m "+msg)
 c = c + 1
    据说163邮件一天最多发500封信,之后。。。呵呵,何时解封时间不确定,我看可以多申请几个163邮箱。
    在sendEmail目录下执行python sm.py即可发499封邮件给他/她/Ta.

5. 怎样使发送邮件内容为Html的呢?

    首先在sm.py文件所在目录下创建一个html文件,例如a.html,代码如下:

<html>
<body>
<B>测试网页</B><br>
<a href= "http://www.csdn.net"><font color = 'blue' size = '7'><u>CSDN就是牛!</u></font></a>
</body>
</html>

    接着,需要在sendEmail命令行里增加几个可以发送html文本作为邮件正文内容的参数选项。

     -o message-content-type=html 
     -o message-charset=CHARSET 
     -o message-header=HEADER  
     -o message-file=afile
     -o message-content-type = html 
                 告诉邮件服务器发送的是html格式邮件内容
     -o message-charset = CHARSET 
                这里不能用utf-8否则邮件内容显示乱码
     -o message-file=某文件  
                是用来指定携带的那个html网页文件作为邮件正文, 这样邮件正文里就可以有超级链接了。

     最后运行测试。


參考資料