MIT App Inventor&Arduino&ESP8266:在Google Firebase中存储值

问题描述 投票:0回答:1

我正在尝试在MIT App Inventor 2中构建一个Android应用程序。

这是我的design

这是我的code blocks

我的目的是;当我点击色轮上的某个地方时;获取我点击的地方的坐标(黑球)并获得其RGB值。

它在手机屏幕上完美运行,它显示了值。但问题是;当我尝试将rgb值导入Firebase时,这个值在此picture中就像这种格式

如您所见,其框中的文本格式如下:"\"101\""

但我想:101只。因为我将获取我的NodeMCU ESP8266的值以使RGB LED闪烁。我将这些值插入analogWrite(pin,value)函数。

我在麻省理工学院App Inventor Block屏幕上的错在哪里?那里有解决方案吗?或者你可以给我ESP8266代码部分的建议(比如拆分文本或其他东西)?

firebase-realtime-database arduino esp8266 nodemcu app-inventor
1个回答
0
投票

您可以添加此行

String b_fir = Firebase.getString("B");
String str_b_fir = getStringPartByNr(b_fir, '"', 1);
int int_b_fir = str_b_fir.toInt();

您可以在loop下添加此功能

String getStringPartByNr(String data, char separator, int index)
{
    // spliting a string and return the part nr index
    // split by separator

    int stringData = 0;        //variable to count data part nr 
    String dataPart = "";      //variable to hole the return text

    for(int i = 0; i<data.length()-1; i++) {    //Walk through the text one letter at a time

      if(data[i]==separator) {
        //Count the number of times separator character appears in the text
        stringData++;

      }else if(stringData==index) {
        //get the text when separator is the rignt one
        dataPart.concat(data[i]);

      }else if(stringData>index) {
        //return text and stop if the next separator appears - to save CPU-time
        return dataPart;
        break;

      }

    }
    //return text if this is the last part
    return dataPart;
}
© www.soinside.com 2019 - 2024. All rights reserved.