RF

#include <SPI.h>  
#include <Ethernet.h>  
#include <Wire.h> 
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress serverIP(172,25,60,127); // IP Adress to our Server
int serverPort=56787;
String stringOne ;
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to
EthernetClient client;

void setup() {
  // start the serial for debugging
  Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  // give the Ethernet shield a second to initialize:
  
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:
  

  //Serial.println("connecting to Server ...");

  // if you get a connection to the Server
  if (client.connect(serverIP, serverPort)) {
    Serial.println("connected");//report it to the Serial
    String msg="I,8,67005AC948;";//Message to be sent
    Serial.println("sending Message:"+msg);//log to serial
    client.println(msg);//send the message
  }

  
  
  
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
    stringOne=stringOne+c;
    if(c==';'){
          Serial.println(stringOne.indexOf('CLOSE'));
      if(stringOne.indexOf('CLOSE')>0){
           Serial.println("shutdown the door");
      }
      client.stop();
      
      Serial.println("disconnected");
    }
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();//report it to the serial
    Serial.println("disconnected");
    client.stop();
     for(;;)
      ;

  }
}
#include <SPI.h>  
#include <Ethernet.h>  
#include <Wire.h> 
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress serverIP(172,25,60,127); // IP Adress to our Server
int serverPort=56787;
String stringOne ;
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to
EthernetClient client;
  String flag1 ="N";
          int ledPin1=8; //设定控制LED的数字IO脚
          
void setup() {
  // start the serial for debugging
  Serial.begin(9600);
   pinMode(ledPin1,OUTPUT);//设定数字IO口的模式,OUTPUT 为输出
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  // give the Ethernet shield a second to initialize:
  
  digitalWrite(ledPin1,HIGH); 
  delay(1000);
  digitalWrite(ledPin1,LOW); 

}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:
  



  // if you get a connection to the Server
  if (client.connect(serverIP, serverPort)) {
    Serial.println("connected");//report it to the Serial
    String msg="I,8,67005AC948;";//Message to be sent
    Serial.println("sending Message:"+msg);//log to serial
    client.println(msg);//send the message
  }

  
  
  while(true){
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
    stringOne=stringOne+c;
    if(c==';'){
          Serial.println(stringOne.indexOf('CLOSE'));
      if(stringOne.endsWith("OPEN;")){
           Serial.println("shutdown the door");
           digitalWrite(ledPin1,HIGH); 
      }
      client.stop();
  
      Serial.println("disconnected");
          break;
    }
  }
  }
  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();//report it to the serial
    Serial.println("disconnected");
    client.stop();
     for(;;)
      ;

  }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值