V1.0.4 Update
This commit is contained in:
parent
3b39af65d3
commit
9dd60e1ca5
|
@ -30,3 +30,7 @@
|
||||||
*.exe
|
*.exe
|
||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
|
|
||||||
|
# macOS
|
||||||
|
.DS_Store
|
||||||
|
*/.DS_Store`
|
||||||
|
|
19
README.md
19
README.md
|
@ -1,7 +1,26 @@
|
||||||
# DLLN3X_zigbee_mesh_module_library
|
# DLLN3X_zigbee_mesh_module_library
|
||||||
This library allows you to use DLLN3X ZigBee mesh module very easily.
|
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
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
**V1.0.4 2023.1.26**
|
||||||
|
|
||||||
|
- Bug fixes and stability improvements.
|
||||||
|
|
||||||
**V1.0.3 2023.1.12**
|
**V1.0.3 2023.1.12**
|
||||||
|
|
||||||
- Bug fixed for example.
|
- Bug fixed for example.
|
||||||
|
|
Binary file not shown.
|
@ -9,27 +9,42 @@ void zigbee_call_back(uint8_t orig_port,
|
||||||
case 0x82:
|
case 0x82:
|
||||||
{
|
{
|
||||||
/* Do everything you want to do */
|
/* 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;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
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);
|
dlln33.setcallback(zigbee_call_back);
|
||||||
printf("DLLN33 addr is 0x%X\n", dlln33.read_addr());
|
while(dlln33.read_addr()==0)
|
||||||
zframe.src_port = 0x81;
|
{
|
||||||
zframe.des_port = 0x82;
|
Serial.println("Waiting for DLLN3X to connect........");
|
||||||
*((uint16_t *)&zframe.remote_addrL) = dlln33.read_addr();
|
delay(1000);
|
||||||
strncpy((char*)zframe.data,"Hello to port 0x82!",21);
|
}
|
||||||
zframe.length = 21;
|
char temp[20];
|
||||||
dlln33.send(&zframe);
|
sprintf(temp, "DLLN3X addr: 0x%04X.",dlln33.read_addr());
|
||||||
|
Serial.println(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t interval = 5000, pre_milli = 0;
|
||||||
void loop() {
|
void loop() {
|
||||||
dlln33.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();
|
||||||
|
}
|
||||||
}
|
}
|
Binary file not shown.
After Width: | Height: | Size: 99 KiB |
|
@ -1,7 +1,7 @@
|
||||||
name= DLLN3X ZigBee Mesh Module Library
|
name= DLLN3X ZigBee Mesh Module Library
|
||||||
version= 1.0.3
|
version= 1.0.4
|
||||||
author= Duke Liu <mentalflow@ourdocs.cn>
|
author= Dylan Liu <mentalflow@ourdocs.cn>
|
||||||
maintainer= Duke Liu <mentalflow@ourdocs.cn>
|
maintainer= Dylan Liu <mentalflow@ourdocs.cn>
|
||||||
sentence= This library allows you to use DLLN3X ZigBee mesh module very easily.
|
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.
|
paragraph= This library currently allows basic send and receive operations using the DLLN3X module, with more features to come.
|
||||||
category= Communication
|
category= Communication
|
||||||
|
|
Binary file not shown.
|
@ -8,7 +8,6 @@ void DLLN3X::init(HardwareSerial *DSerial)
|
||||||
_DSerial = DSerial;
|
_DSerial = DSerial;
|
||||||
DSerial->begin(115200);
|
DSerial->begin(115200);
|
||||||
rled_blink();
|
rled_blink();
|
||||||
_clear();
|
|
||||||
read_addr();
|
read_addr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +16,6 @@ void DLLN3X::init(SoftwareSerial *DSerial)
|
||||||
_DSerial = DSerial;
|
_DSerial = DSerial;
|
||||||
DSerial->begin(115200);
|
DSerial->begin(115200);
|
||||||
rled_blink();
|
rled_blink();
|
||||||
_clear();
|
|
||||||
read_addr();
|
read_addr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,6 +88,8 @@ bool DLLN3X::recv(uint8_t *orig_port,
|
||||||
_recv_lock = true;
|
_recv_lock = true;
|
||||||
uint8_t buf[200] = "";
|
uint8_t buf[200] = "";
|
||||||
uint8_t head = 0, tail = 0;
|
uint8_t head = 0, tail = 0;
|
||||||
|
if(_DSerial->available()<6)
|
||||||
|
return false;
|
||||||
head = _DSerial->read();
|
head = _DSerial->read();
|
||||||
if (head == 0xFE)
|
if (head == 0xFE)
|
||||||
{
|
{
|
||||||
|
@ -102,13 +102,16 @@ bool DLLN3X::recv(uint8_t *orig_port,
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int i = 0; i < *length; i++)
|
for (int i = 0; i < *length; i++)
|
||||||
{
|
{
|
||||||
|
while(_DSerial->available()<1);
|
||||||
buf[count++] = _DSerial->read();
|
buf[count++] = _DSerial->read();
|
||||||
if (buf[count-1]==0xFE)
|
if (buf[count-1]==0xFE)
|
||||||
{
|
{
|
||||||
|
while(_DSerial->available()<1);
|
||||||
buf[count++]=_DSerial->read();
|
buf[count++]=_DSerial->read();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*length = count;
|
*length = count;
|
||||||
|
while(_DSerial->available()<1);
|
||||||
_DSerial->read(); // read pkg tail
|
_DSerial->read(); // read pkg tail
|
||||||
*length = _depack(buf, data, *length);
|
*length = _depack(buf, data, *length);
|
||||||
_recv_lock = false;
|
_recv_lock = false;
|
||||||
|
@ -127,7 +130,6 @@ bool DLLN3X::send(uint8_t orig_port,
|
||||||
{
|
{
|
||||||
if (orig_port<0x80)
|
if (orig_port<0x80)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
uint8_t send_buf[208] = {0xFE}, buf[200] = "";
|
uint8_t send_buf[208] = {0xFE}, buf[200] = "";
|
||||||
uint8_t head = 0, buf_length = 0;
|
uint8_t head = 0, buf_length = 0;
|
||||||
buf_length = _pack(buf, data, length);
|
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)
|
if (i%2!=0)
|
||||||
send(orig_port, 0x20, addr, &gap, 1);
|
send(orig_port, 0x20, addr, &gap, 1);
|
||||||
else
|
else
|
||||||
delay(gap*100);
|
delay(gap*200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,13 +170,11 @@ uint16_t DLLN3X::read_addr()
|
||||||
uint16_t addr = 0xFFFF;
|
uint16_t addr = 0xFFFF;
|
||||||
uint8_t data[60] = "";
|
uint8_t data[60] = "";
|
||||||
int length = 0;
|
int length = 0;
|
||||||
if (!_online)
|
|
||||||
{
|
|
||||||
_clear();
|
|
||||||
_online = true;
|
|
||||||
}
|
|
||||||
send(0x80, 0x21, 0x0000, &arg, 1);
|
send(0x80, 0x21, 0x0000, &arg, 1);
|
||||||
|
while(_DSerial->available()<10);
|
||||||
|
_recv_lock = true;
|
||||||
recv(&orig_port, &dest_port, &addr, data, &length);
|
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)
|
if (orig_port!=0x21||dest_port!=0x80||addr !=0x0000||length!=3||data[0]!=0x21)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -192,15 +192,19 @@ void DLLN3X::loop()
|
||||||
uint16_t addr = 0xFFFF;
|
uint16_t addr = 0xFFFF;
|
||||||
uint8_t data[200] = "";
|
uint8_t data[200] = "";
|
||||||
int length = 0;
|
int length = 0;
|
||||||
if (_DSerial->available()>0&&!_recv_lock)
|
if (_DSerial->available()>7&&!_recv_lock)
|
||||||
{
|
{
|
||||||
recv(&orig_port,&dest_port,&addr,data,&length);
|
recv(&orig_port,&dest_port,&addr,data,&length);
|
||||||
printf("Message: ");
|
Serial.print("Message: ");
|
||||||
for (int i = 0; i < length;i++)
|
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)
|
if (_callback!=nullptr)
|
||||||
_callback(orig_port, dest_port, addr, data, length);
|
_callback(orig_port, dest_port, addr, data, length);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue