首页 > 解决方案 > 如何使用 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");
  }
 }

标签: carduino-uno

解决方案


推荐阅读