SHARE
TWEET

SIM5320

a guest May 19th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unsigned long nMillis, oMillis;
  2. char buf[100];
  3.  
  4. void setup() {
  5.   // put your setup code here, to run once:
  6.     Serial.begin(115200);
  7.     Serial3.begin(4800);
  8.     pinMode(39, OUTPUT);
  9.    
  10.     rstModem();
  11.     openConnect();
  12.    
  13. }
  14. void loop() {
  15.   // put your main code here, to run repeatedly:
  16.     nMillis = millis();
  17.     if ( nMillis - oMillis >= 3000){    
  18.       pushData();
  19.        
  20.       oMillis = nMillis;
  21.     }
  22. }
  23.  
  24. String waitRespon(){
  25.   String txt;
  26.   while (!Serial3.available()){}
  27.   while (Serial3.available()) {
  28.     txt = Serial3.readString();
  29.   }
  30.   return txt;
  31. }
  32.  
  33. bool replayOK(){
  34.   String txt; int len;
  35.   bool i;
  36.   while(!Serial3.available()){}
  37.   while (Serial3.available()){
  38.     txt = Serial3.readString();
  39.   }
  40.   len = txt.length();
  41.   //Serial.print("len: ");
  42.   //Serial.println(len);
  43.   txt.toCharArray(buf, len);
  44.   txt = "";
  45.   txt = String(buf[len-4]) + buf[len-3];
  46.   if ( txt == "OK" ){
  47.     i = true;
  48.   }else{
  49.     i = false;
  50.   }
  51.   return i;
  52. }
  53.  
  54. void rstModem(){
  55.     int i;
  56.     char dt[8];
  57.     digitalWrite(39, HIGH);
  58.     delay(1000);
  59.     digitalWrite(39, LOW);
  60.     delay(1000);
  61.     digitalWrite(39, HIGH);
  62.     while (!Serial3.available()){}
  63.  
  64.     nMillis = millis();
  65.     oMillis = nMillis;
  66.     while ( nMillis - oMillis < 15000){
  67.       nMillis = millis();
  68.       while(Serial3.available()){
  69.         Serial.println(Serial3.readString());
  70.       }
  71.     }
  72.     Serial.println(F("Restart Sukses"));
  73.     oMillis = nMillis;
  74. }
  75.  
  76. bool reg(){
  77.   bool sts;
  78.   String txt; int len;
  79.   int dt, i;
  80.   Serial3.println("AT+CFUN?");
  81.   txt = waitRespon();
  82.   len = txt.length();
  83.   txt.toCharArray(buf,len);
  84.   for ( i = 0; i < len; i++){
  85.     //Serial.print(i);
  86.     //Serial.println(buf[i]);
  87.     if( buf[i] == ':'){
  88.       break;
  89.     }
  90.   }
  91.   txt = "";
  92.   txt = String(buf[i+2]);
  93.   dt = txt.toInt();
  94.   if ( dt != 1){
  95.     Serial3.println("AT+CFUN=1");
  96.     if (!replayOK){
  97.       delay(5000);
  98.       return;
  99.     }
  100.   }
  101.   if ( dt == 1 ){
  102.     sts = true;
  103.   }else{
  104.     sts = false;
  105.   }
  106.   return sts;
  107. }
  108.  
  109. void inSSL(){
  110.   String txt; bool i;
  111.   Serial3.println("AT+CGPSSSL=1");
  112.   wRespon(2000);
  113.  
  114.  
  115.   Serial.println("SSL");
  116.   delay(1000);
  117.   Serial3.println("AT+CCERTLIST");
  118.   wRespon(2000);
  119.  
  120. }
  121.  
  122. void openConnect(){
  123.   delay(500);
  124.   Serial3.println("AT+CFUN?");
  125.   wRespon(1000);
  126.  
  127.   delay(500);
  128.   Serial3.println("AT+CREG?");
  129.   wRespon(1000);
  130.  
  131.   delay(500);
  132.   Serial3.println("AT+CGATT=1");
  133.   wRespon(1000);
  134.  
  135.  
  136.    delay(500);
  137.    Serial3.println("AT+CGSOCKCONT=1,\"IP\",\"Internet\"");
  138.    wRespon(1000);
  139.  
  140.    delay(1000);
  141.    Serial3.println("AT+CPSI?");
  142.    wRespon(5000);
  143. }
  144.  
  145. void pushData(){
  146.    int len; String txt;  
  147.    String url = "id=01&tgl=2019/3/29&jam=5:17:10";
  148.           url += "&van=223&vbn=112&vcn=111&vab=111&vac=0";
  149.           url += "&vbc=111&ca=0&cb=0&cc=0&cn=0&lu=0&kwh=0";
  150.           url += "&f=50&t=29&h=69&r1=1&s1=1&t1=1&r2=1";
  151.           url += "&s2=1&t2=1&r3=1&s3=1&t3=1&r4=1&s4=1&t4=1\r";
  152.           len = url.length();
  153.    
  154.    Serial3.println("AT+CHTTPACT=\"example.com\",80");
  155.    wRespon(5000);
  156.    Serial3.print(F("POST http://example.com/pln/i.php HTTP/1.1\r\n"));
  157.    Serial3.print(F("Host: example.com\r\n"));
  158.    Serial3.print(F("User-Agent: MY WEB AGENT\r\n"));
  159.    Serial3.print(F("Accept: */*\r\n"));
  160.    Serial3.print(F("Content-Type: application/x-www-form-urlencoded\r\n"));
  161.    Serial3.print(F("Cache-Control: no-cache\r\n"));
  162.    Serial3.print(F("Accept-Charset: utf-8, us-ascii\r\n"));
  163.    Serial3.print(F("Pragma: no-cache\r\n"));
  164.    Serial3.print(String("Content-Length: ") + len + "\r\n\r\n");
  165.    Serial3.println(url);
  166.    Serial3.print(char(0x1A));
  167.    wRespon(15000);
  168. }
  169.  
  170. void wRespon(unsigned long waktu){
  171.   nMillis = millis();
  172.    oMillis = nMillis;
  173.    while ( nMillis - oMillis < waktu){
  174.     nMillis = millis();
  175.     while(Serial3.available()){
  176.       Serial.println(Serial3.readString());
  177.     }
  178.    }
  179. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top