2016年6月29日 星期三

XHTML and CSS Tutorial

IDE : Visual Studio Code 1.2.1
Web Server : Ubuntu 14.02 + Apache/2.4.10 + VMware WorkStation 12

完成時間6/25-7/4,共約16小時
練習檔案 https://github.com/jicianho/CSS-Tutorial

7/5發現Html功能不足,無法做到讀取server資料夾等資訊,以及接收post資料
將繼續學習 JavaScript與HTML5之應用

參考連結

https://www.youtube.com/playlist?list=PLC1322B5A0180C946

Ubunut 架設 apache2 (web server)

sudo apt-get install apache2

sudo /etc/init.d/apache2 start

/etc/httpd/conf/httpd.conf Apache 的主要設定檔。
/etc/rc.d/init.d/httpd 啟動、停止、重新啟動 Apache 的 script。
/usr/bin/htpasswd 設定使用者認證資料時所使用的指令。
/usr/sbin/apachectl 這是另一支可以控制 Apache 服務的 script。
/usr/sbin/httpd Apache 執行的主程式 (daemon)。
/var/www 存放網頁資料的目錄。

/var/log/httpd 紀錄檔存放位置。





參考網頁

http://www.arthurtoday.com/2010/05/ubuntu-apache2-server.html

2016年6月28日 星期二

2016年6月27日 星期一

客製化的 mosquitto

進入 src/mosquitto.c

main function裡面有從開啟server之後的動作

首先他先載入 config 也就是我們輸入的命令


接著
_mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "mosquitto version %s (build date %s) starting", VERSION, TIMESTAMP);
    _mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "add-plus Mosquitto-server-saving");

開始的message

/*J-強制載入 /etc/mosquitto/mosquitto.conf*/

config.config_file = "/etc/mosquitto/mosquitto.conf";
bool config_exist = file_exists(config.config_file);

if (config_exist){
   _mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Config loaded from %s.", config.config_file);
}else{
_mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Can't find config at %s.", config.config_file);
}


在handle_read中

讓mosquitto把接收到的資訊存下來

    /* J-"Payload"" is the message what publisher are sending */
_mosquitto_log_printf(NULL, MOSQ_LOG_DEBUG, "Received PUBLISH from %s (d%d, q%d, r%d, m%d, '%s', ... (%ld bytes))", context->id, dup, qos, retain, mid, topic, (long)payloadlen);
_mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Topic : %s, From : %s", topic, context->id);
_mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Message here : %s", payload);

/*將檔案寫入使用者目錄,檔名=TOPIC、內容=PAYLOAD*/
FILE *pFile;
    char buffer[50];
sprintf(buffer,"/home/cche/mqtt_state/%s.txt",topic);
pFile = fopen( buffer,"w" );
if( NULL == pFile ){
        _mosquitto_log_printf(NULL, MOSQ_LOG_DEBUG,"open failure" );
    }else{
        fwrite(payload,1,sizeof(payload)-1,pFile);
_mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "File context : %s", payload);
    }
fclose(pFile);
/*-J*/



mosquitto 執行命令後面輸入的東西會出現在

conf.c 裡面的 mqtt3_config_parse_args 裡面




2016年6月24日 星期五

Mosquitto database

mosquitto.conf中,開啟
# Persistence
# Logging
以下的註解



Error: Invalid user 'mosquitto'.
-->> useradd mosquitto
##創造使用者

1466750350: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1466750350: Error saving in-memory database, unable to open /var/lib/mosquitto/mosquitto.db.new for writing.
1466750350: Error: Permission denied.
-->> cche@ubuntu:/var/lib$ sudo chown mosquitto:mosquitto mosquitto
##把它資料夾所有者改成mosquitto


But, database of Mosquitto created can't provide look up (what's it can do??)
So, We will maybe do second dev. from Mosquitto,

doing..
1. Subscribe appoing topic.
2. Daliy system to subscribe topic.
3. A process subscribe and processing data, and sent to B process.

2016年6月23日 星期四

MQTT mossquitto.conf設定

mosquitto.comf 是mosquitto的配置文件。

放在mosquitto讀取的路徑下就可以,mosquitto預設不需要mosquitto.comf ,即使用預設值。
mosquitto -v
    【-v】打印更多的调试信息
mosquitto -c /etc/mosquitto/mosquitto.conf

mosquitto_sub -v -t test
mosquitto_sub -u name -P Passwd -v -t test
    【-t】指定主题,此处为test
    【-v】打印更多的调试信息

