NB-IOT : Mega2560
จะว่าไปแล้ว NB-IOT ก็ออกมานานมากแล้ว มาถึงปี 2019 ถึงจะได้เริ่มมาลองเล่นบ้าง ด้วยเพราะปัญหาว่า วิธีการสื่อสารด้วย Lora ก็จะมีค่าใช้จ่ายที่สูง ในขณะที่การจะติดตั้งระบบ WiFI ก็มีขั้นตอนมากมาย หรือหากจะจาก GSM-Shield ก็พบว่าไม่สะดวกมากนัก จึงต้องทดลอง NB-IOT
ส่วนสาเหตุที่ทำให้ไม่อยากลอง NB-IOT ตั้งแต่แรก เพราะเราไม่อยากใช้ระบบสาธารณะ หรือ Magellan แต่เมื่อได้ศึกษาไปพบว่า เราสามารถที่จะส่งไปยัง Server อื่นๆ ภายใต้ UDP Protocol แต่ถึงต้องนี้ ยังลองเล่นแค่การส่งไปยัง airmagellan.io กันก่อน
ทั้งนี้ก็ต้องไปลองใช้ สมัครใช้ aismagellan.io กันก่อนนะครับ
NB-IOT ถูกออกแบบมาให้ใช้ได้กับ Arduino ได้หลายรุ่น แต่มักจะใช้กันกับ Arduino Uno แต่สำหรับงานที่ต้องการ sensor หรือการควบคุมจำนวนมาก ก็ต้องอาศัยบอร์ดจำพวก Mega2560 เป็นต้น
มาสรุปวิธีการใช้ NB-IOT กับ Mega2560 กันเลยนะครับ
- ทำการเชื่อมต่อขา 9 บน NB-IOT เข้ากับ 46 ของMega
- ทำการเชื่อมต่อขา 8 บน NB-IOT เข้ากับขา 48 ของ Mega
- เปิดโปรแกรมตัวอย่าง POST-Magellan และ อัพโหลดโค้ดตามรูป
#include <AltSoftSerial.h> /* supported board and hardware competible Arduino UNO please use software serial on pin8=RX pin9=TX and pin4=RST Arduino MEGA please use software serial on pin48=RX pin46=TX and pin4=RST NUCLEO_L476RG please use Hardware serial on pin2=RX pin8=TX and pin4=RST NodeMCU-32S please use Hardware serial on RX2=RX TX2=TX and 3V3=IOREF Pre required install library - Altsoftserial Example for post random data to Magellan IoT Platform please use payload with json format e.g. {"Temperature":25.5,"Humidity":90.4} and {"Location":["13.001","100.44"]} for plot the location on MAP | | latitude longitude and {"Lamp":0} or {"Lamp":1"} for show the Lamp status on dashboard */ #include "Magellan.h" Magellan magel; char auth[]="caf1b1b0-0ba8-11ea-810a-f990cf998f9d"; //Token Key you can get from magellan platform String payload; void setup() { Serial.begin(9600); magel.begin(auth); //init Magellan LIB } void loop() { /* Example send random temperature and humidity to Magellan IoT platform */ String Temperature=String(random(0,100)); String Humidity=String(random(0,100)); payload="{\"Temperature\":"+Temperature+",\"Humidity\":"+Humidity+"}"; //please provide payload with json format magel.post(payload); //post payload data to Magellan IoT platform }
โปรดสังเกต คำแนะนำในคอมเม้นท์ที่แนะนให้ทำการเชื่อมต่อขาตามนั้น โดยหากทำการใช้งานกับ Arduino Uno ก็ไม่ต้องทำการเชื่อมต่ออะไรเป็นพิเศษ
จากนั้นก็ทดลอง Run program โดยตรวจสอบฝั่ง Serial port จะได้ผลลัพธ์ตามรูป
และดูผลงานบน aismagellan.io
ที่เหลือลำดับต่อไปก็จะลองเล่น การอ่านค่าจาก sensor ต่างๆ ขึ้นระบบจริงและตามด้วยการใช้ UDP Protocol ไปยัง Server ตัวเอง
โปรดติดตามตอนต่อไปครับ