mysql - 无法使用 arduino 连接到数据库服务器以发送一些数据
问题描述
我正在尝试使用 Arduino 将一些数据发送到我的数据库。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();
}
解决方案
添加什么作为服务器名称取决于您触发您提到的代码的位置。如果您登录到您的 Arduino,您应该使用“localhost”,因为我假设您在 Arduino 上运行 MariaDB。
如果您怀疑存在阻止脚本完全工作的端口问题,请尝试将“localhost”更改为“127.0.0.1”。如果您有防火墙,您是否允许端口 3306 上的数据?
如果您正在从另一台机器上运行代码但想要访问您的 Arduino/MariaDB,那么在该机器上您使用服务器名称 [ip-adress to your arduino machine] 更新您的代码。
推荐阅读
- powershell - 修改 PowerShell 以仅针对特定 OU 将 Windows 更新导出到 CSV 文件不起作用
- dart - Flutter如何强制Timer取消?
- intellij-idea - 如何在 IntelliJ 中使用本地 Maven 存储库
- php - 在 Sonata Admin 中设置表演动作时出现问题。尝试使用标签选项自定义显示字段的显示标签时出错
- laravel - laravel 5.6护照。邮递员加载无输出
- python-2.7 - 从网站获取数据时出现空白列表错误
- java - Spring MVC 到 SpringBoot 2:bean 'xyz' 不能作为 'com..Abc' 注入,因为它是一个 JDK 动态代理,它实现:
- caching - 仅在 Safari 中的页面刷新时播放的视频
- haskell - haskell mtl/transformers 相当于镜头的缩放状态
- ios - iOS 12 对关闭我的应用程序更加激进?