微信クライアント+微信公衆プラットフォーム+新浪雲SAE+Arduino+WS 100(制御LED)


ステップ1:準備
1、スマートフォンの微信クライアント或いは微信コンピュータ版
2、微信公衆プラットフォームの登録
https://mp.weixin.qq.com
3、新浪アカウントの登録
http://www.sinacloud.com
4、一つのArduino UNO R 3を持つ
http://item.jd.com/1593883356.html
5、WS 100を持っている
https://item.taobao.com/item.htm?spm=a1z09.2.0.0.NJ6mUE&id=528047071612&_u=4p210bab347
ステップ2:ワークフロー
  微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)_第1张图片 微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)_第2张图片
ステップ3:作業開始
手順1:ハードウェアセクション
1)、Arduino、WS 100、ケーブル、ルーター.
2)、ルータの設定
  微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)_第3张图片
微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)_第4张图片
下図のmacとIPはArduinoデバイスに割り当てられています(必須ではなく、検証されていません)
  微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)_第5张图片
3)、Arduino設備プログラムの記録
Arduino IDE
https://www.arduino.cc/en/Main/Software
Eclipse IDE
http://eclipse.baeyens.it/download.php(付属のarduinoのプラグインが含まれており、eclipseのインストール前にJDKと環境変数の構成が必要です)
Arduinoコード
#include "Arduino.h"
#include 
#include 


char state = '0';
char c;
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192,168,3,2);

IPAddress myDns(192,168,3,1);

EthernetClient client;

char server[] = "    ";
int sensrdata = 50;

unsigned long lastConnectionTime = 0;
boolean lastConnected = false;
const unsigned long postingInterval = 200*1000;

//The setup function is called once at startup of the sketch
void setup()
{
// Add your initialization code here
	  Serial.begin(9600);
	  delay(1000);
	  Ethernet.begin(mac, ip, myDns);
	  Serial.print("My IP address: ");
	  Serial.println(Ethernet.localIP());
	  pinMode(13, OUTPUT);
	  pinMode(7, OUTPUT);
}

// The loop function is called in an endless loop
void loop()
{
//Add your repeated code here
	  while(client.available()) {
		  state = client.read();
		if(state == '{'){				//  	0
			Serial.println(state);
			digitalWrite(13, LOW);
			digitalWrite(7, HIGH);
			delay(9000);
		  }else if(state == '}'){		//  	1
			Serial.println(state);
			digitalWrite(13, HIGH);
			digitalWrite(7, LOW);
			delay(9000);
		  }
	  }

	  if (!client.connected() && lastConnected) {
	    Serial.println("disconnecting 2.");
	    client.stop();
	  }

	  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
	    if (client.connect(server, 80)) {

	    	Serial.println("connecting");
	      // send the HTTP PUT request:
	      client.print("GET /downup.php?token=  Token&data=");
	      client.print(sensrdata);
	      client.println(" HTTP/1.1");
	      client.println("Host:     ");
	      client.println("User-Agent: arduino-ethernet");
	      client.println("Connection: close");
	      client.println();

	      lastConnectionTime = millis();
	    }else {
	      Serial.println("connection failed");
	      Serial.println("disconnecting 1.");
	      client.stop();
	    }
	  }
	  lastConnected = client.connected();
}

手順2:サーバー側
1)、新浪雲SAE
  微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)_第6张图片 微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)_第7张图片
データベース構築
微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)_第8张图片 微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)_第9张图片
index.phpコード
");
        echo "wrong input!";
        exit(0);
}
 
//  XML
$fromUserName = $xmlObj-?>FromUserName;
$toUserName = $xmlObj->ToUserName;
$msgType = $xmlObj->MsgType;
 
 
if($msgType == 'voice') {//       
        $content = $xmlObj->Recognition;
}elseif($msgType == 'text'){
        $content = $xmlObj->Content;
}else{
        $retMsg = '          ';
}
 
if (strstr($content, "  ")) {
        $con = mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS); 
        mysql_select_db("       ", $con);//      
 
        $result = mysql_query("SELECT * FROM sensor");
        while($arr = mysql_fetch_array($result)){
          if ($arr['ID'] == 1) {
                  $tempr = $arr['data'];
          }
        }
        mysql_close($con);
 
    $retMsg = "  :"."
"." ".$tempr."!"; }else if (strstr($content, " LED")) { $con = mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS); $dati = date("h:i:sa"); mysql_select_db(" ", $con);// $sql ="UPDATE switch SET timestamp='$dati',state = '1' WHERE ID = '1'";// if(!mysql_query($sql,$con)){ die('Error: ' . mysql_error()); }else{ mysql_close($con); $retMsg = "OK"; } }else if (strstr($content, " LED")) { $con = mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS); $dati = date("h:i:sa"); mysql_select_db(" ", $con);// $sql ="UPDATE switch SET timestamp='$dati',state = '0' WHERE ID = '1'";// if(!mysql_query($sql,$con)){ die('Error: ' . mysql_error()); }else{ mysql_close($con); $retMsg = "OK"; } }else{ $retMsg = " "; } // XML $retTmp = " %s 0 "; $resultStr = sprintf($retTmp, $fromUserName, $toUserName, time(), $retMsg); // echo $resultStr; ?>

downup.phpコード

2)、微信公衆プラットフォーム微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)_第10张图片
手順3:ネットワーク接続のテスト
ハードウェアIP(イントラネット):192.168.3.2
ハードウェアDNS(イントラネット):192.168.3.1
ワークコンピュータIP(イントラネット):192.168.3.100
新浪雲住所:http://1.gamesalad.applinzi.com/
新浪クラウドポート:80または443
微信TOKEN:自己定義
WeChatのサーバURL:http://1.gamesalad.applinzi.com/index.php
  微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)_第11张图片
手順4:デバッグ手段
ハードウェア:シリアルポート出力を採用
  微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)_第12张图片
サーバ側:
  微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)_第13张图片
注意:このケースでは、複数のプロセスについて説明します.段階的にデバッグしてください.
微信クライアントと新浪クラウドデータのインタラクション(データベースの値を表示することによってインタラクション状況を判断する)
ハードウェアと新浪クラウドのインタラクション(データベースの値を表示することでインタラクションを判断)
ステップ4:
微信客户端+微信公众平台+新浪云SAE+Arduino+WS100(控制LED)_第14张图片