2016年1月3日 星期日

blynk arduino record

/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social networks:            http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************
 *
 * This example shows how to use Arduino Ethernet shield (W5100)
 * to connect your project to Blynk.
 * Feel free to apply it to any other example. It's simple!
 *
 **************************************************************/

//#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include
#include
#include
#include
#include
#define dht_dpin 12
dht DHT;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
SimpleTimer timer;
void setup()
{
  Serial.begin(9600);
  //Blynk.begin(auth);
  // You can also specify server.
  // For more options, see BoardsAndShields/Arduino_Ethernet_Manual example
  Blynk.begin(auth, "192.168.1.252", 8442);
  //Blynk.begin(auth, IPAddress(192,168,1,100), 8888);
  //sensors.begin();

  timer.setInterval(1000,readTemp);
  digitalWrite(3, HIGH);
  digitalWrite(2, HIGH);
}

// Keep this flag not to re-sync on every reconnection
bool isFirstConnect = true;

// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
  if (isFirstConnect) {
    Blynk.syncAll();
    isFirstConnect = false;
  }
}
void loop()
{
  Blynk.run();
  timer.run();
 // sensors.requestTemperatures();
 // Serial.println(sensors.getTempCByIndex(0));
 // delay(2000);
}
void readTemp()
{
  // sensors.requestTemperatures();
  // float floatTempC = sensors.getTempCByIndex(0);
    //Serial.println(floatTempC);
   //char t_buffer[15];
   //dtostrf(floatTempC,8,9,t_buffer);
   DHT.read11(dht_dpin);
   Blynk.virtualWrite(0,String(DHT.temperature).substring(0,4)+"℃"); //dht11
   Blynk.virtualWrite(1,String(DHT.humidity).substring(0,2)+"%"); //dht11
   Blynk.virtualWrite(2,DHT.temperature);
  // Blynk.virtualWrite(3,DHT.humidity); //dht11
   //Blynk.virtualWrite(6,t_buffer);  //ds18b20
   //Serial.println (t_buffer);

}
缺少的地方登入後編輯文件, use html 即可看到

沒有留言: