簡體   English   中英

將JSON中的字符串變量從arduino yun發送到Firebase

[英]Sending string variable in JSON from arduino yun to firebase

我正在嘗試通過curl POST將arduino yun的json發送到firebase。 通過String()轉換的所有其他數據(int,float)均已正確發送,但原本是字符串的“計時器”無法通過。 有任何想法嗎 ?

// Measure the humidity
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();

// Measure light level
int lightLevel = analogRead(A0);

// Time
String timer = getTimeStamp();

// Firebase post
Process p;
p.runShellCommand("curl -k -X POST https://xxx.firebaseio.com/data.json -d    '{ \"Timestamp\" : "timer",\"Humidity\" : " + String(humidity) + ",\"Temperature\"  : " + String(temperature) + ",\"Lightlevel\" : " + String(lightLevel) + "}'");

雖然,我還沒有在Firebase上工作,但是我使用下面的代碼來創建json字符串,但它運行得很好:

String jsonString = "{\"temperature\":\"";
jsonString += temperatureC;
jsonString +="\",\"humidity\":\"";
jsonString += humidity;
jsonString +="\",\"other_value\":\"";
jsonString += otherValue;
jsonString +="\"}";

希望它能以某種方式對您有所幫助。

它通過使用以下行來工作:

  Process p;   
  p.runShellCommand("curl -H \"Content-Type: application/json\" -X POST -d '{\"name\":\"arduino\",\"value\":\"15\"}' http://localhost:1234/temp");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM