LAB8: MCU send data to IoT platform

M5stack core send read data to SENSES IoT platform

อุปกรณ์ทดลอง

  1. M5stack demo board

การทดลองที่1: ส่งข้อมูลเซนเซอร์ DHT12 ขึ้น Dashboard ของ Senses IoT platform

สร้าง Widget บน Dashboard สำหรับ แสดงข้อมูลอุณภูมิ และ ความชื้น ที่ได้รับจาก sensor DHT12

  1. ไปที่หน้า Dashboard ที่สร้างไว้(วิธีการสร้างdashboard คลิ๊ก วิธีสร้าง-Dashboard ) >> ไปที่ edit Dashboard >>เลือกสร้าง widget Gauge >> setting >>ตั้งค่าดังภาพด้านล่าง

2. เลือกสร้าง widget chat>> setting >>ตั้งค่าดังภาพด้านล่าง>>Save

3. เมื่อตั้งค่าทั้งสอง widget เรียบร้อยแล้ว ให้กด Save edited Dashboard

4. กด F5 Dashboard จะแสดงหน้าต่าง widget พร้อมใช้งาน

ต่อวงจรระหว่าง M5Stack กับ DHT12 Sensor

M5Stack (use pin I2C )

sensor DHT12

21D

SDA

22C

SCL

GND

GND

Code M5Stack send data sensor DHT12 to dashboard


#include "Senses_wifi_esp32.h"
#include <WiFi.h>
#include <DHT12.h>

const char *ssid  = "...";   //  your network SSID      
const char *pass = "...";    //your network password  
const char *userid = "..." ;  // channel ID number of your Dashboard
const char * key = "..."; // Paste your Write Key of Dashboard 

WiFiClient  client;
DHT12 dht12;
Senses_wifi_esp32 myiot;

void setup()
{
    Serial.begin(115200);
    delay(10);
    dht12.begin();

// We start by connecting to a WiFi network and sense platform
 Serial.println("Senses Platform status: ");
 String response = myiot.connect(ssid, pass, userid, key);
  Serial.println(response);
    
}

