Arduino:循环函数只运行一次

时间:2015-09-27 05:05:47

标签: arduino arduino-uno

我试图要求DS18B20传感器的温度在plot.ly上发布,但似乎我的循环功能只运行一次;连接到plot.ly并创建图表后,温度在串行监视器中打印一次,似乎不会继续!任何帮助是极大的赞赏。这是我的代码:

#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <plotly_streaming_cc3000.h>
#include <OneWire.h>
#include <DallasTemperature.h>


#define WLAN_SSID       "wifi"
#define WLAN_PASS       "********"
#define WLAN_SECURITY   WLAN_SEC_WPA2

OneWire  oneWire(10);
DallasTemperature sensors(&oneWire);

#define nTraces 1

char *tokens[nTraces] = {"token"};

plotly graph("username", "token", tokens, "filename", nTraces);


void wifi_connect(){
  /* Initialise the module */
  Serial.println(F("\n... Initializing..."));
  if (!graph.cc3000.begin())
  {
    Serial.println(F("... Couldn't begin()! Check your wiring?"));
    while(1);
  }

  // Optional SSID scan
  // listSSIDResults();

  if (!graph.cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }

  Serial.println(F("... Connected!"));

  /* Wait for DHCP to complete */
  Serial.println(F("... Request DHCP"));
  while (!graph.cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!

    unsigned long aucDHCP = 14400;
unsigned long aucARP = 3600;
unsigned long aucKeepalive = 10;
unsigned long aucInactivity = 20;
if (netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity) != 0) {
  Serial.println("Error setting inactivity timeout!");
}

  }
}


void setup() {
  graph.maxpoints = 100;
  Serial.begin(9600);
  sensors.begin();

  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  wifi_connect();

  bool success;
  success = graph.init();
  if(!success){while(true){}}
  graph.openStream();
}

void loop(void) {
    Serial.print("Requesting temperatures...");
    sensors.requestTemperatures();
    Serial.println("DONE");
    Serial.print("Temperature for Device 1 is: ");
    Serial.print(sensors.getTempFByIndex(0));
    graph.plot(millis(), sensors.getTempFByIndex(0), tokens[0]);
    delay(500);
}

0 个答案:

没有答案