2018年6月29日 星期五

DHT11_SSD1306_Webserver



















//D1 --SSD1305 SCL
//D2 --SSD1306 SDA

// Including the ESP8266 WiFi library
#include <ESP8266WiFi.h>
#include "DHT.h"
#include  "Adafruit_Sensor.h"
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET LED_BUILTIN  //4
Adafruit_SSD1306 display(OLED_RESET);

// Uncomment one of the lines below for whatever DHT sensor type you're using!
#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321

// Replace with your network details
//const char* ssid = "YOUR_NETWORK_NAME";
//const char* password = "YOUR_NETWORK_PASSWORD";
const char* ssid = "74170287";
const char* password = "24063173";


// Web Server on port 80
WiFiServer server(80);

// DHT Sensor
const int DHTPin = D3;
// Initialize DHT sensor.
DHT dht(DHTPin, DHTTYPE);

// Temporary variables
static char celsiusTemp[7];
static char fahrenheitTemp[7];
static char humidityTemp[7];

// only runs once on boot
void setup() {
  // Initializing serial port for debugging purposes
  Serial.begin(115200);
  delay(10);
  dht.begin();

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  // Clear the buffer.
  display.clearDisplay();
  display.display();

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Hello from:");
  display.println("http://alex9ufo.blogspot.com/");
  display.display();
 
  // Connecting to WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Starting the web server
  server.begin();
  Serial.println("Web server running. Waiting for the ESP IP...");
  delay(10000);
 
  // Printing the ESP IP address
  Serial.println(WiFi.localIP());
}

// runs over and over again
void loop() {
  // Listenning for new clients
  WiFiClient client = server.available();
 
  if (client) {
    Serial.println("New client");
    // bolean to locate when the http request ends
    boolean blank_line = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
       
        if (c == '\n' && blank_line) {
            // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
            float h = dht.readHumidity();
            // Read temperature as Celsius (the default)
            float t = dht.readTemperature();
            // Read temperature as Fahrenheit (isFahrenheit = true)
            float f = dht.readTemperature(true);
            // Check if any reads failed and exit early (to try again).
            if (isnan(h) || isnan(t) || isnan(f)) {
              Serial.println("Failed to read from DHT sensor!");
              strcpy(celsiusTemp,"Failed");
              strcpy(fahrenheitTemp, "Failed");
              strcpy(humidityTemp, "Failed");       
            }
            else{
              /*
              // Compute heat index in Fahrenheit (the default)
              float hif = dht.computeHeatIndex(f, h);
              // Compute heat index in Celsius (isFahreheit = false)
              float hic = dht.computeHeatIndex(t, h, false); */
             
              // Computes temperature values in Celsius + Fahrenheit and Humidity
              float hic = dht.computeHeatIndex(t, h, false);     
              dtostrf(hic, 6, 2, celsiusTemp);           
              float hif = dht.computeHeatIndex(f, h);
             
              dtostrf(hif, 6, 2, fahrenheitTemp);       
              dtostrf(h, 6, 2, humidityTemp);
              // You can delete the following Serial.print's, it's just for debugging purposes
              Serial.print("Humidity: ");
              Serial.print(h);
              Serial.print(" %\t Temperature: ");
              Serial.print(t);
              Serial.print(" *C ");
              Serial.print(f);
              Serial.print(" *F\t Heat index: ");
              Serial.print(hic);
              Serial.print(" *C ");
              Serial.print(hif);
              Serial.print(" *F");
              Serial.print("Humidity: ");
              Serial.print(h);
              Serial.print(" %\t Temperature: ");
              Serial.print(t);
              Serial.print(" *C ");
              Serial.print(f);
              Serial.print(" *F\t Heat index: ");
              Serial.print(hic);
              Serial.print(" *C ");
              Serial.print(hif);
              Serial.println(" *F");
              //-------------SSD 1306 Display-------------------//
                // Clear the buffer.
              display.clearDisplay();
              display.display();

              display.setTextSize(1);
              display.setTextColor(WHITE);
              display.setCursor(0,0);
              display.print("TemCel:");
              display.print(celsiusTemp);
              display.println(" *C ");
             
              display.setCursor(0,8);           
              display.print("TemFah:");
              display.print(fahrenheitTemp);
              display.println(" *F ");
             
              display.setCursor(0,16);             
              display.print("Humidity:");
              display.print(humidityTemp);
              display.println(" %");           
              //-------------SSD 1306 Display-------------------//
              display.setCursor(0,24); 
              display.println("http://alex9ufo.blogspot.com/");
              display.display();
              //-------------SSD 1306 Display-------------------//
            }
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println("Connection: close");
            client.println();
            // your actual web page that displays temperature and humidity
            client.println("<!DOCTYPE HTML>");
            client.println("<html>");
            client.println("<head></head><body><h1>ESP8266 - Temperature and Humidity</h1><h3>Temperature in Celsius: ");
            client.println(celsiusTemp);
            client.println("*C</h3><h3>Temperature in Fahrenheit: ");
            client.println(fahrenheitTemp);
            client.println("*F</h3><h3>Humidity: ");
            client.println(humidityTemp);
            client.println("%</h3><h3>");
            client.println("</body></html>");   
            break;
        }
        if (c == '\n') {
          // when starts reading a new line
          blank_line = true;
        }
        else if (c != '\r') {
          // when finds a character on the current line
          blank_line = false;
        }
      }
    } 
    // closing the client connection
    delay(1);
    client.stop();
    Serial.println("Client disconnected.");
 
  }


