Advertisement
microrobotics

SIM808-TCP-TEST

Jun 14th, 2017
3,989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.45 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2.  
  3. SoftwareSerial mySerial(7, 8);
  4. #include<stdio.h>
  5. #include<string.h>
  6. #define DEBUG true
  7. int pon=9;
  8. void setup()
  9. {
  10.   Serial.begin(9600);
  11.   mySerial.begin(9600);
  12.   delay(1000);
  13.   pinMode(pon, OUTPUT);
  14.   digitalWrite(pon, HIGH);
  15.   delay(3000);
  16.   digitalWrite(pon, LOW);
  17.   delay(1000);
  18.   Serial.println("After 3s, test begin!!");
  19.   delay(3000);  
  20. }
  21.  
  22. void loop()
  23. {
  24.      sendData("AT+CCID",3000,DEBUG);
  25.      sendData("AT+CREG?",3000,DEBUG);    
  26.      sendData("AT+CGATT=1",1000,DEBUG);
  27.      sendData("AT+CGACT=1,1",1000,DEBUG);
  28.      sendData("AT+CSTT=CMNET",3000,DEBUG);
  29.      sendData("AT+CIICR",1000,DEBUG);
  30.      sendData("AT+CIFSR",1000,DEBUG);
  31.       sendData("AT+CDNSGIP=\"www.sim.com\"",1000,DEBUG);
  32.       sendData("AT+CDNSGIP=\"a b c d e f\"",1000,DEBUG);
  33.       sendData("AT+CIPSTART=\"TCP\",\"WWW.SIM.COM\",80",5000,DEBUG);
  34.       delay(10000);
  35.       sendData("AT+CIPSEND=6",1000,DEBUG);
  36.       sendData("123456",1000,DEBUG);
  37.      delay(2000);
  38.      sendData("AT+CIPCLOSE",1000,DEBUG);
  39. }
  40.  
  41. String sendData(String command, const int timeout, boolean debug)
  42. {
  43.     String response = "";    
  44.     mySerial.println(command);
  45.     long int time = millis();  
  46.     while( (time+timeout) > millis())
  47.     {
  48.       while(mySerial.available())
  49.       {      
  50.         char c = mySerial.read();
  51.         response+=c;
  52.       }  
  53.     }    
  54.     if(debug)
  55.     {
  56.       Serial.print(response);
  57.     }    
  58.     return response;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement