diff --git a/.gitignore b/.gitignore index 259148f..2f2def2 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,7 @@ *.exe *.out *.app + +# macOS +.DS_Store +*/.DS_Store` diff --git a/README.md b/README.md index 0027972..0bfed88 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,26 @@ # DLLN3X_zigbee_mesh_module_library This library allows you to use DLLN3X ZigBee mesh module very easily. +# Available Features + +1. Basic message sending and receiving. +2. Module address reading. +3. On-chip red led flashing control. +4. Configuration reading, modification (baud rate, address, etc.).(TODO) +5. Error Report.(TODO) +6. Link quality test.(TODO) +7. On-chip pin control.(TODO) + +# Example run results + +![example](./imgs/example.png) + # Change Log + +**V1.0.4 2023.1.26** + +- Bug fixes and stability improvements. + **V1.0.3 2023.1.12** - Bug fixed for example. diff --git a/examples/.DS_Store b/examples/.DS_Store deleted file mode 100644 index 4eb2eaf..0000000 Binary files a/examples/.DS_Store and /dev/null differ diff --git a/examples/dlln3x_test/dlln3x_test.ino b/examples/dlln3x_test/dlln3x_test.ino index 6c9fd3a..6d058a3 100644 --- a/examples/dlln3x_test/dlln3x_test.ino +++ b/examples/dlln3x_test/dlln3x_test.ino @@ -7,29 +7,44 @@ void zigbee_call_back(uint8_t orig_port, uint8_t data[], int length) { switch (dest_port) { case 0x82: - { + { /* Do everything you want to do */ - printf("Hello from port 0x%X!",orig_port); + char temp[200]; + sprintf(temp, "Hello from port 0x%X: %s",orig_port,data); + Serial.println(temp); + break; + } + default: break; - - default: - break; - } } } void setup() { - dlln33.init(&Serial);// could be used like HardwareSerial(Serial1, Serial2 and etc.) or SoftwareSerial + Serial.begin(115200); + while (!Serial || millis() < 5000) + ; + dlln33.init(&Serial1);// could be used like HardwareSerial(Serial1, Serial2 and etc.) or SoftwareSerial dlln33.setcallback(zigbee_call_back); - printf("DLLN33 addr is 0x%X\n", dlln33.read_addr()); - zframe.src_port = 0x81; - zframe.des_port = 0x82; - *((uint16_t *)&zframe.remote_addrL) = dlln33.read_addr(); - strncpy((char*)zframe.data,"Hello to port 0x82!",21); - zframe.length = 21; - dlln33.send(&zframe); + while(dlln33.read_addr()==0) + { + Serial.println("Waiting for DLLN3X to connect........"); + delay(1000); + } + char temp[20]; + sprintf(temp, "DLLN3X addr: 0x%04X.",dlln33.read_addr()); + Serial.println(temp); } +uint64_t interval = 5000, pre_milli = 0; void loop() { dlln33.loop(); + if (millis() - pre_milli >= interval) { + zframe.src_port = 0x81; + zframe.des_port = 0x82; + *((uint16_t *)&zframe.remote_addrL) = dlln33.read_addr(); // send pkg to self. + strncpy((char*)zframe.data,"Hello to port 0x82!",19); + zframe.length = 19; + dlln33.send(&zframe); + pre_milli = millis(); + } } \ No newline at end of file diff --git a/imgs/example.png b/imgs/example.png new file mode 100644 index 0000000..e96ad34 Binary files /dev/null and b/imgs/example.png differ diff --git a/library.properties b/library.properties index 26e157c..eb70bd4 100644 --- a/library.properties +++ b/library.properties @@ -1,7 +1,7 @@ name= DLLN3X ZigBee Mesh Module Library -version= 1.0.3 -author= Duke Liu -maintainer= Duke Liu +version= 1.0.4 +author= Dylan Liu +maintainer= Dylan Liu sentence= This library allows you to use DLLN3X ZigBee mesh module very easily. paragraph= This library currently allows basic send and receive operations using the DLLN3X module, with more features to come. category= Communication diff --git a/src/.DS_Store b/src/.DS_Store deleted file mode 100644 index 7fe1c5e..0000000 Binary files a/src/.DS_Store and /dev/null differ diff --git a/src/DLLN3X.cpp b/src/DLLN3X.cpp index b2e23c2..1c6663c 100644 --- a/src/DLLN3X.cpp +++ b/src/DLLN3X.cpp @@ -8,7 +8,6 @@ void DLLN3X::init(HardwareSerial *DSerial) _DSerial = DSerial; DSerial->begin(115200); rled_blink(); - _clear(); read_addr(); } @@ -17,7 +16,6 @@ void DLLN3X::init(SoftwareSerial *DSerial) _DSerial = DSerial; DSerial->begin(115200); rled_blink(); - _clear(); read_addr(); } @@ -90,6 +88,8 @@ bool DLLN3X::recv(uint8_t *orig_port, _recv_lock = true; uint8_t buf[200] = ""; uint8_t head = 0, tail = 0; + if(_DSerial->available()<6) + return false; head = _DSerial->read(); if (head == 0xFE) { @@ -102,13 +102,16 @@ bool DLLN3X::recv(uint8_t *orig_port, int count = 0; for (int i = 0; i < *length; i++) { + while(_DSerial->available()<1); buf[count++] = _DSerial->read(); if (buf[count-1]==0xFE) { + while(_DSerial->available()<1); buf[count++]=_DSerial->read(); } } *length = count; + while(_DSerial->available()<1); _DSerial->read(); // read pkg tail *length = _depack(buf, data, *length); _recv_lock = false; @@ -127,7 +130,6 @@ bool DLLN3X::send(uint8_t orig_port, { if (orig_port<0x80) return false; - uint8_t send_buf[208] = {0xFE}, buf[200] = ""; uint8_t head = 0, buf_length = 0; buf_length = _pack(buf, data, length); @@ -155,7 +157,7 @@ void DLLN3X::rled_blink(uint8_t orig_port, uint16_t addr, uint8_t time) if (i%2!=0) send(orig_port, 0x20, addr, &gap, 1); else - delay(gap*100); + delay(gap*200); } } @@ -168,13 +170,11 @@ uint16_t DLLN3X::read_addr() uint16_t addr = 0xFFFF; uint8_t data[60] = ""; int length = 0; - if (!_online) - { - _clear(); - _online = true; - } send(0x80, 0x21, 0x0000, &arg, 1); + while(_DSerial->available()<10); + _recv_lock = true; recv(&orig_port, &dest_port, &addr, data, &length); + _recv_lock = false; if (orig_port!=0x21||dest_port!=0x80||addr !=0x0000||length!=3||data[0]!=0x21) { return 0; @@ -192,15 +192,19 @@ void DLLN3X::loop() uint16_t addr = 0xFFFF; uint8_t data[200] = ""; int length = 0; - if (_DSerial->available()>0&&!_recv_lock) + if (_DSerial->available()>7&&!_recv_lock) { recv(&orig_port,&dest_port,&addr,data,&length); - printf("Message: "); + Serial.print("Message: "); for (int i = 0; i < length;i++) { - printf("%X ", data[i]); + char temp[3]; + sprintf(temp, "%02X ", data[i]); + Serial.print(temp); } - printf("at port %X from %X:%X\n", dest_port, addr, orig_port); + char temp[200]; + sprintf(temp, "at port %02X from %04X:%02X.", dest_port, addr, orig_port); + Serial.println(temp); if (_callback!=nullptr) _callback(orig_port, dest_port, addr, data, length); }