Parse platform Parse.com上的超声波距离传感器读数

Parse platform Parse.com上的超声波距离传感器读数,parse-platform,arduino,distance,Parse Platform,Arduino,Distance,我可能走错了方向,但事情还是这样。我目前正在尝试将超声波距离传感器/Arduino-Yun的读数发布到Parse.com网站。从那里我将把数据输入Xcode并创建一个应用程序,但我知道如何做到这一点 我目前的主要问题是结合解析教程代码和我当前的超声波距离传感器代码。我目前让传感器完全按照我的要求在串行监视器中打印正确的读数,但是我希望它打印的数据在线显示 这容易做到吗 我目前可以将我的数据发布到data.Sparkfun.com上,但是当涉及到将数据刮到Xcode时,它会变得非常混乱 我希望这是

我可能走错了方向,但事情还是这样。我目前正在尝试将超声波距离传感器/Arduino-Yun的读数发布到Parse.com网站。从那里我将把数据输入Xcode并创建一个应用程序,但我知道如何做到这一点

我目前的主要问题是结合解析教程代码和我当前的超声波距离传感器代码。我目前让传感器完全按照我的要求在串行监视器中打印正确的读数,但是我希望它打印的数据在线显示

这容易做到吗

我目前可以将我的数据发布到data.Sparkfun.com上,但是当涉及到将数据刮到Xcode时,它会变得非常混乱

我希望这是一个简单的解决方案,以下是我为传感器工作的当前代码:

#include <Process.h>
#include <NewPing.h>

////////////////
// Pin Inputs //
////////////////
const int triggerPin = 3;
#define TRIGGER_PIN  2  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     4  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 500 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
int i=0;
int current = 0;
int low = 10000;

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

String name = "Yun-anon";
boolean newName = true;

void setup() 
{
  Bridge.begin();
  Serial.begin(115200);

  // Setup Input Pins:
  pinMode(triggerPin, INPUT_PULLUP);
  pinMode(current, INPUT_PULLUP);
  //pinMode(lightPin, INPUT_PULLUP);

  Serial.println("=========== Ready to Stream ===========");
  Serial.println("Press the button (D3) to send an update");
  Serial.println("Type your name, followed by '!' to update name");
}

void loop()
{  
  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  int y = uS / US_ROUNDTRIP_CM;

  int x = y/2;


  current = x;
  current=map(current,9,2,50,800);
    Serial.println(current);
  if (current < low){
    low = current;
  } 
  delay(1000);

  // If the trigger pin (3) goes low, send the data.
  if (!digitalRead(triggerPin))
  {
    // Gather Data
    fieldData[0] = String(analogRead(current));
    //fieldData[1] = String(digitalRead(switchPin));
    //fieldData[2] = name;

    // Post Data
    Serial.println("Posting Data!");
    postData(); // the postData() function does all the work, 
                // see below.
    delay(1000);
  }

  // Check for a new name input:
  if (Serial.available())
  {
    char c = Serial.read();
    if (c == '!')
    {
      newName = true;
      Serial.print("Your name is ");
      Serial.println(name);
    }
    else if (newName)
    {
      newName = false;
      name = "";
      name += c;
    }
    else
    {
      name += c;
    }
  }

}

void postData()
{
  Process phant; // Used to send command to Shell, and view response
  String curlCmd; // Where we'll put our curl command
  String curlData[NUM_FIELDS]; // temp variables to store curl data

  // Construct curl data fields
  // Should look like: --data "fieldName=fieldData"
  for (int i=0; i<NUM_FIELDS; i++)
  {
    curlData[i] = "--data \"" + fieldName[i] + "=" + fieldData[i] + "\" ";
  }

  // Construct the curl command:
  curlCmd = "curl ";
  curlCmd += "--header "; // Put our private key in the header.
  curlCmd += "\"Phant-Private-Key: "; // Tells our server the key is coming
  curlCmd += privateKey; 
  curlCmd += "\" "; // Enclose the entire header with quotes.
  for (int i=0; i<NUM_FIELDS; i++)
    curlCmd += curlData[i]; // Add our data fields to the command
  curlCmd += phantURL + publicKey; // Add the server URL, including public key

  // Send the curl command:
  Serial.print("Sending command: ");
  Serial.println(curlCmd); // Print command for debug
  phant.runShellCommand(curlCmd); // Send command through Shell

  // Read out the response:
  Serial.print("Response: ");
  // Use the phant process to read in any response from Linux:
  while (phant.available())
  {
    char c = phant.read();
    Serial.write(c);
  }
}

所以你想上传一个新的读数,每50毫秒解析一次?你也有一些其他的耽搁。我不太清楚你的问题到底是什么-与传感器部分无关…@Wain超声波传感器每50毫秒读取一次读数是的,但是我只希望在按下按钮时将数据推送到Parse.com。此时此刻,我能够在串行监视器中打印读数,但是我无法获取数据发布到parse.com上。我希望这对你有所帮助,谢谢你的评论!