Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. I want to ask how to send data to more than one database, when I managed to send data to the database, the data sent is not the result of sensors joining a single column, but I have created two columns to hold each data with different variables.
  2.  
  3. #include <SPI.h>
  4. #include <MFRC522.h>
  5. #define nama_wifi "Wifi"
  6. #define pass_wifi "1gakada123"
  7. #define ip_host "192.168.137.1"
  8.  
  9. boolean connected = false;
  10. #define isObstaclePin1 2 // This is our input pin
  11. #define isObstaclePin2 3
  12. int isObstacle1 = HIGH; // HIGH MEANS NO OBSTACLE
  13. int isObstacle2 = HIGH;
  14. int value1;
  15. int value2;
  16. void setup() {
  17.  
  18. // put your setup code here, to run once:
  19. pinMode(isObstaclePin1, INPUT);
  20. pinMode(isObstaclePin2, INPUT);
  21. Serial1.begin(115200);
  22. Serial.begin(9600);
  23. Serial1.setTimeout(5000);
  24. Serial.println("CHECK ESP8266");
  25. delay (1000);
  26. Serial1.println("AT+RST");
  27. delay(1000);
  28. if(Serial1.find("WIFI GOT IP"))
  29. {
  30. Serial.println("ESP8266 Ready To Use");
  31. }
  32. else {
  33. Serial.println(" No Response from ESP8266 ");
  34. while(1);
  35. }
  36. delay(1000);
  37.  
  38. for (int i=0; i<5; i++){
  39. connect_to_wifi();
  40. if (connected){
  41. break;
  42. }
  43. }
  44. if (!connected){
  45. while(1);
  46. }
  47. delay(5000);
  48. Serial1.println("AT+CIPMUX=0");
  49. delay(1000);
  50. }
  51.  
  52. void loop() {
  53. // put your main code here, to run repeatedly:
  54. String cmd = "AT+CIPSTART="TCP","";
  55. cmd+= ip_host;
  56. cmd+="",80";
  57. Serial1.println(cmd);
  58. Serial.println(cmd);
  59. if (Serial1.find("Error")){
  60. Serial.println("Koneksi eror");
  61. return;
  62. }
  63.  
  64. isObstacle1 = digitalRead(isObstaclePin1);
  65. isObstacle2 = digitalRead(isObstaclePin2);
  66. value1=isObstacle1;
  67. value2=isObstacle2;
  68. infra1();
  69. infra2();
  70. cmd = "GET /arduinovb/index.php?data1&data2=";
  71. cmd +=value1;
  72. cmd +=value2;
  73. cmd +="HTTP/1.0/1/rn";
  74. cmd +="rn";
  75.  
  76. Serial1.print("AT+CIPSEND=");
  77. Serial1.println(cmd.length());
  78. if (Serial1.find(">")){
  79. Serial.print(">");
  80. } else {
  81. Serial1.println("AT+CIPCLOSE");
  82. Serial.println("Koneksi Timeout");
  83. delay(1000);
  84. return;
  85. }
  86. Serial1.print(cmd);
  87. delay(2000);
  88.  
  89. while(Serial1.available())
  90. {
  91. char c =Serial1.read();
  92. Serial.write(c);
  93. if (c=='r') Serial.print('n');
  94. }
  95. Serial.println("-----end");
  96. delay(10000);
  97. }
  98.  
  99. void connect_to_wifi()
  100. {
  101. Serial1.println("AT+CWMODE=1");
  102. String cmd = "AT+CWJAP="";
  103. cmd+=nama_wifi;
  104. cmd+="","";
  105. cmd+=pass_wifi;
  106. cmd+=""";
  107. Serial1.println(cmd);
  108. Serial.println(cmd);
  109. if (Serial1.find("OK")){
  110. Serial.println("Connect To Internet");
  111. connected=true;
  112. } else {
  113. Serial.println("Failed to connect");
  114. connected=false;
  115. }
  116. }
  117.  
  118. void infra1(){
  119. if (isObstacle1 == LOW)
  120. {
  121. Serial.println(isObstacle1);
  122. }
  123. else
  124. {
  125. Serial.println(isObstacle1);
  126. }
  127. delay(5000);
  128. }
  129.  
  130. void infra2(){
  131. if (isObstacle2 == LOW)
  132. {
  133. Serial.println(isObstacle2);
  134. }
  135. else
  136. {
  137. Serial.println(isObstacle2);
  138. }
  139. delay(5000);
  140. }
  141.  
  142. <?php
  143. include ("koneksi.php");
  144. $var1 = $_GET['data1'];
  145. $var2 = $_GET['data2'];
  146.  
  147. mysqli_query($konek, "INSERT INTO tbl_blogs(title,description) VALUES('$var1','$var2')");
  148. ?>
  149.  
  150. <?php
  151. $servername = "localhost";
  152. $database = "blog";
  153. $username = "root";
  154. $password = "";
  155. $konek = mysqli_connect ($servername, $username, $password, $database);
  156.  
  157. if ($konek!=false){
  158. echo "berhasil";
  159. } else {
  160. echo "gagal";}
  161.  
  162. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement