Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 转换字符串值​;至整数(esp32)_Javascript_Html_Esp32 - Fatal编程技术网

Javascript 转换字符串值​;至整数(esp32)

Javascript 转换字符串值​;至整数(esp32),javascript,html,esp32,Javascript,Html,Esp32,我正在尝试在esp32上编程一个web服务器,我想用它来控制WS2812b LED条带。我只是想显示颜色,并想用GET方法解决这个问题。如果我读数值​​作为一个字符串,它都可以工作,但是当我试图将它们转换为int时,我在串行监视器中得到奇怪的输出。 我尝试了string.toInt()函数,还尝试了typecast #include <Adafruit_NeoPixel.h> #include <WiFi.h> #include <ESPAsyncWebServer

我正在尝试在esp32上编程一个web服务器,我想用它来控制WS2812b LED条带。我只是想显示颜色,并想用GET方法解决这个问题。如果我读数值​​作为一个字符串,它都可以工作,但是当我试图将它们转换为int时,我在串行监视器中得到奇怪的输出。 我尝试了string.toInt()函数,还尝试了typecast

#include <Adafruit_NeoPixel.h>
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <ESPmDNS.h>
#include <Adafruit_NeoPixel.h>

#define PIN 2
#define NUM 150

const char* ssid = "WLAN";
const char* password = "...";

String html = "<!DOCTYPE html><html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><link rel=\"icon\" href=\"data:,\"><link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css\"><script src=\"https://cdnjs.cloudflare.com/ajax/libs/jscolor/2.0.4/jscolor.min.js\"></script></head><body><div class=\"container\"><div class=\"row\"><h1>ESP Color Picker</h1></div><a class=\"btn btn-primary btn-lg\" href=\"#\" id=\"change_color\" role=\"button\">Change Color</a><input class=\"jscolor {onFineChange:'update(this)'}\" id=\"rgb\"></div><script>function update(picker) {document.getElementById('rgb').innerHTML = Math.round(picker.rgb[0]) + ', ' +  Math.round(picker.rgb[1]) + ', ' + Math.round(picker.rgb[2]);document.getElementById(\"change_color\").href=\"?r=\" + Math.round(picker.rgb[0]) + \"&g=\" +  Math.round(picker.rgb[1]) + \"&b=\" + Math.round(picker.rgb[2]) + \"&\";}</script></body></html>";
            
AsyncWebServer server(80);
Adafruit_NeoPixel stripe (NUM, PIN, NEO_GRB + NEO_KHZ800);
 
void setup()
{
  Serial.begin(115200);
  for(int i = 0; i < NUM; i++)
    {
      stripe.setPixelColor(0,stripe.Color(0,0,0));
    }
  stripe.show();
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(1000);
    Serial.println("Verbinde mit WLAN...");
  }
  Serial.println(WiFi.localIP());

  if(!MDNS.begin("ledStripe_1"))
    {
      Serial.println("Fehler beim DNS");
      return;
    }
 
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){

    String s_rot, s_gruen, s_blau;
    int paramsNr = request->params();
    Serial.print("Anzahl der Parameter: ");
    Serial.println(paramsNr);
 
    for(int i=0;i<paramsNr;i++){
 
        AsyncWebParameter* p = request->getParam(i);
        Serial.print("Parametername: ");
        Serial.println(p->name());
        Serial.print("Parameterwert: ");
        Serial.println(p->value());
        Serial.println("------");

        if(i == 0)
        {
          s_rot = String(p->value());
        }
        else if(i == 1)
        {
          s_gruen =  String(p->value());
        }
        else if(i == 2)
        {
          s_blau =  String(p->value());
        }
    }

    Serial.println("Rot: " + s_rot);
    Serial.println("Grün: " + s_gruen);
    Serial.println("Blau: " + s_blau + "\n");

    int rot = (int)s_rot;
    
    Serial.println("Rot: " + rot);
//    Serial.println("Grün: " + gruen);
//    Serial.println("Blau: " + blau);

//    stripe.setPixelColor(0,stripe.Color((int)rot, (int)gruen, (int)blau));
//    stripe.show();
 
    request->send(200, "text/html", html);
  });
 
  server.begin();
}
 
void loop(){}
包括函数更新(picker){document.getElementById('rgb')。innerHTML=Math.round(picker.rgb[0])+,'+Math.round(picker.rgb[1])+','+Math.round(picker.rgb[2]);document.getElementById(\'change\u color\”)。href=\“?r=\”+Math.round(picker.rgb[0+\”&g=\“+Math.round(picker.rgb[1]),'b=\+++\\+Math.round(picker.rgb[2])";
异步web服务器(80);
Adafruit_Neopix条纹(数量、针、NEO_GRB+NEO_KHZ800);
无效设置()
{
序列号开始(115200);
for(int i=0;i参数();
串行打印(“Anzahl der参数:”);
Serial.println(paramsr);
对于(int i=0;IGETRAM(i);
Serial.print(“参数名称:”);
Serial.println(p->name());
Serial.print(“Parameterwert:”);
Serial.println(p->value());
Serial.println(“----”);
如果(i==0)
{
s_rot=String(p->value());
}
else如果(i==1)
{
s_gruen=String(p->value());
}
else如果(i==2)
{
s_blau=String(p->value());
}
}
Serial.println(“Rot:+s_Rot”);
连载.println(“Grün:+s_gruen”);
Serial.println(“Blau:+s_Blau+”\n);
int rot=(int)s_rot;
序列号println(“Rot:+Rot”);
//Serial.println(“Grün:+gruen”);
//Serial.println(“Blau:+Blau”);
//stripe.setPixelColor(0,stripe.Color((int)rot,(int)gruen,(int)blau));
//stripe.show();
请求->发送(200,“文本/html”,html);
});
server.begin();
}
void loop(){}

你尝试了吗?这看起来像C或C++代码,为什么它被标记为JavaScript?……r= \“+数学。圆(Pkur.RGB [0)] +…………所以…R= \“+ PARSETIN(Maul.Prime:Pigr.RGB(0)))……用字符串HTML引起颜色选择器…