[IoT EDGE V.3 Board] Connect Arduino Cloud IoT

Supphakarin Phoruangrong
4 min readJun 10, 2021

--

Device

  • IoT EDGE V.3 Board
  • HW 691 MLX90614ESF

Software

  • Arduino IDE

Library for Arduino IDE

Model Test

  • IoT EDGE V.3 Board (Receiver)
  • HW 691 MLX90614ESF (Sensor)

Source Code

  • IoT EDGE V.3 + Arduino IoT Cloud (Download)

Explain

ในการทดสอบการใช้งานบอร์ด IoT EAGE V.3 ในบทความนี้จะทดสอบการใช้ Could ของ Arduino IoT โดยจะส่งข้อมูลและแสดงผลผ่าน Dashboard

Method

1.สมัครสมาชิก Arduino IoT Cloud ที่ Link โดยใช้ Gmail or Apple ID

2.กำหนดชื่อ Username และ Create account

3.สร้าง Thing อุปกรณ์ที่เราจะใช้งาน CREATE THING

4.ตั้งชื่อ Project แล้ว Add Device

5.เลือก Set up a 3rd Party device → ESP32 → ESP32 Dev Module

6.ตั้งชื่ออุปกรณ์

7. Download the PDF เพื่อนำ Device ID และ Secret Key ไปใส่ใน code

8.สร้างตัวแปลที่เราจะใช้งาน

9. ตั้งค่าตัวแปรที่เราจะใช้งาน และ ADD VARIABLE

10.เข้าไปที่ Sketch และ คลิก Open full editor

11.Download sketch

12.ทำการแตกไฟล์ แล้ว เปิด Filne .ino ที่ Download มา เราจะได้ ไฟล์ ย่อยมา 3 ไฟล์

  • ไฟล์แรกใช้เขียน code กำหนดการทำงานต่างๆ
  • arduino_secrets.h ใส่รหัส WiFi / Password และ SECRET
  • thingProperties.h ใส่ THING_ID(จะอยู่หน้าสร้าง Device มุมล่างซ้าย) / DEVICE_LOGIN_NAME

13.เขียน Code ไฟล์นำหนดการทำงาน

#include "arduino_secrets.h"
/*
Sketch generated by the Arduino IoT Cloud Thing "Temp"
https://create.arduino.cc/cloud/things/c51785ac-0290-47d5-8131-be4ee174e0ca
Arduino IoT Cloud Variables descriptionThe following variables are automatically generated and updated when changes are made to the Thingint temp;Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"void setup() {
// Initialize serial and wait for port to open:
Serial.begin(115200);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
mlx.begin();
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
temp = mlx.readAmbientTempC();
// Your code here
}

14. arduino_secrets.h code

#define SECRET_SSID "=NAME WiFi"
#define SECRET_PASS "PASS WiFi"
#define SECRET_DEVICE_KEY "SECRET KEY "

15. thingProperties.h code

// Code generated by Arduino IoT Cloud, DO NOT EDIT.#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();const char THING_ID[] = "c51785ac-0290-47d5-8131-be4ee174e0ca";
const char DEVICE_LOGIN_NAME[] = "e7c7cff2-85f9-4ea7-a03a-a5d86a5fd9ae";
const char SSID[] = SECRET_SSID; // Network SSID (name)
const char PASS[] = SECRET_PASS; // Network password (use for WPA, or use as key for WEP)
const char DEVICE_KEY[] = SECRET_DEVICE_KEY; // Secret device password
int temp;void initProperties(){ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
ArduinoCloud.setThingId(THING_ID);
ArduinoCloud.addProperty(temp, READ, 1 * SECONDS, NULL);
}WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

16.เลือก board ESP32 Dev Module แล้ว Upload

17.สร้าง Deshboard แสดงผลข้อมูล Temp

18.คลิก Edit ทำการแก้ไข้ ชื่อ และสร้าง Gauge

19.กำหนดชื่อตัวแปร และทำการ Link

20.เสร็จ รอทำงาน Online Board ขึ้นมาเพื่อให้เกิดการส่งค่าผ่าน Arduino IoT Could

Reference

--

--

No responses yet