Sunday, 1 March 2015

Arduino dirt cheap wifi solution -- ESP8266 (arduino code call http restful endpoint)


See the circuit connection first, I believe you can make your circuit by my photos:






See the log first:





This is my http restful server log:

The log proves that the endpoint was accessed.


If the endpoint accessed by bowser:



Let's see the Arduino code first:

#include 
SoftwareSerial WIFISerial(8, 9); // RX, TX
void setup()
{
  Serial.begin(9600);
   
  WIFISerial.begin(9600);
  delay(2000);
  int i = 0;
  for(i = 15 ; i >0 ; i--){
    xx();
  }
  WIFISerial.println("AT+RST");
  delay(2000);
  for(i = 190 ; i >0 ; i--){
    xx();
  }
  WIFISerial.println("AT+CWMODE=1"); //ap+sta mode
  delay(2000);
  for(i = 90 ; i >0 ; i--){
    xx();
  }
  WIFISerial.println("AT+CWJAP=\"Cisco05642\",\"ASDFZXCV\""); //connect to router!
  delay(3000);
  for(i = 160 ; i >0 ; i--){
    xx();
  }
  WIFISerial.println("AT+CIFSR"); //connect to router!
  delay(3000);
  for(i = 160 ; i >0 ; i--){
    xx();
  }
  WIFISerial.println("AT+CIPMUX=1"); //connect to router!
  delay(3000);
  for(i = 160 ; i >0 ; i--){
    xx();
  }
  WIFISerial.println("AT+CIPSTART=4,\"TCP\",\"192.168.1.102\",9000");
  delay(3000);
  for(i = 160 ; i >0 ; i--){
    xx();
  }
  WIFISerial.println("AT+CIPSEND=4,28");
  delay(3000);
  for(i = 160 ; i >0 ; i--){
    xx();
  }
  WIFISerial.println("GET /api/things HTTP/1.0\r\n");
  delay(3000);
  for(i = 1360 ; i >0 ; i--){
    xx();
  }
}

void xx(){
 
   
 if (WIFISerial.available()){
    Serial.write(WIFISerial.read());}
  if (Serial.available()){
    WIFISerial.write(Serial.read());
}

}
 
void loop(){
 
//   
// if (WIFISerial.available()){
//    Serial.write(WIFISerial.read());}
//  if (Serial.available()){
//    WIFISerial.write(Serial.read());
//}
//   
   
//       WIFISerial.println("AT+CIFSR"); //connect to router!
//  delay(4000);
}























































No comments:

Post a comment