我正在尝试用Arduino向我的数据库发送一些数据。我的PC上安装了MariaDB。不幸的是,我无法连接。我的第一个疑问是服务器地址应该与我的PC ip地址相同吗?有人能帮帮忙吗。
if (conn.connect(server_addr, 3306, user, password))
{ Serial.println("Connecting to database server...");
delay(1000);
// Initiate the query class instance
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
dtostrf(voltage, 6, 2, voltageNew);
dtostrf(current, 6, 4, currentNew);
sprintf(querymessuremnt, INSERT_measurements,voltageNew, currentNew);
// Execute the query
cur_mem->execute(querybuffer);
delete cur_mem;
Serial.println("Data recorded.");
}
else
Serial.println("Connection to DB failed.");
conn.close();
}
发布于 2019-06-06 18:46:27
添加什么作为服务器名称,这取决于您从何处触发所提到的代码。如果你登录到你的Arduino,你应该使用'localhost‘,因为我假设你在Arduino上运行MariaDB。
如果您怀疑存在阻止脚本完全工作的端口问题,请尝试将“localhost”更改为“127.0.0.1”。如果您有防火墙,是否允许端口3306上的数据?
如果您正在从另一台机器运行代码,但是想要访问您的Arduino/MariaDB,那么在那台机器上,您需要使用服务器名称ip-adress将您的代码更新到您的arduino机器。
https://stackoverflow.com/questions/56473925
复制相似问题