OLED SSD1306 Display







//D1 --SSD1305 SCL
//D2 --SSD1306 SDA

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET LED_BUILTIN  //4
Adafruit_SSD1306 display(OLED_RESET);

//#if (SSD1306_LCDHEIGHT != 64)
//#error("Height incorrect, please fix Adafruit_SSD1306.h!");
//#endif

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

  // Clear the buffer.
  display.clearDisplay();
  display.display();

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Hello from:");
  display.println("http://alex9ufo.blogspot.com/");
  display.display();

}

void loop() {
  // put your main code here, to run repeatedly:

}

2018年6月20日 星期三

NodeMCU Starter Kit - Neo










NodeMCU Starter Kit - Neo

NodeMCU Analog Input on Arduino IDE 

This tutorial of Robo India explains the basics of input and output programming in physical computing world. This tutorial teaches how to take analog input from NodeMCU.

NodeMCU Analog Output on Arduino IDE 

This tutorial of Robo India explains the basics of input and output programming in physical computing world. This tutorial teaches how to take analog output from NodeMCU.

NodeMCU Serial Monitor on Arduino IDE 

This tutorial of Robo India explains the basics of serial monitor of Arduino IDE for NodeMCU.

NodeMCU i2c Scanner on Arduino IDE 

This tutorial of Robo India explains how to get address of i2c device connected to a NodeMCU using Arduino IDE.

NodeMCU Weather Station on Arduino IDE 

This tutorial of Robo India is to make an online weather station on NodeMCU with Arduino IDE.

NodeMCU Temperature, Humidity data upload on Thingspeak on Arduino IDE 

This tutorial of Robo India explains how to store and upload the weather data of DHT11 temperature and humidity sensor on cloud ( ThingSpeak.com) using wifi modem NodeMCU.

NodeMCU on Arduino - Introduction 

This tutorial of Robo India explains how to use NodeMCU on Arduino IDE.

NodeMCU RGB LED on Arduino IDE 

This tutorial of Robo India explains how to use RGB LED on NodeMCU using Arduino IDE.

NodeMCU Switching Using Transistor on Arduino IDE 

This tutorial of Robo India explains how to a transistor as a switch on NodeMCU using Arduino IDE.

NodeMCU Seven Segment Display on Arduino IDE 

This tutorial of Robo India explains how to use a seven segment display on NodeMCU using Arudino IDE.

NodeMCU connecting to internet on Arduino IDE 

This tutorial of Robo India is a basic tutorial to connect a NodeMCU wifi module to the internet. This tutorial is based on Arduino IDE.

NodeMCU Digital Output - LED Blinking on Arduino IDE 

This tutorial of Robo India explains the basics of input and output programming in physical computing world. This tutorial teaches how to take digital output from NodeMCU on Arduion IDE. The output is taken on LED, It glows for a second and remain off for a second.

NodeMCU 16x2 LCD on Arduino IDE 

This tutorial explains how to use 16x2 LCD on NodeMCU wifi development board using Arduino IDE.

NodeMCU LDR on Arduino IDE 

This tutorial of Robo India explains how to use LDR on NodeMCU using Arduino IDE.

NodeMCU IR proximity & Color Detection on Arduino IDE 

This tutorial of Robo India explains how to use IR LED and photo diode as a color detection sensor and as a proximity detection sensor.