mosquitto_pub -t test  -m test123
mosquitto_pub -u name -P Passwd -t test -m test123

參考來源
http://qinfei.lexinsmart.com/2015/09/mosquitto%E5%8D%8F%E8%AE%AE%E4%B9%8Bmosquitto-conf5-%E4%BB%A3%E7%90%86%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%85%8D%E7%BD%AE/

2016年6月22日 星期三

Mosquitto + Ubuntu 14.02 Source install

Source code

https://github.com/eclipse/mosquitto


環境 : VMware + putty

sudo apt-get install openssh-server gcc openssl

sudo apt-get install libssl-dev build-essential zlibc zlib-bin libidn11-dev libidn11


./mosquitto_internal.h:51:12: fatal error: 'ares.h' file not found

wget http://c-ares.haxx.se/download/c-ares-1.10.0.tar.gz

tar -zxf c-ares-1.10.0.tar.gz

cd c-ares-1.10.0

./configure

sudo make install


uuid.h

sudo apt-get install uuid-dev


xsltproc: Command not found

sudo apt-get install xsltproc

/usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl

sudo apt-get install  docbook-xsl

libmosquitto.so.1 not find

su

cat /etc/ld.so.conf

echo "/usr/local/lib" >> /etc/ld.so.conf

ldconfig

exit

回到mosquitto資料夾

sudo make

sudo make install

done

mosquitto -v
    【-v】打印更多的调试信息

mosquitto_sub -v -t test
    【-t】指定主题,此处为test
    【-v】打印更多的调试信息

mosquitto_pub -t test  -m test123


參考來源
http://blog.csdn.net/yajun0601/article/details/41982583
http://houjixin.blog.163.com/blog/static/3562841020156142544694/
http://www.360doc.com/content/14/1010/17/12928831_415836429.shtml
http://www.openchange.org/cookbook/initializing.html
http://m.blog.csdn.net/article/details?id=51395812

Ubuntu Samba setup

安裝Samba
sudo apt-get install samba
設定Samba 
編輯 /etc/samba/smb.conf
 
(1)
[global]
workgroup = root
security = share
 
(2)尾部加入
[分享資料夾的名稱]
path = 分享資料夾的路徑
writable = yes
guest account = root
force user = root
public = yes
force group = root
 
[3]重新啟動 Samba Server
sudo /etc/init.d/samba restart
 
[4]Windows設定
在網路上的芳鄰圖示下按右鍵,
 "連線網路磁碟機"
磁碟機: 任選
資料夾: \\Ubuntu下所設IP\分享資料夾的名稱

參考
http://flykof.pixnet.net/blog/post/23028119-ubuntu%E4%B8%8Bsamba%E5%AE%89%E8%A3%9D%E8%A8%AD%E5%AE%9A

VMware Workstation12 + ssh + putty


1.安裝 OpenSSH Server 


sudo apt-get install openssh-server


2.取消 root 的登入權限

打開 /etc/ssh/sshd_config

PermitRootLogin No


3.設定可以連線的主機

打開 /etc/hosts.allow 

sshd:XXX.XXX.X.X:allow

打開 /etc/hosts.deny

sshd:all:deny


4.重啟 SSH Server

sudo /etc/init.d/ssh restart

參考來源
http://www.arthurtoday.com/2010/08/ubuntu-ssh.html

2016年6月21日 星期二

安裝 mingw

參考http://itspg.github.io/blog/2012/04/06/windows-gnu-tutorial/

1.下載mingw-w64-install

2.安裝時選 x86_64 其他預設

我的電腦右鍵 -> 內容 -> 環境變數 -> PATH -> 增加

C:\Program Files\mingw-w64\x86_64-5.3.0-posix-seh-rt_v4-rev0\mingw64\bin

(順便將此目錄底下的mingw32-make.exe改成make.exe)

以及

C:\MinGW\bin


3.開新檔案 a.bat 內容cmd

4.啟動a.bat

5.執行 gcc -v

6.開新檔案 a.cpp

內容

#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World " << endl;
}

7.執行a.bat

8.輸入g++ -o filename.exe filename.cpp

就會把filename.cpp編譯成 filename.exe

2016年6月20日 星期一

強制關閉趨勢防毒

公司電腦有鎖防毒,

有時候一定要連某些PORT來做事,

又被擋

只好...


控制台-系統管理工具-服務

把Officer scan開頭的停用掉即可