mndrj

motor gprs

May 11th, 2018
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2. SoftwareSerial gprsSerial(9, 10);// tx rx
  3. //int ledPin = 13;
  4. //int EP =11;
  5. long randNumber;
  6. int count=1;
  7. char buff[105];
  8. void(* resetFunc) (void) = 0; //declare reset function @ address 0
  9. void setup()
  10. {
  11.  
  12. randomSeed(analogRead(0));
  13. gprsSerial.begin(19200);
  14. Serial.begin(19200);
  15.  
  16. Serial.println("Config SIM900...");
  17. delay(2000);
  18. Serial.println("Done!...");
  19. gprsSerial.flush();
  20. Serial.flush();
  21.  
  22. //attach or detach from GPRS service
  23. gprsSerial.println("AT+CGATT?");
  24. delay(100);
  25. toSerial();
  26.  
  27.  
  28. // bearer settings
  29. gprsSerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  30. delay(2000);
  31. toSerial();
  32.  
  33. // bearer settings
  34. gprsSerial.println("AT+SAPBR=3,1,\"internet\",\"xxxx\"");
  35. delay(2000);
  36. toSerial();
  37.  
  38. // bearer settings
  39. gprsSerial.println("AT+SAPBR=1,1");
  40. delay(2000);
  41. toSerial();
  42. }
  43.  
  44. void loop()
  45. {
  46.  
  47. randNumber = random(300);
  48. randNumber = random(10, 20);
  49. delay(50);
  50.  
  51.  
  52. // initialize http service
  53. gprsSerial.println("AT+HTTPINIT");
  54. delay(2000);
  55. toSerial();
  56.  
  57. char song[] = {'c', 'd',' ', 'e', 'f',' ', 'g', 'a', 'b', 'C',' '};
  58. char fs[10];
  59. int lengthh=10;
  60. Serial.println(count);
  61. int i;
  62. if(count==1){
  63. for(i = 0;i < lengthh; i++){
  64.  
  65. fs[i] = song[random (0, 10)];
  66.  
  67. }
  68. }
  69.  
  70. String str(fs);
  71. String stringOne = "http://148.251.158.132/tempsensor/logger.php?temp1="+str;
  72. gprsSerial.println("AT+HTTPPARA=\"URL\","+stringOne);
  73. count++;
  74. delay(2000);
  75. toSerial();
  76. //count++;
  77. // set http action type 0 = GET, 1 = POST, 2 = HEAD
  78. gprsSerial.println("AT+HTTPACTION=0");
  79. delay(6000);
  80. toSerial();
  81.  
  82. // read server response
  83. gprsSerial.println("AT+HTTPREAD");
  84. delay(1000);
  85. toSerial();
  86.  
  87. gprsSerial.println("");
  88. gprsSerial.println("AT+HTTPTERM");
  89. toSerial();
  90. delay(300);
  91.  
  92. gprsSerial.println("");
  93. delay(10000);
  94. resetFunc(); //call reset
  95. }
  96.  
  97. void toSerial()
  98. {
  99. while(gprsSerial.available()!=0)
  100. {
  101. Serial.write(gprsSerial.read());
  102. }
  103. }
Add Comment
Please, Sign In to add comment