如何将数据从arduino发送到通过wifi处理?

时间:2019-09-26 10:18:15

标签: android arduino wifi

我实际上是在尝试连接门铃。就像您按下按钮一样,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;
  }
}

1 个答案:

答案 0 :(得分:0)

您必须将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和路由器的密码。