gpt4 book ai didi

mysql - Arduino - 基于 mysql 数据库值通过 wifi 控制 LED

转载 作者:行者123 更新时间:2023-11-29 02:26:23 25 4
gpt4 key购买 nike

<分区>

我有:

  • 带有 MySQL 数据库并可用于网络的家庭服务器设置
  • 带有连接到 LED 的 WiFi shield 的 Arduino

以上两者都在工作 - Arduino 连接到 WiFi 并分配了一个 IP 地址。

我现在要做的是编写一些 Arduino 代码来读取存储在网络服务器数据库中的值。

如果我能想出如何做到这一点,我可以从那里开始。有人可以举例说明如何这样做吗?

关于我目前所做工作的额外细节:

  • 下面的代码使用 wifi shield 连接到 wifi。
  • 我正在使用 Arduino Uno 和 IDE 的 v 1.05
  • 在本地 NAS 上设置 PHP/MYSQL - ip 192.168.0.102/web/homeserver

简而言之,只需要知道从已经连接到网络的 arduino 查询网络服务器/数据库需要什么。

#include <WiFi.h>

char ssid[] = "SSID_IS_HERE"; // your network SSID (name)
char pass[] = "MY_PASSWORD"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status

void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}

// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);

// wait 10 seconds for connection:
delay(10000);
}

// you're connected now, so print out the data:
Serial.print("You're connected to the network");
printCurrentNet();
printWifiData();
}

void loop() {
// check the network connection once every 10 seconds:
delay(10000);
printCurrentNet();
}

void printWifiData() {
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
Serial.println(ip);

// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
Serial.print(mac[5],HEX);
Serial.print(":");
Serial.print(mac[4],HEX);
Serial.print(":");
Serial.print(mac[3],HEX);
Serial.print(":");
Serial.print(mac[2],HEX);
Serial.print(":");
Serial.print(mac[1],HEX);
Serial.print(":");
Serial.println(mac[0],HEX);
}

void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
Serial.print(bssid[5],HEX);
Serial.print(":");
Serial.print(bssid[4],HEX);
Serial.print(":");
Serial.print(bssid[3],HEX);
Serial.print(":");
Serial.print(bssid[2],HEX);
Serial.print(":");
Serial.print(bssid[1],HEX);
Serial.print(":");
Serial.println(bssid[0],HEX);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.println(rssi);

// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type:");
Serial.println(encryption,HEX);
Serial.println();
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com