Skip to content

Commit 9d3d433

Browse files
Merge pull request #22 from AIS-DeviceIntegration/main
Update and Fix Library AIS Magellan IoT Platform
2 parents c13c5b4 + 093c7da commit 9d3d433

66 files changed

Lines changed: 1499 additions & 1567 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Magellan/example_MQTT/ConnectWithESP32wifi/ConnectWithESP32wifi.ino

Lines changed: 0 additions & 49 deletions
This file was deleted.

Magellan/example_MQTT/OTA/autoUpdate/autoUpdate.ino

Lines changed: 0 additions & 39 deletions
This file was deleted.

Magellan/example_MQTT/OTA/manualUpdate/manualUpdate.ino

Lines changed: 0 additions & 71 deletions
This file was deleted.

Magellan/example_MQTT/OTA/utilityInformation/utilityInformation.ino

Lines changed: 0 additions & 112 deletions
This file was deleted.

README.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ AIS 4G Board เป็นบอร์ดที่รวมไมโครคอ
124124

125125
### สมัคร AIS Playground และ Magellan Platform
126126

127-
* เข้าไปที่ https://magellan.ais.co.th/ กด REGISTER เพื่อสมัครสมาชิก หากไม่มี Account ของ AIS Playground ให้กดเลือก [Register](https://apisgl.ais.co.th/auth/v3.1/oauth/authorize?response_type=code&client_id=iQftE1wqrGJMCbco8D4MADHySRZpgMXlI5tU3sBYNmY%3D&redirect_uri=https%3A%2F%2Fmagellan.ais.co.th%2F&state=sgl&scope=profile#) กรอกข้อมูลแล้วกด ปุ่ม Done จากนั้นรอ Email ยืนยัน
127+
* เข้าไปที่ https://enterprise-magellan.ais.co.th/ กด REGISTER เพื่อสมัครสมาชิก หากไม่มี Account ของ AIS Playground ให้กดเลือก [Register](https://apisgl.ais.co.th/auth/v3.1/oauth/authorize?response_type=code&client_id=iQftE1wqrGJMCbco8D4MADHySRZpgMXlI5tU3sBYNmY%3D&redirect_uri=https%3A%2F%2Fmagellan.ais.co.th%2F&state=sgl&scope=profile#) กรอกข้อมูลแล้วกด ปุ่ม Done จากนั้นรอ Email ยืนยัน
128128
* เมื่อได้รับ Email ยืนยันเรียบร้อยแล้ว สามารถ Login ใช้งาน Magellan Platform ได้ผ่าน Email ที่สมัครไว้
129129

130130
### ลงทะเบียน Device และสร้างโปรเจค
@@ -277,7 +277,7 @@ AIS 4G Board เป็นบอร์ดที่รวมไมโครคอ
277277
ใช้เชื่อมต่อ รับ-ส่งข้อมูลกับ Azure IoT Central มีคำสั่งเหมือนกับ `AzureIoTHub.h` ทุกประการ ยกเว้นตอนสร้างออปเจค ให้สร้างโดยใช้คำสั่ง `AzureIoTCentral iot;` แทน
278278
<a name="SDK_MAGELLAN"></a>
279279

