hi, i have a project to control ac and tv power with IR signal from internet and i have arduino mega and uno.
in this case i use mysql connector for getting condition and applying IR command, so if in db value is TvPower command will be send IR signal with Tv power code or if value is AcPower then will send ir signal with Ac Power raw code.
but if i put 2 code raw in one time, code is crash and just showing unreadeble characters.
this is my code
#include <Ethernet.h>
#include <MySQL_Connection.h>
#include <Dns.h>
#include <MySQL_Cursor.h>
#include <IRremote.h>
IRsend irsend;
//this is the problem
#define RAW_DATA_LEN 68
uint16_t rawTvPower[RAW_DATA_LEN]={
4510, 4498, 558, 1682, 554, 1682, 554, 1682,
558, 566, 554, 566, 554, 566, 550, 566,
554, 566, 554, 1682, 554, 1686, 554, 1682,
554, 566, 554, 566, 554, 566, 554, 566,
554, 566, 550, 566, 554, 1682, 558, 566,
554, 566, 550, 566, 554, 566, 554, 566,
554, 566, 554, 1682, 554, 566, 554, 1682,
554, 1682, 558, 1682, 554, 1682, 558, 1682,
554, 1682, 554, 1000};
/*if i add more raw code like this, serial monitor is broke and not showing nothing or just weird characters (mysql connector also cant start)
*/
uint16_t rawAcPower[RAW_DATA_LEN]={
4470, 4538, 490, 1750, 490, 1746, 490, 1750,
490, 630, 490, 626, 494, 626, 490, 630,
490, 630, 490, 1746, 490, 1750, 542, 1694,
494, 626, 490, 630, 490, 630, 490, 630,
490, 630, 490, 1746, 490, 1750, 494, 1742,
490, 1750, 542, 578, 542, 578, 490, 630,
542, 574, 494, 626, 490, 630, 546, 574,
490, 630, 490, 1750, 542, 1694, 546, 1694,
490, 1746, 490, 1000};
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char hostname[] = "******";
char user[] = "*******";
char password[] = "*******";
char query[] = "SELECT * FROM ****** where user='trial'";
char INSERT_SQL[] = "UPDATE ****** SET value ='%s' WHERE user ='%s'";
char queryInsert[128];
EthernetClient client;
IPAddress server_ip;
MySQL_Connection conn((Client *)&client);
DNSClient dns_client;
MySQL_Cursor cur = MySQL_Cursor(&conn);
void setup() {
Serial.begin(115200);
while (!Serial);
Ethernet.begin(mac_addr);
// Begin DNS lookup
dns_client.begin(Ethernet.dnsServerIP());
dns_client.getHostByName(hostname, server_ip);
Serial.println(server_ip);
// End DNS lookup
Serial.println("Connecting...");
if (conn.connect(server_ip, 3306, user, password)) {
Serial.println("CONNECTED!");
}
else
Serial.println("Connection failed.");
}
void loop() {
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
MySQL_Cursor *cur_insert = new MySQL_Cursor(&conn);
sprintf(queryInsert, INSERT_SQL, "NO","****");
cur_mem->execute(query);
column_names *cols = cur_mem->get_columns();
row_values *row;
while(row = cur_mem->get_next_row())
{
String rawValue=row->values[3];
String catIR=row->values[2];
Serial.println("\nraw value = ");
Serial.println(rawValue);
if(rawValue=="TvPower")
{
irsend.sendRaw(rawTvPower, RAW_DATA_LEN, 38); //send raw data at 38KHz frequency
cur_insert->execute(queryInsert);
Serial.println("Recording data!");
delete cur_insert;
}else if(rawValue=="AcPower")
{
irsend.sendRaw(rawAcPower, RAW_DATA_LEN, 38); //send raw data at 38KHz frequency
cur_insert->execute(queryInsert);
Serial.println("Recording data!");
delete cur_insert;
}
}
delete cur_mem;
}
in serial monitor just printing :
x⸮⸮x