arduino Wifiライブラリ(モデルMKR1000)を使用して、Webページから値を受け取りました。もちろん私が受け取っている価値はasciiなので、Arduinoはそれを受け取って数字にするのに問題があります。ASCIIをintに変換する
基本的に、62(Webページ上の番号)の代わりに、「5450」(54はASCII値6、50はASCII値2)を受け取っています。
私のコードは、私は完全に失われています
String c;
// By setting this to String it prints out 5450
// By setting this to int it instead prints out "hp"
if (client.connect(server, 80)) {
Serial.println("connected to server");
// Make a HTTP request:
client.println("GET /arduino/electricity.php");
delayNumber = 0;
}
while (client.available()) {
c = c + client.read();
}
//Adds 54 and then 50 to c
Serial.print("C is: " + c);
//Currently prints 5450
です。変数 "c"が62になるようにするにはどうすればいいですか?
編集:私はあなたの場合には整数を返します。このテーブルhttp://www.asciitable.com/
黙って質問すると、6はDECの値54、DECの値の2は50であるのはなぜですか? –
それはちょうど、私は翻訳のためのこの参照に従っていますhttp://www.asciitable.com/ – Eight
それはASCIIコード、DEC値ではありません。他人に誤解を与えてはなりません。 –