代码片段:
Serial.println(sensorString); //so you can see the captured string
char carray[sensorString.length() + 1]; //determine size of the array
Serial.println(sizeof(carray));
sensorString.toCharArray(carray, sizeof(carray)); //put sensorString into an array
float sensorStringFloat = atoi(carray); //convert the array into an Integer
Serial.println(sensorStringFloat);
Serial.println(sensorStringFloat) 打印出 5.00 而不是正确的浮点值 5.33。为什么会这样,我该如何解决这个问题?我最终想将 sensorStringFloat 传递给:
aJson.addNumberToObject(sensor, "ph", sensorStringFloat);