c - 如何使用 Ethernet Shield 将数据从 Arduino Uno 发送到 MySQL 数据库
问题描述
我正在尝试使用以太网屏蔽将数据从 Arduino 发送到数据库,但它不起作用。连接成功,但是当我签入数据库时,我在数据库中找不到任何新值。
这是我的 Arduino 代码。
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //Setting MAC Address
char server[] = "192.168.1.1";
IPAddress ip(192,168,1,105);
EthernetClient client;
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
delay(1000);
}
/* Infinite Loop */
void loop(){
Sending_To_phpmyadmindatabase();
delay(30000); // interval
}
void Sending_To_phpmyadmindatabase() //CONNECTING WITH MYSQL
{
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
Serial.print("GET /testcode/info.php?request=");
client.print("GET /testcode/info.php?request="); //YOUR URL
client.print("Testing");
client.print(" "); //SPACE BEFORE HTTP/1.1
client.print("HTTP/1.1");
client.println();
client.println("Host: 192.168.1.1");
client.println("Connection: close");
client.println();
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
解决方案
推荐阅读
- java - 匹配单词和带有撇号的单词的正则表达式
- c# - C# CustomAttributeData 类来属性
- python - 其他命令不起作用。(Python, Discord.py)
- python - 从数据框中的特定列开始计算每 4 列的平均值,并将每个平均值结果输出到 np 数组以进行进一步处理
- python - 在不同的窗口 tkinter 上按下按钮后如何获得文本
- javascript - 使用图层组传单生成 10,000 个性能良好的标记
- etl - 从流复制数据制作 SCD 类型 2 表的最佳方法是什么?
- python - linux上的旧python版本,是否需要升级?
- javascript - Vue 和 Axios,这个回调的东西让我很困惑。错误:'v-on 处理程序中的错误:“TypeError:无法读取未定义的属性'成功'”'
- python - 你能从一个 h5py 对象写一个 h5 文件吗?