void loop (){
  float tmp = dht12.readTemperature();
  float humid = dht12.readHumidity();

if (isnan(tmp) || isnan(humid)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
// myiot.send(send data to slot_number 1 of dashboard, send tmp data)
 String response = myiot.send(1,tmp); 
 Serial.println(response);
 Serial.print("Temperature :");
 Serial.println(tmp);

// myiot.send(send data to slot_number 2 of dashboard ,send Humid data) 
  response = myiot.send(2, humid); 
  Serial.println(response);
  Serial.print("Humidity :");
  Serial.println(humid);
  delay(2000);

}  

บันทึกผล หน้า Serial monitor และ dashboard ที่แสดงค่าข้อมูลที่ได้รับ

....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

การทดลองที่2: ส่งข้อมูลเซนเซอร์ BMP280 ขึ้น Dashboard ของ Senses IoT platform

สร้าง Widget บน Dashboard สำหรับ แสดงข้อมูลความดันอากาศ จาก BMP280 sensor

  1. การสร้างdashboard ใหม่มา (วิธีสร้าง dashboard คลิ๊ก วิธีสร้าง-Dashboard )

  2. หลังจากสร้าง Dashbboard ใหม่เรียบร้อยแล้วให้คลิ๊กที่ Dashborad menager >> เลือก Dashboard อันใหม่

3. ไปที่ edit Dashboard >>เลือกสร้าง widget Gauge และ widget chat แบบการทดลองที่1

4. เมื่อตั้งค่าทั้งสอง widget เรียบร้อยแล้ว ให้กด Save edited dashboard

5. กด F5 Dashboard จะแสดงหน้าต่าง widget พร้อมใช้งาน

ต่อวงจรระหว่าง M5Stack กับ BMP280 Sensor

M5Stack (use pin I2C )

sensor BMP280

21D

SDA

22C

SCL

GND

GND

Code M5Stack send data sensor BMP280 to dashboard


#include "Senses_wifi_esp32.h"
#include <Wire.h>
#include "Adafruit_Sensor.h"
#include <Adafruit_BMP280.h>

const char *ssid  = "....";   // your network SSID (Hot spotname)     
const char *pass = "....";    // your network password  
const char *userid = "...." ;  // channel ID number (Senses ID)
const char * key = "....";    // Device key 
//------------------------------------------------------------------
WiFiClient  client;
Senses_wifi_esp32 myiot;
Adafruit_BMP280 bme;

void setup()
{
    Serial.begin(115200);
    delay(10);
    Wire.begin();
    if (!bme.begin(0x76)){
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
        while (1);
    }
    // We start by connecting to a WiFi network and sense platform
    Serial.println("Connect to hot spot");
    String response = myiot.connect(ssid, pass, userid, key);
    Serial.println(response);
    
}

void loop (){
  float pressure = bme.readPressure();
  String response = myiot.send(1,pressure); // myiot.send(slot_mnumber on SensesPlatform,data)
  Serial.println(response);
  Serial.print("Air pressure :");
  Serial.println(pressure);

}  

บันทึกผล หน้า Serial monitor และ dashboard ที่แสดงค่าข้อมูลที่ได้รับ

....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

การทดลองที่3: ส่งข้อมูลเซนเซอร์ Microphone และ light ขึ้น Dashboard ของ Senses IoT platform

สร้าง Widget บน Dashboard สำหรับ แสดงข้อมูลระดับความเข้มแสง ที่ได้รับจาก sensor LDR และ ข้อมูล เสียง ที่ได้รับจาก Microphone

  1. เนื่องจาก Senses IoT platform ให้สิทธิสำหรับผู้ใช้ฟรี ในการสร้าง dashboard ได้เพียง 2 Dashboard ดังนั้นเลือก 1 dashboard มาทำการ edit เพื่อสำหรับรับค่าข้อมูลของ sensor LDR และ เสียง จากMicrophone

  2. ไปที่ edit Dashboard

  3. เลือกสร้าง widget Gauge 2 ตัว สำหรับแสดงค่า แสง เสียง ตั้งค่าตามภาพด้านล่าง

4. เลือกสร้าง widget chat สำหรับแสดงค่า แสง แบบ chat ตั้งค่าตามภาพด้านล่าง

5. เมื่อตั้งค่าเรียบร้อยแล้ว ให้กด Save edited dashboard

6. กด F5 Dashboard จะแสดงหน้าต่าง widget พร้อมใช้งาน

ต่อวงจรระหว่าง M5Stack กับ Light Sensor และ Microphone

M5Stack

sensor Light

Microphone

36

Analog

-

35

-

Analog

2

Digital

-

5

-

Digital

GND

GND

GND

Code M5Stack send data (Analog and Digital data ) of Light sensor and Microphone to Dashboard


#include "Senses_wifi_esp32.h"
#include <WiFi.h>


const char *ssid  = "....";   // your network SSID (Hot spotname)     
const char *pass = "....";    // your network password  
const char *userid = "...." ;  // channel ID number (Senses ID)
const char * key = "....";    // Device key 
//------------------------------------------------------------------

WiFiClient  client;
Senses_wifi_esp32 myiot;
const int Analog1 = 36;
const int Analog2 = 35;
const int Digital1 = 2;
const int Digital2 = 5;

void setup()
{
    Serial.begin(115200);
    delay(10);
    pinMode(Digital1, INPUT_PULLUP);
    pinMode(Digital2, INPUT_PULLUP);
    // We start by connecting to a WiFi network and sense platform
    Serial.println("Connect to hot spot");
    String response = myiot.connect(ssid, pass, userid, key);
    Serial.println(response);
    
}

void loop (){
  float LightA = analogRead(Analog1);
  float LightD = digitalRead(Digital1);
  float MicA = analogRead(Analog2);
  float MicD = digitalRead(Digital2);

  String response = myiot.send(1,LightA); // myiot.send(slot_mnumber on SensesPlatform,data)
  Serial.println(response);
  Serial.print("Light dencity :");
  Serial.println(LightA);

  response = myiot.send(2, LightD); // myiot.send(slot_mnumber on SensesPlatform,data)
  Serial.println(response);
  Serial.print("Light status :");
  Serial.println(LightD);

  response = myiot.send(3,MicA); // myiot.send(slot_mnumber on SensesPlatform,data)
  Serial.println(response);
  Serial.print("Sound volumn :");
  Serial.println(MicA);

  response = myiot.send(4, MicD); // myiot.send(slot_mnumber on SensesPlatform,data)
  Serial.println(response);
  Serial.print("Sound status :");
  Serial.println(MicD);
  delay(500);

}  

บันทึกผล หน้า Serial monitor และ dashboard ที่แสดงค่าข้อมูลที่ได้รับ

....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Homework: เลือกเซนเซอร์ 3 ประเภท และออกแบบหน้า Dashboard สำหรับแสดงค่า sensor และเขียนโปรแกรมส่งข้อมูลเซนเซอร์ ขึ้น Dashboard

Update: 2022

Author: Soontree Jaikhong (AIC-Researcher)

Author: Thanaluk Pranekunakol (AIC-Researcher)

Last updated

Assoc. Prof. Wiroon Sriborrirux, Founder of Advance Innovation Center (AIC) and Bangsaen Design House (BDH), Electrical Engineering Department, Faculty of Engineering, Burapha University