2018年11月12日 星期一

Read temperature and humidity on Blynk with DHT11

Read temperature and humidity on Blynk with DHT11


/**************************************************************
  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 ordinary Arduino Serial
  to connect your project to Blynk.
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <SimpleTimer.h>

#include "DHT.h"
#define DHTPIN 23          // What digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "c03be235b22f4f2a85681a8057a50548";

// Your WiFi credentials.
// Set password to "" for open networks.
//char ssid[] = "Your network name";
//char pass[] = "Your network password";
char ssid[] = "alex9ufo";
char pass[] = "alex9981";

//===========================================
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();    // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
}
//===========================================
void setup()
{
  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  delay(10);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("WiFi connected");
  Blynk.begin(auth , ssid, pass);

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
}
//===========================================
void loop()
{
  Blynk.run();
  timer.run(); // Initiates SimpleTimer
}
//===========================================




















2018年11月11日 星期日

ESP32 to Control LED With Blynk Via WiFi

ESP32 to Control LED With Blynk Via WiFi


#define BLYNK_PRINT Serial

int LEDpin        = 2;   //build in LED

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
//char auth[] = "Your auth token key";
char auth[] = "25caf73aa9374cdf9220df77c848980a";

// Your WiFi credentials.
// Set password to "" for open networks.
//char ssid[] = "Your network name";
//char pass[] = "Your network password";
char ssid[] = "alex9ufo";
char pass[] = "alex9981";
//===========================================
WidgetLED led1(V1); //register to virtual pin 1
void led_status() { 
     Serial.print("Blynk LED pin status :");
     int pinvalue = digitalRead (LEDpin);
     Serial.println(String(pinvalue).c_str());
    if (pinvalue==HIGH){
        led1.on();
        }
    else{
        led1.off();
      }
}
//===========================================
void setup() {  
  pinMode(LEDpin, OUTPUT); 
  pinMode(LEDpin, HIGH);
  Serial.begin(115200);

  delay(10);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("WiFi connected");  
  Blynk.begin(auth , ssid, pass);

}
//===========================================
void loop(){
    Blynk.run();
    led_status(); 
    
}
//===========================================













ESP32_Blynk_DHT11


// Robo India Tutorial
// Digital Output on LED
// Hardware: NodeMCU Blynk Board

#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <SimpleTimer.h>   //including the library of SimpleTimer

#include "DHT.h"           // including the library of DHT11 temperature and humidity sensor
#define DHTTYPE DHT11      // DHT 11

#define dht_dpin 23
DHT dht(dht_dpin, DHTTYPE);
SimpleTimer timer;
char auth[] = "92e8d542e63184fa4bc2c3d0a3694f5da";            // You should get Auth Token in the Blynk App.
                                                             // Go to the Project Settings (nut icon).

char ssid[] = "abex99ufo";           // Your WiFi credentials.
char pass[] = "aedx93981";           // Set password to "" for open networks.
float t;                                   // Declare the variables
float h;



void setup()
{
    Serial.begin(115200);// Debug console
    Blynk.begin(auth, ssid, pass);
    dht.begin();
    timer.setInterval(2000, sendUptime);
}

void sendUptime()
{
 
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  Serial.println("Humidity and temperature\n\n");
  Serial.print("Current humidity = ");
  Serial.print(h);
  Serial.print("%  ");
  Serial.print("temperature = ");
  Serial.print(t);
  Blynk.virtualWrite(V0, t);
  Blynk.virtualWrite(V1, h);
 
}

void loop()
{
  Blynk.run();
  timer.run();
}





























Node-Red --> MQTT --> Fuxa

Node-Red --> MQTT --> Fuxa      FUXA(一個開源的 Web HMI / SCADA 自動化監控軟體)的專案設定檔 。 這份設定檔完整定義了 HMI 監控畫面的 後端通訊(MQTT 連線、點位標籤) 與 前端網頁圖形介面(SVG 畫布...