--

问题描述 投票:-2回答:1

我想整理一下我的arduino代码,把ESP32连接在一起。第一个ESP32(发送端)将电位计的值发送给另一个ESP32(接收端),另一个激活伺服。

请你帮我一个忙,检查一下我下面的代码。谢谢

感应器代码:

/*
receiving the instruction from switches and send through
*/

#include "WiFi.h"
#include "ESPAsyncWebServer.h"


// Set your access point network credentials
const char* ssid = "ESP32-Access-Point";
const char* password = "123456789";


AsyncWebServer server(80);

int sensorPin = 26;    // select the input pin for the potentiometer
int sensor = 0;  // variable to store the value coming from the sensor
String sensorValue;



void setup(){
  // Serial port for debugging purposes
  Serial.begin(115200);
  Serial.println();

  // Setting the ESP as an access point
  Serial.print("Setting AP (Access Point)…");
  // Remove the password parameter, if you want the AP (Access Point) to be open
  WiFi.softAP(ssid, password);

  IPAddress IP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(IP);

  server.begin();
} 

void loop(){
  sensor = analogRead(sensorPin);
  sensorValue = sensor;
  server.on("/sensorValue", HTTP_GET, [](AsyncWebServerRequest *request){
  request->send_P(200, "text/plain", sensorValue.c_str());});
}

-

arduino esp32
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.