Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- #include <SPI.h>
- #include <MFRC522.h>
- #define nama_wifi "Wifi"
- #define pass_wifi "1gakada123"
- #define ip_host "192.168.137.1"
- boolean connected = false;
- #define isObstaclePin1 2 // This is our input pin
- #define isObstaclePin2 3
- int isObstacle1 = HIGH; // HIGH MEANS NO OBSTACLE
- int isObstacle2 = HIGH;
- int value1;
- int value2;
- void setup() {
- // put your setup code here, to run once:
- pinMode(isObstaclePin1, INPUT);
- pinMode(isObstaclePin2, INPUT);
- Serial1.begin(115200);
- Serial.begin(9600);
- Serial1.setTimeout(5000);
- Serial.println("CHECK ESP8266");
- delay (1000);
- Serial1.println("AT+RST");
- delay(1000);
- if(Serial1.find("WIFI GOT IP"))
- {
- Serial.println("ESP8266 Ready To Use");
- }
- else {
- Serial.println(" No Response from ESP8266 ");
- while(1);
- }
- delay(1000);
- for (int i=0; i<5; i++){
- connect_to_wifi();
- if (connected){
- break;
- }
- }
- if (!connected){
- while(1);
- }
- delay(5000);
- Serial1.println("AT+CIPMUX=0");
- delay(1000);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- String cmd = "AT+CIPSTART="TCP","";
- cmd+= ip_host;
- cmd+="",80";
- Serial1.println(cmd);
- Serial.println(cmd);
- if (Serial1.find("Error")){
- Serial.println("Koneksi eror");
- return;
- }
- isObstacle1 = digitalRead(isObstaclePin1);
- isObstacle2 = digitalRead(isObstaclePin2);
- value1=isObstacle1;
- value2=isObstacle2;
- infra1();
- infra2();
- cmd = "GET /arduinovb/index.php?data1&data2=";
- cmd +=value1;
- cmd +=value2;
- cmd +="HTTP/1.0/1/rn";
- cmd +="rn";
- Serial1.print("AT+CIPSEND=");
- Serial1.println(cmd.length());
- if (Serial1.find(">")){
- Serial.print(">");
- } else {
- Serial1.println("AT+CIPCLOSE");
- Serial.println("Koneksi Timeout");
- delay(1000);
- return;
- }
- Serial1.print(cmd);
- delay(2000);
- while(Serial1.available())
- {
- char c =Serial1.read();
- Serial.write(c);
- if (c=='r') Serial.print('n');
- }
- Serial.println("-----end");
- delay(10000);
- }
- void connect_to_wifi()
- {
- Serial1.println("AT+CWMODE=1");
- String cmd = "AT+CWJAP="";
- cmd+=nama_wifi;
- cmd+="","";
- cmd+=pass_wifi;
- cmd+=""";
- Serial1.println(cmd);
- Serial.println(cmd);
- if (Serial1.find("OK")){
- Serial.println("Connect To Internet");
- connected=true;
- } else {
- Serial.println("Failed to connect");
- connected=false;
- }
- }
- void infra1(){
- if (isObstacle1 == LOW)
- {
- Serial.println(isObstacle1);
- }
- else
- {
- Serial.println(isObstacle1);
- }
- delay(5000);
- }
- void infra2(){
- if (isObstacle2 == LOW)
- {
- Serial.println(isObstacle2);
- }
- else
- {
- Serial.println(isObstacle2);
- }
- delay(5000);
- }
- <?php
- include ("koneksi.php");
- $var1 = $_GET['data1'];
- $var2 = $_GET['data2'];
- mysqli_query($konek, "INSERT INTO tbl_blogs(title,description) VALUES('$var1','$var2')");
- ?>
- <?php
- $servername = "localhost";
- $database = "blog";
- $username = "root";
- $password = "";
- $konek = mysqli_connect ($servername, $username, $password, $database);
- if ($konek!=false){
- echo "berhasil";
- } else {
- echo "gagal";}
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement