mysql - 无法使用arduino连接到数据库服务器发送一些数据

标签 mysql database arduino

我正在尝试使用 Arduino 将一些数据发送到我的数据库。 MariaDB 安装在我的电脑上。不幸的是,我无法连接。我的第一个疑问是服务器地址应该与我的电脑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,那么您可以在该计算机上使用服务器名称 [arduino 计算机的 IP 地址] 更新代码。

关于mysql - 无法使用arduino连接到数据库服务器发送一些数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56473925/

相关文章:

c++ - Arduino 上的十六进制乘法

MySQL CASE EnumInt WHEN Varchar ELSE Int 返回为 BLOB - 如何转换为 Varchar?

php - 如何阻止行 ID 变大

mysql - 将数据库从 Postgres 迁移到 MySQL

Arduino NFC门解锁

java - 通过串口从 C# 发送数字到 Java

mysql - 通过向 dst 和 src 发送 RST 来强制关闭 TIME_WAIT 连接?

mysql - 将数据插入表时 Date_format 不起作用? (SQL)

mysql - 如何更新Mysql中的一系列记录

sql-server - 如何解释 t-sql 死锁跟踪