Guest User

Untitled

a guest
Jan 17th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. char* text;
  2. char* number;
  3. bool error; //to catch the response of sendSms
  4.  
  5.  
  6. void setup(){
  7. GSM.begin(4800);
  8. text="Testing Sms"; //text for the message.
  9. number="2926451386"; //change to a valid number.
  10. error=SIM800L .sendSms(number,text);
  11. }
  12.  
  13. #include <Sim800L.h>
  14. #include <SoftwareSerial.h>
  15. #include <UIPEthernet.h>
  16.  
  17. #define RX 10
  18. #define TX 11
  19.  
  20. Sim800L GSM(RX, TX);
  21.  
  22. int buzzer = 8;
  23. int smokeA0 = A5;
  24. int smokeA1 = A4;
  25. int smokeA2 = A3;
  26.  
  27. int sensorThres1 = 650;
  28. int sensorThres2 = 500;
  29. int sensorThres3 = 500;
  30.  
  31.  
  32. byte mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};
  33. EthernetClient client;
  34. char server[] = "192.168.2.100";
  35. int interval = 5000;
  36. char uid[] = "1";
  37. String response = String(100);
  38. char* text;
  39. char* number;
  40.  
  41. void setup() {
  42.  
  43. pinMode(buzzer, OUTPUT);
  44. pinMode(smokeA0, INPUT);
  45. pinMode(smokeA1, INPUT);
  46. pinMode(smokeA2, INPUT);
  47.  
  48.  
  49. Serial.begin(9600);
  50. Ethernet.begin(mac);
  51.  
  52. Serial.print("IP Address : ");
  53. Serial.println(Ethernet.localIP());
  54. GSM.begin(4800);
  55. }
  56.  
  57. void loop() {
  58. int analogSensor1 = analogRead(smokeA0);
  59. int analogSensor2 = analogRead(smokeA1);
  60. int analogSensor3 = analogRead(smokeA2);
  61.  
  62.  
  63. if (analogSensor1 > sensorThres1 || analogSensor2 > sensorThres2 || analogSensor3 > sensorThres3){
  64.  
  65. if(client.connect(server, 80)){
  66. Serial.println("-> Connected");
  67. // Make a HTTP request:
  68. client.print( "GET /apartment/insert.php?");
  69. client.print("uid=");
  70. client.print(uid);
  71. client.println( " HTTP/1.1");
  72. client.print( "Host: " );
  73. client.println(server);
  74. client.println( "Connection: close" );
  75. client.println();
  76. client.println();
  77.  
  78. while (client.connected()) {
  79. if (client.available()) {
  80. char c = client.read();
  81. //Serial.print(c);
  82. response= response + c;
  83. }
  84. }
  85.  
  86. int contentBodyIndex = response.lastIndexOf('n');
  87. if (contentBodyIndex > 0) {
  88. number = response.substring(contentBodyIndex); // THE ERROR POINTS TO THIS LINE OF CODE
  89. Serial.print(number);
  90. text = "Smoke was detected in your apartment unit";
  91. Sim800L.sendSms(number,text);
  92. }
  93.  
  94.  
  95.  
  96. client.stop();
  97. delay(1000);
  98. tone(buzzer, 1000);
  99. delay(10000);
  100. noTone(buzzer);
  101. delay(1000);
  102. }else{
  103. Serial.println("--> connection failed/n");
  104. }
  105. }
  106. else
  107. {
  108. noTone(buzzer);
  109. }
  110. delay(1000);
  111. }
Add Comment
Please, Sign In to add comment