280-
![Library Version](https://img.shields.io/badge/SDK_Magellan_4G_Board_Version-1.2.0-blue)
280+
![Library Version](https://img.shields.io/badge/SDK_Magellan_4G_Board_Version-1.2.1-blue)
281281
### `#include <MAGELLAN_SIM7600E_MQTT.h>`
282282

283283
ใช้เชื่อมต่อ รับ-ส่งข้อมูลกับ Magellan Platform ด้วยโปรโตคอล MQTT (Message Queuing Telemetry Transport)
@@ -307,6 +307,8 @@ AIS 4G Board เป็นบอร์ดที่รวมไมโครคอ
307307

308308
* `Subscribes (lists of subscribe)`
309309
* `magel.subscribes.([](){ Function Register Subscribe Here })` ใช้ Subscribe Topic หรือ Subscribe Function ภายใน Function subscribes นี้เมื่อมีการ connect หรือ reconnect ตัว function นี้จะ triger function ที่บรรจุไว้ภายในให้อัตโนมัติให้อัตโนมัติเมื่ออุปกรณ์สามารถเชื่อมต่อ Magellan Platform ได้
310+
* `Subscribe Auto`
311+
* `magel.subscribesHandler.([](){ Function Register Subscribe Here })` ใช้สำหรับ Handle Subscribe และ Resume topic ที่จะ Subscribe แต่ไม่จำเป็นต้องเรียก Function magel.subscribe.xxx แล้วเนื่องจาก function นี้จะทำการ subscribe topic ตาม Callback ที่เราได้ Register ไว้ไม่ว่าจะเป็น Control, ServerConfig,etc.
310312
# วิธีใช้งาน Subscribes
311313
```cpp
312314
void loop()
@@ -336,9 +338,32 @@ AIS 4G Board เป็นบอร์ดที่รวมไมโครคอ
336338
/* do something */
337339
}
338340
```
341+
## 🎉 NEW version 1.2.1 (auto subscribe follow by Register Callback)
342+
```cpp
343+
void doSomeThingOnceAfterReconnect(){
344+
345+
Serial.println("Connected!!!");
346+
}
347+
348+
void loop()
349+
{
350+
magel.loop();
351+
magel.subscribesHandler(doSomeThingOnceAfterReconnect);
352+
/* do something */
353+
}
354+
```
355+
## 🎉 ใน version 1.2.1 Magellan SDK ได้มีการเปลี่ยน FS library
356+
* Default จาก `SPIFFS` มาใช้งานเป็น `LittleFS` หาต้องการใช้งาน SPIFFS
357+
ให้ `Declare Macro` ไว้เหนือการ Include Magellan SDK ดังนี้
358+
```cpp
359+
#include <Arduino.h>
360+
#define MG_USE_SPIFFS
361+
#include <MAGELLAN_SIM7600E_MQTT.h>
362+
```
339363

340364
* `Interval timer`
341-
* `magel.interval(unsigned int second, []() { function here })` ใช้กำหนดช่วงเวลาให้ Function ที่ประกาศภายใน Interval ทำงานในแต่ละรอบโดยมีหน่วยเป็น Second
365+
* `magel.interval(unsigned int second, []() { function here })` ใช้กำหนดช่วงเวลาให้ Function ที่ประกาศภายใน Interval ทำงานในแต่ละรอบโดยมีหน่วยเป็น Second
366+
### ⚠️ `magel.interval` ใน 1 loop function timer ใช้ได้แค่ 1 อันเท่านั้นหากใช้งานมากกว่า 1 function จะทำงานแค่บรรทัดที่เขียนไว้ล่างสุด.
342367
>ℹ️ Information`Function "Interval" เป็น Function optional เท่านั้น สามารถใช้ function timer ทดแทนได้`
343368
344369
* `Check Connection`
@@ -387,7 +412,7 @@ AIS 4G Board เป็นบอร์ดที่รวมไมโครคอ
387412
* `.setDuration(unsigned int duration)`
388413
* `.generateMsgId()`
389414

390-
>⚠️ Warning`หากมีการเปิดใช้งาน enabled retransmit ด้วย setEnabled จะมีการ report จนกว่าจะได้ Response, msgId โดยทุกๆ duration และ repeat ที่ตั้งค่าไว้ซึ่งจะใช้เวลาในการทำงาน เนื่องจากต้องรอการตอบกลับ ทั้งนี้ขึ้นอยู่กับคุณภาพของสัญญาณของ network connection ของอุปกรณ์แต่สามารถมั่นใจได้ว่า message ของที่ส่งไปถึงหรือไม่ หรือในกรณีผิดพลาดสามารถ track ได้จากจาก`[Status code](https://magellan.ais.co.th/api-document/3/3)
415+
>⚠️ Warning`หากมีการเปิดใช้งาน enabled retransmit ด้วย setEnabled จะมีการ report จนกว่าจะได้ Response, msgId โดยทุกๆ duration และ repeat ที่ตั้งค่าไว้ซึ่งจะใช้เวลาในการทำงาน เนื่องจากต้องรอการตอบกลับ ทั้งนี้ขึ้นอยู่กับคุณภาพของสัญญาณของ network connection ของอุปกรณ์แต่สามารถมั่นใจได้ว่า message ของที่ส่งไปถึงหรือไม่ หรือในกรณีผิดพลาดสามารถ track ได้จากจาก`[Status code](https://enterprise-magellan.ais.co.th/learningcenter/api-document/mqtt-apis-v2#response-status-codes)
391416
392417
# วิธีใช้งาน Report with message id ด้วย RetransmitSetting [เพิ่มเติม](#retransmitStructor)
393418
```cpp
@@ -462,7 +487,7 @@ AIS 4G Board เป็นบอร์ดที่รวมไมโครคอ
462487
void setup()
463488
{
464489
Serial.begin(115200);
465-
setting.endpoint = "magellan.ais.co.th"; //if not set *default: magellan.ais.co.th
490+
setting.endpoint = "device-entmagellan.ais.co.th"; //default is device-entmagellan.ais.co.th
466491
setting.clientBufferSize = defaultOTAbuffer; // if not set *default: 1024
467492
magel.begin(setting);
468493
//* callback getControl
@@ -475,7 +500,7 @@ AIS 4G Board เป็นบอร์ดที่รวมไมโครคอ
475500
}
476501
```
477502
* `หลังจาก decleare function callback getControl มาแล้วไม่ว่าจะ format 'JSON' หรือ 'Plaintext' ก็ตามหากทำการ triger control จาก widget บน platform เพื่อให้อุปกรณ์ได้รับค่า control แต่ตัวอุปกรณ์เกิด disconnect หรือปัญหาที่ไม่ได้รับ message value ทัน event นั้นๆ สามารถเรียกขอค่า control ที่ค้างหรือยังไม่ได้ Acknowledge ได้ดังนี้`
478-
>ℹ️ Information`หากทำการ Request control แล้วไม่มีค่าค้างอยู่ค่าที่จะได้รับเข้ามาใน Callback getControl จะมีแค่ code 40400 หากมีค้างอยู่จะได้รับ code 20000 และ value control` [Status code](https://magellan.ais.co.th/api-document/3/3)
503+
>ℹ️ Information`หากทำการ Request control แล้วไม่มีค่าค้างอยู่ค่าที่จะได้รับเข้ามาใน Callback getControl จะมีแค่ code 40400 หากมีค้างอยู่จะได้รับ code 20000 และ value control` [Status code](https://enterprise-magellan.ais.co.th/learningcenter/api-document/mqtt-apis-v2#response-status-codes)
479504
# วิธีการ Request control value ที่ค้างอยู่ (ยังไม่ได้รับการ Acknowledge จากอุปกรณ์)
480505
```cpp
481506
void loop()
@@ -509,7 +534,7 @@ AIS 4G Board เป็นบอร์ดที่รวมไมโครคอ
509534
void setup()
510535
{
511536
Serial.begin(115200);
512-
setting.endpoint = "magellan.ais.co.th"; //if not set *default: magellan.ais.co.th
537+
setting.endpoint = "device-entmagellan.ais.co.th"; //default is device-entmagellan.ais.co.th
513538
magel.begin(setting);
514539
magel.clientConfig.add("location", "15.0000, 58.0000"); //* update location once after connect platform
515540
magel.clientConfig.add("battery", 100); //* update battery level once after connect platform
@@ -538,7 +563,6 @@ AIS 4G Board เป็นบอร์ดที่รวมไมโครคอ
538563
void setup()
539564
{
540565
Serial.begin(115200);
541-
setting.endpoint = "magellan.ais.co.th"; //if not set *default: magellan.ais.co.th
542566
magel.begin(setting);
543567
magel.getResponse(UNIXTIME, [](EVENTS events)
544568
{ //* for get unixTime from magellan

0 commit comments

Comments
 (0)