IoT Kit 2から温度の送信

IoT Study Kit 2からFirebaseへ温度データの送信。

 

IoT Sensor

UbiSense Ver2を利用。

結線

プログラム1

3連ベースで、ESP8266, LED Matrix, SHT30を装着。温度と湿度を計測。

WEMOS_SHT3x_Arduino_Libraryを使用。

https://github.com/wemos/WEMOS_SHT3x_Arduino_Library

ただの温度と湿度の表示サンプル。

#include <WEMOS_SHT3X.h>

SHT3X sht30(0x45);

void setup() {

  Serial.begin(115200);

}

void loop() {

  if(sht30.get()==0){
    Serial.print("Temperature in Celsius : ");
    Serial.println(sht30.cTemp);
    Serial.print("Temperature in Fahrenheit : ");
    Serial.println(sht30.fTemp);
    Serial.print("Relative Humidity : ");
    Serial.println(sht30.humidity);
    Serial.println();
  }
  else
  {
    Serial.println("Error!");
  }
  delay(1000);

}

参考

  1. http://stigern.net/blog/using-wemos-d1-mini-sht30-sensor-shield/

プログラム2

検出した温度をFirebaseに送信。

#include "Firebase_ESP_Client.h"
#include  <ESP8266WiFi.h>

#define FIREBASE_HOST "test2-***.firebaseio.com"                    // Enter the Firebase Database URL Without Https and backslash
#define API_KEY "AIzaSyDfl-s-**** "

FirebaseData fbdo;

FirebaseAuth auth;
FirebaseConfig config;

FirebaseJson json;

#define WIFI_SSID "SSID003"                     // Change the name of your WIFI
#define WIFI_PASSWORD "12345"                        // Change the password of your WIFI

#define USER_EMAIL "xxx@yyy.net"
#define USER_PASSWORD "12345"

#include <WEMOS_SHT3X.h>
SHT3X sht30(0x45);

void setup() 
{
  Serial.begin(115200);
  WiFi.begin (WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) 
  {
   delay(500);
   Serial.print(".");
  }
  Serial.println ("");
  Serial.println ("WiFi Connected!");

  /* Assign the project host and api key (required) */
  config.host = FIREBASE_HOST;
  config.api_key = API_KEY;

  /* Assign the user sign in credentials */
  auth.user.email = USER_EMAIL;
  auth.user.password = USER_PASSWORD;

  Firebase.begin(&config, &auth);
  Firebase.reconnectWiFi(true);
}

void loop() 
{
 float h =0;
 float t = 0;         // Reading temperature as Celsius (the default)

  if(sht30.get()==0){
    t = sht30.cTemp;
    h = sht30.humidity;
    Serial.print("Temperature in Celsius : ");
    Serial.println(sht30.cTemp);
    Serial.print("Temperature in Fahrenheit : ");
    Serial.println(sht30.fTemp);
    Serial.print("Relative Humidity : ");
    Serial.println(sht30.humidity);
    Serial.println();
  }
  else
  {
    Serial.println("SHT30 Error!");
  }

  
  Firebase.RTDB.setFloat (&fbdo, "Temperature",t);
  Serial.println(t);
  Firebase.RTDB.setFloat (&fbdo, "Humidity",h);
  Serial.println(h);
  delay(200);
}