我实际上是在尝试制作一个联网的门铃。就像当你按下按钮时,wifi-arduino ( ESP32 DEVKITV1 ) 向我的笔记本电脑 (正在处理) 发送信号以通过 wifi 制作歌曲。笔记本电脑连接无线,让歌曲更强劲。
我的 wifi 连接不成功:
#include <WiFi.h> // Include the Wi-Fi library
const char* ssid = "Wifi Guest"; // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = ""; // The password of the Wi-Fi network
const int bouton = 14;
const int ledtemoin = 12;
int compteur = 0;
int etatbouton = 0;
int etatboutonprecedent = 0;
void setup() {
Serial.begin(115200); // Start the Serial communication to send messages to the computer
delay(10);
Serial.println('\n');
pinMode(bouton, INPUT);
pinMode(ledtemoin, OUTPUT);
Serial.begin(115200);
WiFi.begin(ssid, password); // Connect to the network
Serial.print("Connecting to ");
Serial.print(ssid);
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
delay(500);
Serial.print('.');
}
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
pinMode(13, OUTPUT);
}
void loop() {
etatbouton = digitalRead(bouton);
if (etatbouton != etatboutonprecedent) {
if (etatbouton == HIGH) {
compteur++;
digitalWrite (ledtemoin, HIGH);
Serial.println("APPUI");
Serial.print("nombre d'appuis: ");
Serial.println(compteur, DEC);
}
else {
Serial.println("PAS D'APPUI");
digitalWrite (ledtemoin, LOW);
}
etatboutonprecedent = etatbouton;
}
}
最佳答案
您必须将 ESP32(它不是 Arduino)连接到您的 WiFi 路由器。
开启
const char* ssid = "Wifi Guest"; // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = ""; // The password of the Wi-Fi network
您必须提供路由器的 SSID 和密码。这是将 ESP32 连接到网络的唯一方法。
使用一些库行 WiFiManager,你可以将你的 ESP32 设置为 AccessPoint 等,如果它不能连接到你的路由器,它会创建一个新的网络。因此,您可以通过手机或 PC 设置 SSID 和密码,而无需在您的代码中进行编码。
但为了保持简短:如果您想在网络中看到您的 esp32,请将您的路由器 ssid 和路由器密码放在您的代码中。
关于android - 如何通过wifi从arduino发送数据到处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58114624/