LAB8: MCU send data to IoT platform
M5stack core send read data to SENSES IoT platform
- 1.M5stack demo board
- 1.ไปที่หน้า Dashboard ที่สร้างไว้(วิธีการสร้างdashboard คลิ๊ก วิธีสร้าง-Dashboard ) >> ไปที่ edit Dashboard >>เลือกสร้าง widget Gauge >> setting >>ตั้งค่าดังภาพด้านล่าง

สร้าง Widget gauge

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

สร้าง widget chat

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

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

widget on Dashboard
M5Stack (use pin I2C ) | sensor DHT12 |
21D | SDA |
22C | SCL |
GND | GND |
#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);
}
....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
- 1.
- 2.หลังจากสร้าง Dashbboard ใหม่เรียบร้อยแล้วให้คลิ๊กที่ Dashborad menager >> เลือก Dashboard อันใหม่


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

Widget setting of Widget Gauge

Widget setting of Widget Chat
4. เมื่อตั้งค่าทั้งสอง widget เรียบร้อยแล้ว ให้กด Save edited dashboard
5. กด F5 Dashboard จะแสดงหน้าต่าง widget พร้อมใช้งาน
M5Stack (use pin I2C ) | sensor BMP280 |
21D | SDA |
22C | SCL |
GND | GND |
#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);
}
....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
- 1.เนื่องจาก Senses IoT platform ให้สิทธิสำหรับผู้ใช้ฟรี ในการสร้าง dashboard ได้เพียง 2 Dashboard ดังนั้นเลือก 1 dashboard มาทำการ edit เพื่อสำหรับรับค่าข้อมูลของ sensor LDR และ เสียง จากMicrophone
- 2.ไปที่ edit Dashboard
- 3.เลือกสร้าง widget Gauge 2 ตัว สำหรับแสดงค่า แสง เสียง ตั้งค่าตามภาพด้านล่าง

Widget setting of Light widget gauge

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

Widget setting of Widget MixedChat
5. เมื่อตั้งค่าเรียบร้อยแล้ว ให้กด Save edited dashboard
6. กด F5 Dashboard จะแสดงหน้าต่าง widget พร้อมใช้งาน
M5Stack | sensor Light | Microphone |
36 | Analog | - |
35 | - | Analog |
2 | Digital | - |
5 | - | Digital |
GND | GND | GND |
#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);
}
....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Last modified 2yr ago