DHT11 Temperature & Humidity sensor on NodeMCU using Arduino IDE 

Robo India presents tutorial on how to read temperature and humidity data through DHT11 sensor using ESP8266 wifi module on NODEMCU LUA platform.

NodeMCU on Arduino IDE - Getting MAC address 

This tutorial of Robo India explains how to get MAC address of NodeMCU using Aruduino IDE.



NodeMCU Digital Input with Output Arduino IDE 

This tutorial of Robo India explains the basics of input and output programming in physical computing world. This tutorial teaches how to take digital input and show that as an output on NodeMCU on Arduion IDE. The input is taken through switch and the output is taken on LED, the LED glows when button is pressed.

2018年6月17日 星期日

IoT Sharing


Introduction to ESP32

Demo 1: Blinky - a Hello World on Arduino ESP32

Demo 2: How to use multiple Serial port on Arduino ESP32

Demo 3: How to use Arduino ESP32 to read temperature/humidity from DHT11/DHT22

Demo 4: How to use Arduino ESP32 to display information on I2C LCD

Demo 5: How to use Arduino ESP32 to display information on SPI LED matrix
  
Demo 6: How to use Arduino ESP32 to display information on OLED

Demo 7: How to use Arduino ESP32 to store data to sdcard

Demo 8: How to use TCP/IP with Arduino ESP32

Demo 9: How to use mDNS to resolve host names to Arduino ESP32 IP addresses

Demo 10: How to turn the Arduino ESP32 into an Access Point

Demo 11: How to use SmartConfig on Arduino ESP32

Demo 12: How to turn the Arduino ESP32 into a Web Server

Demo 13: How to display temperature/humidity using Google Chart/Jquery and control LED through Arduino ESP32 Web Server

Demo 14: How to use MQTT and Arduino ESP32 to build a simple Smart home system

Demo 15: How to build a system to update Price Tag automatically using Arduino ESP32

Demo 16: How to update firmware OTA for a batch of Arduino ESP32

Why Finite State Machine (FSM) is important to Arduino ESP32

Demo 17: Arduino ESP32/ESP8266 WebGPIO - control GPIO from web
Arduino ESP32 FreeRTOS 1: How to create a task

Demo 19: How to use UDP/IP with Arduino ESP32

Demo 20: How to control a Servo via Arduino ESP32 Web Server

Demo 21: How to use interrupt in Arduino ESP32

How to get the IP address of a node by its mdns host name in Arduino ESP32

Demo 22: How to use Timer interrupt in Arduino ESP32

Demo 23: How to use Preferences to backup Arduino ESP32 data in main flash memory when power is off

Demo 24: How to bring ESP32 to low power-sleep mode to extend battery life

Demo 25: How to configure ESP32 Dual core - Multicore in Arduino ESP32

Demo 26: How to use Arduino ESP32 I2S to play wav music file from sdcard

Demo 27: How to use Arduino ESP32 BLE (Bluetooth Low Energy) as a GATT server

Demo 28: How to use Arduino ESP32 BLE (Bluetooth Low Energy) as a GATT client

Demo 29: How to use HTTPS in Arduino ESP32

Demo 30: How to use ESP32 MQTTS with MQTTS Mosquitto broker (TLS/SSL)

Demo 31: How to use Arduino ESP32 CAN interface

Demo 32: Simple Machine Learning - Artificial neural network demo using Arduino ESP32


Demo 34: firmware update OTA for ESP32 using HTTP and sdcard

Demo 35: firmware update OTA for ESP32 directly using HTTP 

Demo 36: Firmware update OTA via ESP Http Web Server

Demo 37: Display distance measured by ultrasonic sensor using module 7-segment-LED-N-Digits

Demo 38: How to decode error/exception "CPU halted" of ESP on Arduino 

Demo 39: Demo 39: ESP multipart upload a file and download a file via HTTP

Demo 40: Create a Facebook Messenger chat bot for monitoring and controlling home devices using Raspberry/Orange Pi and ESP32/8266

Demo 41: ESP32 connects with nRF24L01 2.4 GHz wireless chip

Demo 42: How to build an IoT Dashboard using Node-Red dashboard and ESP

MQTT Explorer 與 Node-Red 介面的實驗

 MQTT Explorer 與 Node-Red 介面的實驗 MQTT EXplorer 與 Node-Red介面的設定 (1) 設定  MQTT EXplorer Client    (2)        Node-Red LED ON  --> MQTT Explor...