V1.0.4 Update

This commit is contained in:
Mentalflow 2023-01-26 14:37:24 +08:00
parent 3b39af65d3
commit 9dd60e1ca5
Signed by: Mentalflow
GPG Key ID: 5AE68D4401A2EE71
8 changed files with 72 additions and 30 deletions

4
.gitignore vendored
View File

@ -30,3 +30,7 @@
*.exe
*.out
*.app
# macOS
.DS_Store
*/.DS_Store`

View File

@ -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.

BIN
examples/.DS_Store vendored

Binary file not shown.

View File

@ -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();
}
}

BIN
imgs/example.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

View File

@ -1,7 +1,7 @@
name= DLLN3X ZigBee Mesh Module Library
version= 1.0.3
author= Duke Liu <mentalflow@ourdocs.cn>
maintainer= Duke Liu <mentalflow@ourdocs.cn>
version= 1.0.4
author= Dylan Liu <mentalflow@ourdocs.cn>
maintainer= Dylan Liu <mentalflow@ourdocs.cn>
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

BIN
src/.DS_Store vendored

Binary file not shown.

View File

@ -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);
}