#include <Ethernet.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <avr/pgmspace.h>
int SensorPin1 = A0; //analog pin 0
int SensorPin2 = A1; //analog pin 0
int SensorPin3 = A2; //analog pin 0
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr(); // mysql
char user[] = ""; // mysql user
char password[] = ""; // mysql password
// Sample query
EthernetClient client;
MySQL_Connection conn((Client *)&client);
void setup() {
Serial.begin(9600);
while (!Serial); // wait for serial port to connect
Ethernet.begin(mac_addr);
Serial.println("Connecting...");
if (conn.connect(server_addr, 3306, user, password)) {
delay(1000);
}
else
Serial.println("Connection failed.");
}
void loop() {
delay(2000);
int SensorReading1 = analogRead(SensorPin1);
int SensorReading2 = analogRead(SensorPin2);
int SensorReading3 = analogRead(SensorPin3);
int mfsr_r18 = map(SensorReading1, 0, 1024, 0, 255);
if ( mfsr_r18 >= 1 )
{
const PROGMEM char UPDATE_SQL[] = "UPDATE userdb.ParkingLotSpace set is_park='1' where P_number = 'park101' and Reserv != '1'";
Serial.println("Recording data.");
const PROGMEM char UPDATE_SQL2[] = "UPDATE userdb.park set parkempty=parkempty-1 where parkname = 'park1'";
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
cur_mem->execute(UPDATE_SQL);
MySQL_Cursor *cur_mem2 = new MySQL_Cursor(&conn);
cur_mem2->execute(UPDATE_SQL2);
delete cur_mem;
}
else
{
const PROGMEM char UPDATE_SQL[] = "UPDATE userdb.ParkingLotSpace set is_park='0' where P_number = 'park101'and Reserv != '1'";
Serial.println("Recording data.");
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
cur_mem->execute(UPDATE_SQL);
delete cur_mem;
}
int mfsr_r19 = map(SensorReading2, 0, 1024, 0, 255);
if ( mfsr_r19 >= 1 )
{
const PROGMEM char UPDATE_SQL[] = "UPDATE userdb.ParkingLotSpace set is_park='1' where P_number = 'park102'and Reserv != '1'";
Serial.println("Recording data.");
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
cur_mem->execute(UPDATE_SQL);
delete cur_mem;
}
else
{
const PROGMEM char UPDATE_SQL[] = "UPDATE userdb.ParkingLotSpace set is_park='0' where P_number = 'park102'and Reserv != '1'";
Serial.println("Recording data.");
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
cur_mem->execute(UPDATE_SQL);
delete cur_mem;
}
int mfsr_r20 = map(SensorReading3, 0, 1024, 0, 255);
if ( mfsr_r20 >= 1 )
{
const PROGMEM char UPDATE_SQL[] = "UPDATE userdb.ParkingLotSpace set is_park='1' where P_number = 'park103'and Reserv != '1'";
Serial.println("Recording data.");
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
cur_mem->execute(UPDATE_SQL);
delete cur_mem;
}
else
{
const PROGMEM char UPDATE_SQL[] = "UPDATE userdb.ParkingLotSpace set is_park='0' where P_number = 'park103'and Reserv != '1'";
Serial.println("Recording data.");
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
cur_mem->execute(UPDATE_SQL);
delete cur_mem;
}
Serial.println(mfsr_r18);
Serial.println(mfsr_r19);
Serial.println(mfsr_r20);
}
The code above is the code that sends data to mysql using Arduino.
If mfsr_r18 >=1 in one conditional statement, I want to send 2 lines of queries, but I keep getting errors. For example
char UPDATE_SQL1[] = "UPDATE userdb.ParkLotSpace setting is _park='1". where P_number = 'park101' and Reserve! = '1';,
char UPDATE_SQL2[] = "UPDATE userdb.park set parkempty='1" where P_number = 'park101' and Reserve!= '1',
I'd like to send the top two lines by mysql
I don't know how to send it by mysql.
I'd really appreciate it if you could help me.코드