├── ESP32-JN5169.ino ├── LICENSE ├── README.md ├── commands.ino ├── converters.ino ├── data ├── data.db ├── favicon.ico └── ws.html ├── parsing.ino ├── sqlite.ino ├── util.ino └── web.ino /ESP32-JN5169.ino: -------------------------------------------------------------------------------- 1 | #if CONFIG_FREERTOS_UNICORE 2 | #define ARDUINO_RUNNING_CORE 0 3 | #else 4 | #define ARDUINO_RUNNING_CORE 1 5 | #endif 6 | 7 | #include 8 | #include "time.h" 9 | #include "SPIFFS.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "HardwareSerial.h" 15 | HardwareSerial jnSerial(2); 16 | 17 | unsigned long timing; // Переменная для хранения точки отсчета 18 | //Web server 19 | AsyncWebServer server(80); 20 | WebSocketsServer webSocket = WebSocketsServer(81); 21 | //--------------------------------- 22 | //SQlite 23 | sqlite3 *db; 24 | int rc; 25 | sqlite3_stmt *res; 26 | int rec_count = 0; 27 | const char *tail; 28 | 29 | //NTP 30 | const char* ntpServer = "pool.ntp.org"; 31 | const long gmtOffset_sec = 7200; 32 | const int daylightOffset_sec = 3600; 33 | char dateStringBuff[50]; //50 chars should be enough 34 | char timeStringBuff[50]; //50 chars should be enough 35 | 36 | //--------------------------------------- 37 | String print_string = ""; 38 | String attr_response = ""; 39 | bool oledidle = true; 40 | bool joinStarted = false; 41 | int joinSecCounter = 0; 42 | // ------task del from database--------- 43 | bool DelCall = false; 44 | uint64_t deletedDevLongAddr = 0; 45 | // ------task get full info ------------ 46 | bool new_device_connected = false; 47 | bool connectGood = true; 48 | bool needBind = false; 49 | uint8_t bindEp = 0; 50 | uint16_t new_device_ShortAddr = 0; 51 | uint64_t new_device_LongAddr = 0; 52 | String NewDevName = ""; 53 | int counter = 0; 54 | bool EpResponse = false; 55 | bool ClResponse = false; 56 | bool BindResponse = false; 57 | bool DnResponse = false; 58 | byte rxMessageData_newDevice[1000]; 59 | byte ClDataNewDevice[1000]; 60 | String NewDevComplete = ""; 61 | //--------------------------------------- 62 | uint64_t u64ExtendedAddr_coord; 63 | // -------------------------------------- 64 | uint64_t au64ExtAddr[16]; 65 | byte rxMessageData[1024]; 66 | byte rxMessageChecksum = 0; 67 | uint16_t rxMessageLength = 0; 68 | uint8_t rxMessageState = 0; 69 | uint16_t rxMessageType = 0; 70 | uint8_t rxMessageCount = 0; 71 | bool rxMessageInEscape = false; 72 | byte rxByte; 73 | 74 | 75 | #define RXD2 16 76 | #define TXD2 17 77 | 78 | void serialEvent() { 79 | webSocket.loop(); 80 | while (jnSerial.available()) 81 | { 82 | byte rxByte = (byte)jnSerial.read(); 83 | 84 | if (rxByte == 0x01) 85 | { 86 | // Start character received 87 | rxMessageChecksum = 0; 88 | rxMessageLength = 0; 89 | rxMessageType = 0; 90 | rxMessageState = 0; 91 | rxMessageCount = 0; 92 | rxMessageInEscape = false; 93 | } 94 | else if (rxByte == 0x02) 95 | { 96 | rxMessageInEscape = true; 97 | } 98 | else if (rxByte == 0x03) 99 | { 100 | displayDecodedCommand(rxMessageType, rxMessageLength, rxMessageData); 101 | } 102 | else 103 | { 104 | if (rxMessageInEscape == true) 105 | { 106 | rxByte ^= 0x10; 107 | rxMessageInEscape = false; 108 | } 109 | 110 | // Parse character 111 | switch (rxMessageState) 112 | { 113 | case 0: 114 | { 115 | rxMessageType = rxByte; 116 | rxMessageType <<= 8; 117 | rxMessageState++; 118 | } 119 | break; 120 | 121 | case 1: 122 | { 123 | rxMessageType |= rxByte; 124 | rxMessageState++; 125 | } 126 | break; 127 | 128 | case 2: 129 | { 130 | rxMessageLength = rxByte; 131 | rxMessageLength <<= 8; 132 | rxMessageState++; 133 | } 134 | break; 135 | 136 | case 3: 137 | { 138 | rxMessageLength |= rxByte; 139 | rxMessageState++; 140 | } 141 | break; 142 | 143 | case 4: 144 | { 145 | rxMessageChecksum = rxByte; 146 | rxMessageState++; 147 | } 148 | break; 149 | 150 | default: 151 | { 152 | rxMessageData[rxMessageCount++] = rxByte; 153 | } 154 | break; 155 | } 156 | } 157 | } 158 | } 159 | 160 | void TaskDecode( void *pvParameters ); 161 | void TaskGetFullInfo( void *pvParameters ); 162 | void TaskDelDevice( void *pvParameters ); 163 | 164 | //gets called when WiFiManager enters configuration mode 165 | void configModeCallback (WiFiManager *myWiFiManager) { 166 | Serial.println("Entered config mode"); 167 | Serial.println(WiFi.softAPIP()); 168 | //if you used auto generated SSID, print it 169 | Serial.println(myWiFiManager->getConfigPortalSSID()); 170 | } 171 | 172 | void UpdateLocalTime() 173 | { 174 | struct tm timeinfo; 175 | if (!getLocalTime(&timeinfo)) { 176 | Serial.println("Failed to obtain time"); 177 | return; 178 | } 179 | strftime(dateStringBuff, sizeof(dateStringBuff), "%d %B %Y", &timeinfo); //"%A, %B %d %Y" 180 | strftime(timeStringBuff, sizeof(timeStringBuff), "%H:%M:%S", &timeinfo); 181 | } 182 | 183 | uint32_t getTime() { 184 | time_t now; 185 | struct tm timeinfo; 186 | if (!getLocalTime(&timeinfo)) { 187 | Serial.println("Failed to obtain time"); 188 | return (0); 189 | } 190 | time(&now); 191 | return now; 192 | } 193 | 194 | void setup() { 195 | Serial.begin(115200); 196 | Serial.println("Start"); 197 | 198 | jnSerial.begin(115200, SERIAL_8N1, RXD2, TXD2); 199 | //SPIFFS 200 | if (!SPIFFS.begin()) { 201 | Serial.println("An Error has occurred while mounting SPIFFS"); 202 | return; 203 | } 204 | //SQlite 205 | File root = SPIFFS.open("/"); 206 | if (!root) { 207 | Serial.println("- failed to open directory"); 208 | return; 209 | } 210 | if (!root.isDirectory()) { 211 | Serial.println(" - not a directory"); 212 | return; 213 | } 214 | File file = root.openNextFile(); 215 | while (file) { 216 | if (file.isDirectory()) { 217 | Serial.print(" DIR : "); 218 | Serial.println(file.name()); 219 | } else { 220 | Serial.print(" FILE: "); 221 | Serial.print(file.name()); 222 | Serial.print("\tSIZE: "); 223 | Serial.println(file.size()); 224 | } 225 | file = root.openNextFile(); 226 | } 227 | 228 | sqlite3_initialize(); 229 | if (db_open("/spiffs/data.db", &db)) 230 | return; 231 | //------------------------------------------------------------------------- 232 | // Wifi Section 233 | WiFiManager wm; 234 | //wm.resetSettings(); 235 | 236 | wm.setAPCallback(configModeCallback); 237 | // id/name, placeholder/prompt, default, length 238 | if (!wm.autoConnect("ZigBeeGW")) { 239 | Serial.println("failed to connect and hit timeout"); 240 | //reset and try again, or maybe put it to deep sleep 241 | ESP.restart(); 242 | delay(1000); 243 | } 244 | //init and get the time 245 | configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); 246 | UpdateLocalTime(); 247 | //Web Server setup 248 | server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) { 249 | request->send(SPIFFS, "/ws.html", "text/html"); 250 | }); 251 | server.on ( "/devices", [](AsyncWebServerRequest * request) { 252 | devicesWebpage(request); 253 | } ); 254 | server.on("/favicon.ico", HTTP_GET, [](AsyncWebServerRequest * request) { 255 | request->send(SPIFFS, "/", "text/html"); 256 | }); 257 | server.begin(); 258 | delay(1000); 259 | webSocket.begin(); webSocket.onEvent(onWebSocketEvent); // Start WebSocket server and assign callback 260 | 261 | //// 262 | xTaskCreatePinnedToCore( 263 | TaskDecode 264 | , "TaskDecodeUart" 265 | , 32768 266 | , NULL 267 | , 1 268 | , NULL 269 | , ARDUINO_RUNNING_CORE); 270 | 271 | xTaskCreatePinnedToCore( 272 | TaskGetFullInfo 273 | , "GetFullInfoFromConnectedDevice" 274 | , 10000 275 | , NULL 276 | , 1 277 | , NULL 278 | , ARDUINO_RUNNING_CORE); 279 | 280 | xTaskCreatePinnedToCore( 281 | TaskDelDevice 282 | , "Delete from database" 283 | , 10000 284 | , NULL 285 | , 1 286 | , NULL 287 | , ARDUINO_RUNNING_CORE); 288 | 289 | //Hard RESET 290 | //transmitCommand(0x0012, 0, 0); 291 | //delay(2000); 292 | //SOFT RESET 293 | //transmitCommand(0x0011, 0, 0); 294 | //Check version of firmware on JN5169 295 | transmitCommand(0x0010, 0, 0); 296 | delay(50); 297 | //Set device type Coordinator 298 | setDeviceType(0); 299 | delay(50); 300 | //Set ZigBee Channel 301 | setChannel(11); 302 | delay(50); 303 | transmitCommand(0x0024, 0, 0); 304 | delay(50); 305 | //transmitCommand(0x0015, 0, 0); 306 | //network state 307 | transmitCommand(0x0009, 0, 0); 308 | delay(50); 309 | DiscoverDevices(); 310 | delay(50); 311 | //sendMgmtLqiRequest(0x2FE8, 0); 312 | //delay(50); 313 | setPermitJoin(0xFFFC, 0x1E, 0x00); 314 | delay(50); 315 | transmitCommand(0x0014, 0, 0); 316 | delay(50); 317 | setTime(getTime()); 318 | delay(50); 319 | transmitCommand(0x0017, 0, 0); 320 | delay(50); 321 | //sendReadAttribRequest(0x5465, 1, 1 , 0 , 0, 0, 0, 1, 0x0005); 322 | //void sendReadAttribRequest(uint16_t u16ShortAddr, byte u8SrcEndPoint, byte u8DstEndPoint, uint16_t u16ClusterID, byte u8Direction, byte u8ManuSpecific, uint16_t u16ManuID, byte u8AttribCount, uint16_t u16AttribID1) 323 | //sqlite_select_answer("0xf0c8fc06"); 324 | } 325 | 326 | void loop() { 327 | //transmitCommand(0x0017, 0, 0); 328 | delay(1000); 329 | //sendClusterOnOff(2,0x5465,1,1,2); 330 | } 331 | 332 | /*--------------------------------------------------*/ 333 | /*---------------------- Tasks ---------------------*/ 334 | /*--------------------------------------------------*/ 335 | 336 | void TaskDecode(void *pvParameters) // This is a task. 337 | { 338 | (void) pvParameters; 339 | 340 | for (;;) // A Task shall never return or exit. 341 | { 342 | serialEvent(); 343 | vTaskDelay(10); // one tick delay (15ms) in between reads for stability 344 | } 345 | } 346 | 347 | void TaskGetFullInfo(void *pvParameters) // This is a task. 348 | { 349 | (void) pvParameters; 350 | 351 | for (;;) // A Task shall never return or exit. 352 | { 353 | if (new_device_connected && joinStarted) { 354 | new_device_connected = false; // получаем флаг что девайс подключился, и сразу его сбросим 355 | // дальше начнем обработку, проверим есть ли железка в базе 356 | if (sqlite_select_answer(u64toStr(new_device_LongAddr)) == 0) { 357 | NewDevComplete = ""; // очищаем стринг вывода 358 | activeEndpointDescriptorRequest(new_device_ShortAddr); // посылаем в сеть запрос эндпоинтов (0x0045) 359 | counter = 5000; // задерка на 5 сек 360 | while (!EpResponse) { // ждем ответа 0x8045 (копируем данные в новый массив, и флаг ставим true) 361 | delay(1); 362 | if (counter-- == 0) { 363 | connectGood = false; 364 | break; 365 | } 366 | } // получили ответ или закончилось время 367 | delay(50); // На всякий случай подождем, чтобы слишком быстро не слать команду 368 | //Эндпоинты получили, пытаемся узнать имя железки 369 | sendReadAttribRequest(new_device_ShortAddr, 1, rxMessageData_newDevice[1] , 0 , 0, 0, 0, 1, 0x0005); // Запрос атрибута как зовут железку 370 | counter = 5000; // задержка 5 сек 371 | while (!DnResponse) { // ждем ответа 0x8102 (почему то ответчает атрибут репорт.... имя ложим в переменную NewDevName) 372 | delay(1); 373 | if (counter-- == 0) { 374 | connectGood = false; 375 | break; 376 | } 377 | } 378 | delay(50); //На всякий случай подождем, чтобы слишком быстро не слать команду 379 | // 380 | NewDevComplete += "{" + u64toStr(new_device_LongAddr) + ": "; 381 | NewDevComplete += NewDevName + " ; "; 382 | NewDevComplete += u16toStr(new_device_ShortAddr) + " ; "; 383 | for (int i = 0; i < rxMessageData_newDevice[0]; i++) 384 | { 385 | NewDevComplete += " Ep"; 386 | NewDevComplete += String(i, DEC) + ":"; 387 | NewDevComplete += String(rxMessageData_newDevice[i + 1], DEC) + " ; "; 388 | bindEp = rxMessageData_newDevice[i + 1]; 389 | simpleDescriptorRequest(new_device_ShortAddr, bindEp); 390 | counter = 5000; 391 | while (!ClResponse) { 392 | delay(1); 393 | if (counter-- == 0) { 394 | connectGood = false; 395 | break; 396 | } 397 | } 398 | ///Get clusters 399 | byte u8Length = 0; 400 | u8Length = ClDataNewDevice[0]; 401 | if (u8Length > 0) 402 | { 403 | byte u8InputClusterCount = 0; 404 | u8InputClusterCount = ClDataNewDevice[7]; 405 | NewDevComplete += "Clusters "; 406 | for (int i = 0; i < u8InputClusterCount; i++) 407 | { 408 | uint16_t u16ClusterId = 0; 409 | u16ClusterId = ClDataNewDevice[(i * 2) + 8]; 410 | u16ClusterId <<= 8; 411 | u16ClusterId |= ClDataNewDevice[(i * 2) + 9]; 412 | NewDevComplete += ": " + u16toStr(u16ClusterId); 413 | //Тест механики биндда, если сработает будет круто ) Биндим все кластеры по очереди. и биндим только на новые устройства. 414 | if (connectGood && needBind) { 415 | Serial.println(u64toStr(new_device_LongAddr) + ", " + String(bindEp, DEC) + ", " + u16toStr(u16ClusterId) + ", 3, " + u64toStr(u64ExtendedAddr_coord) + ", 1"); 416 | sendBindRequest(new_device_LongAddr, bindEp, u16ClusterId, 3, u64ExtendedAddr_coord, 1 ); 417 | counter = 5000; 418 | while (!BindResponse) { 419 | delay(1); 420 | if (counter-- == 0) { 421 | break; 422 | } 423 | } 424 | BindResponse = false; 425 | } 426 | delay(50); //На всякий случай подождем, чтобы слишком быстро не слать команду 427 | // sqlite_insertnewdev(u64toStr(new_device_LongAddr), NewDevName, u16toStr(new_device_ShortAddr)); 428 | } 429 | } 430 | delay(50); //На всякий случай подождем, чтобы слишком быстро не слать команду 431 | } 432 | NewDevComplete += " }"; 433 | if (connectGood == true) { 434 | webSocket.broadcastTXT(NewDevComplete); 435 | sqlite_insertnewdev(u64toStr(new_device_LongAddr), NewDevName, u16toStr(new_device_ShortAddr)); 436 | } 437 | else 438 | { 439 | NewDevComplete = "!!!!!!Add device fail, please try again!!!!!!"; 440 | webSocket.broadcastTXT(NewDevComplete); 441 | } 442 | Serial.println(NewDevComplete); 443 | 444 | connectGood = true; EpResponse = false; BindResponse = false; bindEp = 0; DnResponse = false; ClResponse = false; NewDevName = ""; //needBind = false; 445 | memset(rxMessageData_newDevice, 0, sizeof(rxMessageData_newDevice)); 446 | memset(ClDataNewDevice, 0, sizeof(ClDataNewDevice)); 447 | } 448 | else { 449 | Serial.println("Device in base"); 450 | } 451 | } 452 | vTaskDelay(100); // one tick delay (15ms) in between reads for stability 453 | } 454 | } 455 | 456 | void TaskDelDevice(void *pvParameters) // This is a task. 457 | { 458 | (void) pvParameters; 459 | 460 | for (;;) // A Task shall never return or exit. 461 | { 462 | if(DelCall){ 463 | sqliteDeleteDevice(u64toStr(deletedDevLongAddr)); 464 | Serial.println("Delete device from database"); 465 | DelCall = false; 466 | } 467 | vTaskDelay(100); // one tick delay (15ms) in between reads for stability 468 | } 469 | } 470 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESP32-JN5169 2 | Реализация минимально-функционирующего Zigbee координатора на базе ESP32 и модуля NXP JN5168/69 с прошивкой ZiGate 3 | Для работы установить следующие библиотеки 4 | WifiManagerEsp32,arduinoWebSockets,ESPAsyncWebServer, AsyncTCP, esp32_arduino_sqlite3_lib 5 | 6 | Прошивка 7 | https://github.com/fairecasoimeme/ZiGate/tree/master/Module%20Radio/Firmware/bin/ZiGate/JN5169 8 | -------------------------------------------------------------------------------- /commands.ino: -------------------------------------------------------------------------------- 1 | void transmitCommand(int iCommand, int iLength, byte data[]) 2 | { 3 | int i; 4 | uint8_t specialCharacter[1]; 5 | uint8_t message[256]; 6 | 7 | // Build message payload, starting with the type field 8 | message[0] = (byte)(iCommand >> 8); 9 | message[1] = (byte)iCommand; 10 | 11 | // Add message length 12 | message[2] = (byte)(iLength >> 8); 13 | message[3] = (byte)iLength; 14 | 15 | // Calculate checksum of header 16 | byte csum = 0; 17 | csum ^= message[0]; 18 | csum ^= message[1]; 19 | csum ^= message[2]; 20 | csum ^= message[3]; 21 | 22 | // Add message data and update checksum 23 | if (iLength != 0) 24 | { 25 | for (i = 0; i < iLength; i++) 26 | { 27 | message[5 + i] = data[i]; 28 | csum ^= data[i]; 29 | } 30 | } 31 | 32 | // Add checksum 33 | message[4] = csum; 34 | 35 | // Transmit the message, send start character first 36 | specialCharacter[0] = 1; 37 | writeByte(specialCharacter[0]); 38 | 39 | // Transmit message payload with byte stuffing as required 40 | for (i = 0; i < iLength + 5; i++) 41 | { 42 | // Check if stuffing is required 43 | if (message[i] < 0x10) 44 | { 45 | // First send escape character then message byte XOR'd with 0x10 46 | specialCharacter[0] = 2; 47 | writeByte(specialCharacter[0]); 48 | int msg = message[i]; 49 | msg = msg ^ 0x10; 50 | message[i] = (byte)msg; 51 | writeByte(message[i]); 52 | 53 | } 54 | else 55 | { 56 | // Send the character with no modification 57 | writeByte(message[i]); 58 | } 59 | } 60 | 61 | // Send end character 62 | specialCharacter[0] = 3; 63 | writeByte(specialCharacter[0]); 64 | } 65 | 66 | void sendReadAttribRequest(uint16_t u16ShortAddr, byte u8SrcEndPoint, byte u8DstEndPoint, uint16_t u16ClusterID, byte u8Direction, byte u8ManuSpecific, uint16_t u16ManuID, byte u8AttribCount, uint16_t u16AttribID1) 67 | { 68 | byte commandData[14]; 69 | byte u8Len = 0; 70 | 71 | // Build command payload 72 | commandData[u8Len++] = 0x02; // Short address mode 73 | commandData[u8Len++] = (byte)(u16ShortAddr >> 8); 74 | commandData[u8Len++] = (byte)u16ShortAddr; 75 | commandData[u8Len++] = u8SrcEndPoint; 76 | commandData[u8Len++] = u8DstEndPoint; 77 | commandData[u8Len++] = (byte)(u16ClusterID >> 8); 78 | commandData[u8Len++] = (byte)u16ClusterID; 79 | commandData[u8Len++] = u8Direction; 80 | commandData[u8Len++] = u8ManuSpecific; 81 | commandData[u8Len++] = (byte)(u16ManuID >> 8); 82 | commandData[u8Len++] = (byte)u16ManuID; 83 | commandData[u8Len++] = u8AttribCount; 84 | commandData[u8Len++] = (byte)(u16AttribID1 >> 8); 85 | commandData[u8Len++] = (byte)u16AttribID1; 86 | 87 | // Transmit command 88 | transmitCommand(0x0100, u8Len, commandData); 89 | } 90 | 91 | void setPermitJoin(uint16_t u16ShortAddr, byte u8Interval, byte u8TCsignificance) 92 | { 93 | byte commandData[4]; 94 | 95 | // Build command payload 96 | commandData[0] = (byte)(u16ShortAddr >> 8); 97 | commandData[1] = (byte)u16ShortAddr; 98 | commandData[2] = u8Interval; 99 | commandData[3] = u8TCsignificance; 100 | 101 | // Transmit command 102 | transmitCommand(0x0049, 4, commandData); 103 | } 104 | 105 | void activeEndpointDescriptorRequest(uint16_t u16ShortAddr) 106 | { 107 | byte commandData[2]; 108 | 109 | // Build command payload 110 | commandData[0] = (byte)(u16ShortAddr >> 8); 111 | commandData[1] = (byte)u16ShortAddr; 112 | 113 | // Transmit command 114 | transmitCommand(0x0045, 2, commandData); 115 | } 116 | 117 | void simpleDescriptorRequest(uint16_t u16ShortAddr, byte u8EndPoint) 118 | { 119 | byte commandData[3]; 120 | 121 | // Build command payload 122 | commandData[0] = (byte)(u16ShortAddr >> 8); 123 | commandData[1] = (byte)u16ShortAddr; 124 | commandData[2] = u8EndPoint; 125 | 126 | // Transmit command 127 | transmitCommand(0x0043, 3, commandData); 128 | } 129 | 130 | void sendBindRequest(uint64_t u64TargetExtAddr, byte u8TargetEndPoint, uint16_t u16ClusterID, byte u8DstAddrMode, uint64_t u64DstAddr, byte u8DstEndPoint) 131 | { 132 | byte commandData[32]; 133 | byte u8Len = 0; 134 | 135 | // Build command payload 136 | commandData[u8Len++] = (byte)(u64TargetExtAddr >> 56); 137 | commandData[u8Len++] = (byte)(u64TargetExtAddr >> 48); 138 | commandData[u8Len++] = (byte)(u64TargetExtAddr >> 40); 139 | commandData[u8Len++] = (byte)(u64TargetExtAddr >> 32); 140 | commandData[u8Len++] = (byte)(u64TargetExtAddr >> 24); 141 | commandData[u8Len++] = (byte)(u64TargetExtAddr >> 16); 142 | commandData[u8Len++] = (byte)(u64TargetExtAddr >> 8); 143 | commandData[u8Len++] = (byte)u64TargetExtAddr; 144 | commandData[u8Len++] = u8TargetEndPoint; 145 | commandData[u8Len++] = (byte)(u16ClusterID >> 8); 146 | commandData[u8Len++] = (byte)u16ClusterID; 147 | commandData[u8Len++] = u8DstAddrMode; 148 | 149 | if (u8DstAddrMode == 3) 150 | { 151 | commandData[u8Len++] = (byte)(u64DstAddr >> 56); 152 | commandData[u8Len++] = (byte)(u64DstAddr >> 48); 153 | commandData[u8Len++] = (byte)(u64DstAddr >> 40); 154 | commandData[u8Len++] = (byte)(u64DstAddr >> 32); 155 | commandData[u8Len++] = (byte)(u64DstAddr >> 24); 156 | commandData[u8Len++] = (byte)(u64DstAddr >> 16); 157 | commandData[u8Len++] = (byte)(u64DstAddr >> 8); 158 | commandData[u8Len++] = (byte)u64DstAddr; 159 | commandData[u8Len++] = u8DstEndPoint; 160 | } 161 | else 162 | { 163 | commandData[u8Len++] = (byte)(u64DstAddr >> 8); 164 | commandData[u8Len++] = (byte)u64DstAddr; 165 | } 166 | 167 | // Transmit command 168 | transmitCommand(0x0030, u8Len, commandData); 169 | } 170 | 171 | void setChannel(int channel) 172 | { 173 | if (channel >= 11 && channel <= 26) 174 | { 175 | // User is specifying a single channel, we must create the 32-bit mask from this 176 | uint32_t u32ChannelMaskTemp = 1; 177 | 178 | for (int i = 0; i < channel; i++) 179 | { 180 | u32ChannelMaskTemp <<= 1; 181 | } 182 | 183 | // Set channel mask 184 | setChannelMask(u32ChannelMaskTemp); 185 | } 186 | } 187 | 188 | void setChannelMask(uint32_t uiMask) 189 | { 190 | byte commandData[4]; 191 | 192 | // Build command payload 193 | commandData[0] = (byte)(uiMask >> 24); 194 | commandData[1] = (byte)(uiMask >> 16); 195 | commandData[2] = (byte)(uiMask >> 8); 196 | commandData[3] = (byte)uiMask; 197 | 198 | // Transmit command 199 | transmitCommand(0x0021, 4, commandData); 200 | } 201 | 202 | void setTime(uint32_t timestamp) 203 | { 204 | byte commandData[4]; 205 | 206 | // Build command payload 207 | commandData[0] = (byte)(timestamp >> 24); 208 | commandData[1] = (byte)(timestamp >> 16); 209 | commandData[2] = (byte)(timestamp >> 8); 210 | commandData[3] = (byte)timestamp; 211 | 212 | // Transmit command 213 | transmitCommand(0x0016, 4, commandData); 214 | } 215 | 216 | void setDeviceType(byte deviceType) // 0 - Coordinator, 1 - router, 2 end device 217 | { 218 | byte commandData[1]; 219 | 220 | // Build command payload 221 | commandData[0] = deviceType; 222 | 223 | // Transmit command 224 | transmitCommand(0x0023, 1, commandData); 225 | } 226 | 227 | void sendClusterOnOff(byte u8AddrMode, uint16_t u16ShortAddr, byte u8SrcEndPoint, byte u8DstEndPoint, byte u8CommandID) 228 | { 229 | byte commandData[6]; 230 | 231 | // Build command payload 232 | commandData[0] = u8AddrMode; 233 | commandData[1] = (byte)(u16ShortAddr >> 8); 234 | commandData[2] = (byte)u16ShortAddr; 235 | commandData[3] = u8SrcEndPoint; 236 | commandData[4] = u8DstEndPoint; 237 | commandData[5] = u8CommandID; 238 | 239 | // Transmit command 240 | transmitCommand(0x0092, 6, commandData); 241 | } 242 | 243 | void sendMgmtLqiRequest(uint16_t u16ShortAddr, byte u8StartIndex) 244 | { 245 | byte commandData[4]; 246 | 247 | // Build command payload 248 | commandData[0] = (byte)(u16ShortAddr >> 8); 249 | commandData[1] = (byte)u16ShortAddr; 250 | commandData[2] = u8StartIndex; 251 | 252 | // Transmit command 253 | transmitCommand(0x004E, 3, commandData); 254 | } 255 | 256 | void DiscoverDevices() 257 | { 258 | uint16_t u16ShortAddr = 0x0000; 259 | byte u8StartIndex = 0; 260 | sendMgmtLqiRequest(u16ShortAddr, u8StartIndex); 261 | } 262 | 263 | void writeByte(byte data) 264 | { 265 | uint8_t dataArray[1]; 266 | dataArray[0] = data; 267 | // Write data byte to serial port 268 | jnSerial.write(dataArray, 1); 269 | } 270 | -------------------------------------------------------------------------------- /converters.ino: -------------------------------------------------------------------------------- 1 | void displayAttribute(uint8_t SQN, uint16_t u16SrcAddr, uint16_t u16ClusterId, uint16_t u16AttribId, byte u8AttribType, byte* au8AttribData, byte u8AttribIndex, uint16_t u16AttrSize) 2 | { 3 | attr_response += "{Date Time: "; 4 | attr_response += timeStringBuff; 5 | attr_response += "{SQN: 0x" + String(SQN, DEC); 6 | attr_response += ";ShortAddr: " + u16toStr(u16SrcAddr); 7 | attr_response += ";Cluster ID: " + u16toStr(u16ClusterId); 8 | attr_response += ";Attribute ID: " + u16toStr(u16AttribId); 9 | attr_response += ";Attribute Size: " + u16toStr(u16AttrSize); 10 | attr_response += ";Attribute Type: " + u8toStr(u8AttribType)+ ";"; 11 | 12 | /* 13 | clusterList.Add(0x0000, " (General: Basic)"); 14 | clusterList.Add(0x0001, " (General: Power Config)"); 15 | clusterList.Add(0x0002, " (General: Temperature Config)"); 16 | clusterList.Add(0x0003, " (General: Identify)"); 17 | clusterList.Add(0x0004, " (General: Groups)"); 18 | clusterList.Add(0x0005, " (General: Scenes)"); 19 | clusterList.Add(0x0006, " (General: On/Off)"); 20 | clusterList.Add(0x0007, " (General: On/Off Config)"); 21 | clusterList.Add(0x0008, " (General: Level Control)"); 22 | clusterList.Add(0x0009, " (General: Alarms)"); 23 | clusterList.Add(0x000A, " (General: Time)"); 24 | clusterList.Add(0x000F, " (General: Binary Input Basic)"); 25 | clusterList.Add(0x0020, " (General: Poll Control)"); 26 | clusterList.Add(0x0019, " (General: OTA)"); 27 | clusterList.Add(0x0101, " (General: Door Lock"); 28 | clusterList.Add(0x0201, " (HVAC: Thermostat)"); 29 | clusterList.Add(0x0202, " (HVAC: Fan Control)"); 30 | lusterList.Add(0x0204, " (HVAC: Thermostat UI Config)"); 31 | clusterList.Add(0x0300, " (Lighting: Color Control)"); 32 | clusterList.Add(0x0400, " (Measurement: Illuminance)"); 33 | clusterList.Add(0x0402, " (Measurement: Temperature)"); 34 | clusterList.Add(0x0403, " (Measurement: Pressure)"); 35 | clusterList.Add(0x0405, " (Measurement: Relative Humidity)"); 36 | clusterList.Add(0x0406, " (Measurement: Occupancy Sensing)"); 37 | clusterList.Add(0x0500, " (Security & Safety: IAS Zone)"); 38 | clusterList.Add(0x0502, " (Security & Safety: IAS WD)"); 39 | clusterList.Add(0x0702, " (Smart Energy: Metering)"); 40 | lusterList.Add(0x0B05, " (Misc: Diagnostics)"); 41 | clusterList.Add(0x1000, " (ZLL: Commissioning)"); 42 | */ 43 | switch (u16ClusterId) 44 | { 45 | case 0x0000: 46 | switch (u8AttribType) 47 | { 48 | case 0x42: 49 | if (u16AttribId == 0x0005) { 50 | NewDevName = ""; 51 | attr_response += " Attribute Data (Len - " + String(u16AttrSize) + "): "; 52 | for (int i = 0; i < u16AttrSize; i++) 53 | { 54 | char c = (char)au8AttribData[u8AttribIndex + i]; 55 | attr_response += c; 56 | NewDevName += c; 57 | } 58 | DnResponse = true; 59 | } 60 | else { 61 | // for (int i = 0 ; i < u16AttrSize; i++) 62 | // { 63 | // attr_response += Hex([u8AttribIndex + i]); 64 | // } 65 | } 66 | break; 67 | default: 68 | 69 | break; 70 | } 71 | break; 72 | case 0x0006: 73 | switch (u8AttribType) 74 | { 75 | case 0x10: 76 | //attr_response += " (Boolean)"; 77 | attr_response += " Attribute Data: 0x" + String(au8AttribData[u8AttribIndex], DEC); 78 | break; 79 | } 80 | break; 81 | case 0x0400: 82 | break; 83 | case 0x0402: 84 | switch (u8AttribType) 85 | { 86 | case 0x21: 87 | uint16_t u16Data; 88 | u16Data = au8AttribData[u8AttribIndex]; 89 | u16Data <<= 8; 90 | u16Data |= au8AttribData[u8AttribIndex + 1]; 91 | attr_response += " (UINT16)"; 92 | attr_response += " Attribute Data: 0x" + String(u16Data, HEX); 93 | break; 94 | 95 | case 0x29: 96 | uint16_t int16Data; 97 | int16Data = au8AttribData[u8AttribIndex]; 98 | int16Data <<= 8; 99 | int16Data |= au8AttribData[u8AttribIndex + 1]; 100 | attr_response += "Temperature = "; 101 | attr_response += String(int16Data, DEC); 102 | break; 103 | } 104 | break; 105 | case 0x0403: 106 | switch (u8AttribType) 107 | { 108 | case 0x21: 109 | uint16_t u16Data; 110 | u16Data = au8AttribData[u8AttribIndex]; 111 | u16Data <<= 8; 112 | u16Data |= au8AttribData[u8AttribIndex + 1]; 113 | attr_response += " (UINT16)"; 114 | attr_response += " Attribute Data: 0x" + String(u16Data, HEX); 115 | break; 116 | 117 | case 0x29: 118 | uint16_t int16Data; 119 | int16Data = au8AttribData[u8AttribIndex]; 120 | int16Data <<= 8; 121 | int16Data |= au8AttribData[u8AttribIndex + 1]; 122 | attr_response += "Pressure = "; 123 | attr_response += String(int16Data, DEC); 124 | break; 125 | } 126 | break; 127 | case 0x0405: 128 | switch (u8AttribType) 129 | { 130 | case 0x21: 131 | uint16_t u16Data; 132 | u16Data = au8AttribData[u8AttribIndex]; 133 | u16Data <<= 8; 134 | u16Data |= au8AttribData[u8AttribIndex + 1]; 135 | attr_response += "Humidity = "; 136 | attr_response += String(u16Data, DEC); 137 | break; 138 | } 139 | break; 140 | default: 141 | //attr_response += " (Unknown)"; 142 | //attr_response += "\n"; 143 | break; 144 | } 145 | /* 146 | switch (u8AttribType) 147 | { 148 | case 0x10: 149 | //attr_response += " (Boolean)"; 150 | //attr_response += "\n"; 151 | //attr_response += " Attribute Data: 0x" + String(au8AttribData[u8AttribIndex], DEC); 152 | //attr_response += "\n"; 153 | break; 154 | case 0x18: 155 | //attr_response += " (8-bit Bitmap)"; 156 | //attr_response += "\n"; 157 | //attr_response += " Attribute Data: 0x" + String(au8AttribData[u8AttribIndex],HEX); 158 | //attr_response += "\n"; 159 | break; 160 | case 0x20: 161 | //attr_response += " (UINT8)"; 162 | //attr_response += "\n"; 163 | //attr_response += " Attribute Data: 0x" + String(au8AttribData[u8AttribIndex], HEX); 164 | //attr_response += "\n"; 165 | break; 166 | case 0x21: 167 | uint16_t u16Data; 168 | u16Data = au8AttribData[u8AttribIndex]; 169 | u16Data <<= 8; 170 | u16Data |= au8AttribData[u8AttribIndex + 1]; 171 | attr_response += " (UINT16)"; 172 | attr_response += "\n"; 173 | attr_response += " Attribute Data: 0x" + String(u16Data, HEX); 174 | attr_response += "\n"; 175 | break; 176 | case 0x23: 177 | uint32_t u32Data; 178 | u32Data = au8AttribData[u8AttribIndex]; 179 | u32Data <<= 8; 180 | u32Data |= au8AttribData[u8AttribIndex + 1]; 181 | u32Data <<= 8; 182 | u32Data |= au8AttribData[u8AttribIndex + 2]; 183 | u32Data <<= 8; 184 | u32Data |= au8AttribData[u8AttribIndex + 3]; 185 | attr_response += " (UINT32)"; 186 | attr_response += "\n"; 187 | attr_response += " Attribute Data: 0x" + String(u32Data, HEX); 188 | attr_response += "\n"; 189 | break; 190 | case 0x29: 191 | uint16_t int16Data; 192 | int16Data = au8AttribData[u8AttribIndex]; 193 | int16Data <<= 8; 194 | int16Data |= au8AttribData[u8AttribIndex + 1]; 195 | attr_response += " (INT16)"; 196 | attr_response += "\n"; 197 | attr_response += " Attribute Data: 0x" + String(int16Data, HEX); 198 | attr_response += "\n"; 199 | break; 200 | case 0x30: 201 | attr_response += " (8-bit Enumeration)"; 202 | attr_response += "\n"; 203 | attr_response += " Attribute Data: 0x" + String(au8AttribData[u8AttribIndex], HEX); 204 | attr_response += "\n"; 205 | break; 206 | case 0x42: 207 | attr_response += " (Character String)"; 208 | attr_response += "\n"; 209 | attr_response += " Attribute Data (Len - " + String(u16AttrSize) + "): "; 210 | for (int i = 0; i < u16AttrSize; i++) 211 | { 212 | char c = (char)au8AttribData[u8AttribIndex + i]; 213 | attr_response += c; 214 | } 215 | attr_response += "\n"; 216 | break; 217 | case 0xF0: 218 | attr_response += " (IEEE Address)"; 219 | attr_response += "\n"; 220 | attr_response += " Attribute Data: " + au8AttribData[u8AttribIndex]; 221 | attr_response += ":" + au8AttribData[u8AttribIndex + 1]; 222 | attr_response += ":" + au8AttribData[u8AttribIndex + 2]; 223 | attr_response += ":" + au8AttribData[u8AttribIndex + 3]; 224 | attr_response += ":" + au8AttribData[u8AttribIndex + 4]; 225 | attr_response += ":" + au8AttribData[u8AttribIndex + 5]; 226 | attr_response += ":" + au8AttribData[u8AttribIndex + 6]; 227 | attr_response += ":" + au8AttribData[u8AttribIndex + 7]; 228 | attr_response += "\n"; 229 | break; 230 | default: 231 | attr_response += " (Unknown)"; 232 | attr_response += "\n"; 233 | break; 234 | } 235 | */ 236 | attr_response += "}"; 237 | Serial.println(attr_response); 238 | webSocket.broadcastTXT(attr_response); //wsc 239 | attr_response = ""; 240 | } 241 | -------------------------------------------------------------------------------- /data/data.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmahmutov/ESP32-JN5169/357ca7068a7a48256ac48df9ac132ef850727b09/data/data.db -------------------------------------------------------------------------------- /data/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmahmutov/ESP32-JN5169/357ca7068a7a48256ac48df9ac132ef850727b09/data/favicon.ico -------------------------------------------------------------------------------- /data/ws.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | ESP32 ZigBee Gateway 6 | 26 | 27 | 28 | 29 |
30 |

Not connected

31 | 32 | 33 | 34 |
35 |
36 | 37 |
38 | 39 | 40 | -------------------------------------------------------------------------------- /parsing.ino: -------------------------------------------------------------------------------- 1 | void displayDecodedCommand(uint16_t u16Type, uint16_t u16Length, byte* au8Data) 2 | { 3 | 4 | if ( (u16Type != 0x8011 && u16Type != 0x8012)) 5 | { 6 | print_string += "Type: "; 7 | print_string += u16toStr(u16Type); 8 | print_string += "\n"; 9 | } 10 | 11 | switch (u16Type) 12 | { 13 | 14 | case 0x8000: 15 | { 16 | print_string += " (Status)"; 17 | print_string += "\n"; 18 | print_string += " Length: "; 19 | print_string += u16toStr(u16Length); 20 | print_string += "\n"; 21 | print_string += " Status: "; 22 | print_string += u8toStr(au8Data[0]); 23 | 24 | switch (au8Data[0]) 25 | { 26 | case 0: 27 | { 28 | print_string += " (Success)"; 29 | } 30 | break; 31 | 32 | case 1: 33 | { 34 | print_string += " (Incorrect Parameters)"; 35 | } 36 | break; 37 | 38 | case 2: 39 | { 40 | print_string += " (Unhandled Command)"; 41 | } 42 | break; 43 | 44 | case 3: 45 | { 46 | print_string += " (Command Failed)"; 47 | } 48 | break; 49 | 50 | case 4: 51 | { 52 | print_string += " (Busy)"; 53 | } 54 | break; 55 | 56 | case 5: 57 | { 58 | print_string += " (Stack Already Started)"; 59 | } 60 | break; 61 | 62 | default: 63 | { 64 | print_string += " (ZigBee Error Code)"; 65 | } 66 | break; 67 | } 68 | print_string += "\n"; 69 | /* 70 | print_string += "\n"; 71 | print_string += " SQN: 0x"; 72 | print_string += au8Data[1]; 73 | 74 | if (u16Length > 2) 75 | { 76 | print_string += "\n"; 77 | print_string += " Message: "; 78 | //string errorMessage = System.Text.Encoding.Default.GetString(au8Data); 79 | //print_string += errorMessage.Substring(2, (u16Length - 2)); 80 | } 81 | print_string += "\n"; 82 | //Serial.print(print_string); 83 | */ 84 | } 85 | break; 86 | 87 | case 0x8011: 88 | { 89 | 90 | { 91 | uint16_t u16ProfileID = 0; 92 | uint16_t u16ClusterID = 0; 93 | 94 | u16ProfileID = au8Data[4]; 95 | u16ProfileID <<= 8; 96 | u16ProfileID |= au8Data[5]; 97 | 98 | u16ClusterID = au8Data[6]; 99 | u16ClusterID <<= 8; 100 | u16ClusterID |= au8Data[7]; 101 | 102 | print_string += " (APS Data ACK)"; 103 | print_string += "\n"; 104 | print_string += " Status: 0x" + au8Data[0]; 105 | print_string += "\n"; 106 | print_string += " SQN: 0x" + au8Data[1]; 107 | print_string += "\n"; 108 | print_string += " Source EndPoint: 0x" + au8Data[2]; 109 | print_string += "\n"; 110 | print_string += " Destination EndPoint: 0x" + au8Data[3]; 111 | print_string += "\n "; 112 | //displayProfileId(u16ProfileID); 113 | print_string += "\n "; 114 | ////displayClusterId(u16ClusterID); 115 | print_string += "\n"; 116 | } 117 | } 118 | break; 119 | 120 | case 0x8012: 121 | { 122 | 123 | { 124 | print_string += " (APS Data Confirm)"; 125 | print_string += "\n"; 126 | print_string += " Status: 0x" + au8Data[0]; 127 | print_string += "\n"; 128 | print_string += " SQN: 0x" + au8Data[1]; 129 | print_string += "\n"; 130 | print_string += " Source EndPoint: 0x" + au8Data[2]; 131 | print_string += "\n"; 132 | print_string += " Destination EndPoint: 0x" + au8Data[3]; 133 | print_string += "\n"; 134 | } 135 | } 136 | break; 137 | 138 | case 0x8001: 139 | { 140 | print_string += " (Log)"; 141 | print_string += "\n"; 142 | print_string += " Level: 0x" + au8Data[0]; 143 | print_string += "\n"; 144 | print_string += " Message: "; 145 | 146 | //string logMessage = System.Text.Encoding.Default.GetString(au8Data); 147 | //print_string += logMessage.Substring(1, (u16Length - 1)); 148 | print_string += "\n"; 149 | } 150 | break; 151 | 152 | case 0x8002: 153 | { 154 | uint16_t u16ProfileID = 0; 155 | uint16_t u16ClusterID = 0; 156 | 157 | u16ProfileID = au8Data[1]; 158 | u16ProfileID <<= 8; 159 | u16ProfileID |= au8Data[2]; 160 | 161 | u16ClusterID = au8Data[3]; 162 | u16ClusterID <<= 8; 163 | u16ClusterID |= au8Data[4]; 164 | 165 | print_string += " (Data Indication)"; 166 | print_string += "\n"; 167 | print_string += " Status: 0x" + au8Data[0]; 168 | print_string += "\n"; 169 | //displayProfileId(u16ProfileID); 170 | print_string += "\n"; 171 | // //displayClusterId(u16ClusterID); 172 | print_string += "\n"; 173 | print_string += " Source EndPoint: 0x" + au8Data[5]; 174 | print_string += "\n"; 175 | print_string += " Destination EndPoint: 0x" + au8Data[6]; 176 | print_string += "\n"; 177 | print_string += " Source Address Mode: 0x" + au8Data[7]; 178 | print_string += "\n"; 179 | print_string += " Source Address: "; 180 | 181 | byte nextIndex = 0; 182 | 183 | if (au8Data[9] == 0) 184 | { 185 | //0x00 = DstAddress and DstEndpoint not present 186 | print_string += "Not Present"; 187 | print_string += "\n"; 188 | 189 | nextIndex = 10; 190 | } 191 | else if (au8Data[9] == 1) 192 | { 193 | uint16_t u16GroupAddr = 0; 194 | 195 | u16GroupAddr = au8Data[10]; 196 | u16GroupAddr <<= 8; 197 | u16GroupAddr |= au8Data[11]; 198 | 199 | //0x01 = 16-bit group address for DstAddress; DstEndpoint not present 200 | print_string += u16GroupAddr; 201 | print_string += "\n"; 202 | 203 | nextIndex = 12; 204 | } 205 | else if (au8Data[9] == 2) 206 | { 207 | uint16_t u16DstAddress = 0; 208 | uint16_t u16DstEndPoint1 = 0; 209 | 210 | u16DstAddress = au8Data[10]; 211 | u16DstAddress <<= 8; 212 | u16DstAddress |= au8Data[11]; 213 | 214 | u16DstEndPoint1 = au8Data[12]; 215 | u16DstEndPoint1 <<= 8; 216 | u16DstEndPoint1 |= au8Data[13]; 217 | 218 | //0x02 = 16-bit address for DstAddress and DstEndpoint present 219 | print_string += u16DstAddress; 220 | print_string += " EndPoint: 0x" + u16DstEndPoint1; 221 | print_string += "\n"; 222 | 223 | nextIndex = 14; 224 | } 225 | else if (au8Data[9] == 3) 226 | { 227 | //0x03 = 64-bit extended address for DstAddress and DstEndpoint present 228 | } 229 | else 230 | { 231 | //0x04 –- 0xff = reserved 232 | nextIndex = 10; 233 | print_string += "Not Valid"; 234 | print_string += "\n"; 235 | } 236 | 237 | print_string += " Destination Address Mode: 0x" + au8Data[nextIndex]; 238 | print_string += "\n"; 239 | } 240 | break; 241 | 242 | case 0x8003: 243 | { 244 | uint16_t u16Entries = 0; 245 | uint16_t u16ProfileID = 0; 246 | 247 | u16ProfileID = au8Data[1]; 248 | u16ProfileID <<= 8; 249 | u16ProfileID |= au8Data[2]; 250 | 251 | u16Entries = (uint16_t)((u16Length - 3) / 2); 252 | 253 | print_string += " (Cluster List - Entries: "; 254 | print_string += u16Entries; 255 | print_string += ")\n"; 256 | print_string += " Source EndPoint: 0x"; 257 | print_string += au8Data[0]; 258 | print_string += "\n"; 259 | //displayProfileId(u16ProfileID); 260 | 261 | for (int i = 3; i < u16Length; i += 2) 262 | { 263 | uint16_t u16ClusterID; 264 | 265 | u16ClusterID = au8Data[i]; 266 | u16ClusterID <<= 8; 267 | u16ClusterID |= au8Data[i + 1]; 268 | 269 | //displayClusterId(u16ClusterID); 270 | //print_string += "\n"; 271 | } 272 | } 273 | break; 274 | 275 | case 0x8004: 276 | { 277 | uint16_t u16Entries = 0; 278 | uint16_t u16ProfileID = 0; 279 | uint16_t u16ClusterID = 0; 280 | 281 | u16ProfileID = au8Data[1]; 282 | u16ProfileID <<= 8; 283 | u16ProfileID |= au8Data[2]; 284 | 285 | u16ClusterID = au8Data[3]; 286 | u16ClusterID <<= 8; 287 | u16ClusterID |= au8Data[4]; 288 | 289 | u16Entries = (uint16_t)((u16Length - 5) / 2); 290 | 291 | print_string += " (Cluster Attributes - Entries: "; 292 | print_string += u16Entries; 293 | print_string += ")\n"; 294 | print_string += " Source EndPoint: 0x"; 295 | print_string += au8Data[0]; 296 | print_string += "\n"; 297 | //displayProfileId(u16ProfileID); 298 | print_string += "\n"; 299 | ////displayClusterId(u16ClusterID); 300 | print_string += "\n"; 301 | 302 | for (int i = 5; i < u16Length; i += 2) 303 | { 304 | uint16_t u16AttributeID = 0; 305 | 306 | u16AttributeID = au8Data[i]; 307 | u16AttributeID <<= 8; 308 | u16AttributeID |= au8Data[i + 1]; 309 | 310 | print_string += " Attribute ID: 0x"; 311 | print_string += u16AttributeID; 312 | print_string += "\n"; 313 | } 314 | } 315 | break; 316 | 317 | case 0x8005: 318 | { 319 | uint16_t u16Entries = 0; 320 | uint16_t u16ProfileID = 0; 321 | uint16_t u16ClusterID = 0; 322 | 323 | u16ProfileID = au8Data[1]; 324 | u16ProfileID <<= 8; 325 | u16ProfileID |= au8Data[2]; 326 | 327 | u16ClusterID = au8Data[3]; 328 | u16ClusterID <<= 8; 329 | u16ClusterID |= au8Data[4]; 330 | 331 | u16Entries = (uint16_t)(u16Length - 5); 332 | 333 | print_string += " (Command IDs - Entries: "; 334 | print_string += u16Entries; 335 | print_string += ")\n"; 336 | print_string += " Source EndPoint: 0x"; 337 | print_string += au8Data[0]; 338 | print_string += "\n"; 339 | //displayProfileId(u16ProfileID); 340 | print_string += "\n"; 341 | ////displayClusterId(u16ClusterID); 342 | print_string += "\n"; 343 | 344 | for (int i = 5; i < u16Length; i++) 345 | { 346 | print_string += " Command ID: 0x"; 347 | print_string += au8Data[i]; 348 | print_string += "\n"; 349 | } 350 | } 351 | break; 352 | 353 | case 0x8009: 354 | { 355 | 356 | uint16_t u16PanId = 0; 357 | uint64_t u64ExtendedPANID = 0; 358 | uint16_t u16ShortAddr = 0; 359 | uint64_t u64ExtendedAddr = 0; 360 | 361 | u16ShortAddr = au8Data[0]; 362 | u16ShortAddr <<= 8; 363 | u16ShortAddr |= au8Data[1]; 364 | 365 | for (int i = 0; i < 8; i++) 366 | { 367 | u64ExtendedAddr <<= 8; 368 | u64ExtendedAddr |= au8Data[2 + i]; 369 | } 370 | 371 | u16PanId = au8Data[10]; 372 | u16PanId <<= 8; 373 | u16PanId |= au8Data[11]; 374 | 375 | for (int i = 0; i < 8; i++) 376 | { 377 | u64ExtendedPANID <<= 8; 378 | u64ExtendedPANID |= au8Data[12 + i]; 379 | } 380 | //Сохраняем длинный адрес координатора 381 | u64ExtendedAddr_coord = u64ExtendedAddr; 382 | print_string += " (Network State Response)"; 383 | print_string += "\n"; 384 | print_string += " Short Address: "; 385 | print_string += u16toStr(u16ShortAddr); 386 | print_string += "\n"; 387 | print_string += " Extended Address: "; 388 | print_string += u64toStr(u64ExtendedAddr); 389 | print_string += "\n"; 390 | print_string += " PAN ID: "; 391 | print_string += u16toStr(u16PanId); 392 | print_string += "\n"; 393 | print_string += " Ext PAN ID: "; 394 | print_string += u64toStr(u64ExtendedPANID); 395 | print_string += "\n"; 396 | print_string += " Channel: "; 397 | print_string += String(au8Data[20], DEC); 398 | print_string += "\n"; 399 | } 400 | break; 401 | 402 | case 0x8010: 403 | { 404 | uint16_t u16Major = 0; 405 | uint16_t u16Installer = 0; 406 | 407 | u16Major = au8Data[0]; 408 | u16Major <<= 8; 409 | u16Major |= au8Data[1]; 410 | 411 | u16Installer = au8Data[2]; 412 | u16Installer <<= 8; 413 | u16Installer |= au8Data[3]; 414 | 415 | print_string += " (Version)"; 416 | print_string += "\n"; 417 | print_string += " Length: "; 418 | print_string += u16toStr(u16Length); 419 | print_string += "\n"; 420 | print_string += " Application: "; 421 | print_string += u16toStr(u16Major); 422 | print_string += "\n"; 423 | print_string += " SDK: "; 424 | print_string += u16toStr(u16Installer); 425 | print_string += "\n"; 426 | } 427 | break; 428 | 429 | case 0x8024: 430 | { 431 | uint16_t u16ShortAddr = 0; 432 | uint64_t u64ExtAddr = 0; 433 | 434 | u16ShortAddr = au8Data[1]; 435 | u16ShortAddr <<= 8; 436 | u16ShortAddr |= au8Data[2]; 437 | 438 | for (int i = 0; i < 8; i++) 439 | { 440 | u64ExtAddr <<= 8; 441 | u64ExtAddr |= au8Data[3 + i]; 442 | } 443 | // 444 | print_string += " (Network Up)"; 445 | print_string += "\n"; 446 | print_string += " Status: " + u8toStr(au8Data[0]); 447 | print_string += "\n"; 448 | print_string += " Short Address: " + u16toStr(u16ShortAddr); 449 | print_string += "\n"; 450 | print_string += " Extended Address: " + u64toStr(u64ExtAddr); 451 | print_string += "\n"; 452 | print_string += " Channel: " + String(au8Data[11], DEC); 453 | print_string += "\n"; 454 | } 455 | break; 456 | 457 | case 0x8014: 458 | { 459 | print_string += " (Permit Join State)"; 460 | print_string += "\n"; 461 | print_string += "Permit Join: "; 462 | if (au8Data[0] == 1) 463 | { 464 | print_string += "TRUE"; 465 | webSocket.broadcastTXT("Join enabled"); 466 | joinStarted = true; //Ставим флаг что подключение разрешено 467 | joinSecCounter = 30; // По умолчанию 30 сек 468 | } 469 | else 470 | { 471 | print_string += "FALSE"; 472 | } 473 | print_string += "\n"; 474 | } 475 | break; 476 | 477 | case 0x8015: 478 | { 479 | uint16_t u16PanId = 0; 480 | uint16_t u16ShortAddr = 0; 481 | uint16_t u16SuperframeSpec = 0; 482 | uint32_t u32TimeStamp = 0; 483 | uint64_t u64ExtendedPANID = 0; 484 | 485 | u16PanId = au8Data[1]; 486 | u16PanId <<= 8; 487 | u16PanId |= au8Data[2]; 488 | 489 | u16ShortAddr = au8Data[3]; 490 | u16ShortAddr <<= 8; 491 | u16ShortAddr |= au8Data[4]; 492 | 493 | u16SuperframeSpec = au8Data[11]; 494 | u16SuperframeSpec <<= 8; 495 | u16SuperframeSpec |= au8Data[12]; 496 | 497 | for (int i = 0; i < 4; i++) 498 | { 499 | u32TimeStamp <<= 8; 500 | u32TimeStamp |= au8Data[13 + i]; 501 | } 502 | 503 | for (int i = 0; i < 8; i++) 504 | { 505 | u64ExtendedPANID <<= 8; 506 | u64ExtendedPANID |= au8Data[17 + i]; 507 | } 508 | 509 | print_string += " (Discovery Only Scan Response)"; 510 | print_string += "\n"; 511 | print_string += " Address Mode: " + au8Data[0]; 512 | print_string += "\n"; 513 | print_string += " PAN ID: " + u16PanId; 514 | print_string += "\n"; 515 | print_string += " Short Address: 0x" + u16ShortAddr; 516 | print_string += "\n"; 517 | print_string += " Channel: " + au8Data[5]; 518 | print_string += "\n"; 519 | print_string += " GTS Permit: " + au8Data[6]; 520 | print_string += "\n"; 521 | print_string += " Link Quality: " + au8Data[7]; 522 | print_string += "\n"; 523 | print_string += " Security Use: " + au8Data[8]; 524 | print_string += "\n"; 525 | print_string += " ACL Entry: " + au8Data[9]; 526 | print_string += "\n"; 527 | print_string += " Security Failure: " + au8Data[10]; 528 | print_string += "\n"; 529 | print_string += " Superframe Specification: " + u16SuperframeSpec; 530 | print_string += "\n"; 531 | print_string += " Time Stamp: " + u32TimeStamp; 532 | print_string += "\n"; 533 | print_string += " Ext PAN ID: 0x" + u64ExtendedPANID; 534 | 535 | } 536 | break; 537 | 538 | case 0x8017: 539 | { 540 | uint32_t u32TimeStamp = 0; 541 | for (int i = 0; i < 4; i++) 542 | { 543 | u32TimeStamp <<= 8; 544 | u32TimeStamp |= au8Data[i]; 545 | } 546 | print_string += " Time Stamp: " + String(long(u32TimeStamp)); 547 | print_string += "\n"; 548 | } 549 | break; 550 | 551 | case 0x8029: 552 | { 553 | uint64_t u64AddrData = 0; 554 | uint64_t u64Key = 0; 555 | uint64_t u64HostAddrData = 0; 556 | uint64_t u64ExtPANID = 0; 557 | uint32_t u32Mic = 0; 558 | uint16_t u16PANID = 0; 559 | uint16_t u16ShortAddr = 0; 560 | uint16_t u16DeviceId = 0; 561 | 562 | for (int i = 0; i < 8; i++) 563 | { 564 | u64AddrData <<= 8; 565 | u64AddrData |= au8Data[0 + i]; 566 | } 567 | 568 | for (int i = 0; i < 16; i++) 569 | { 570 | u64Key <<= 8; 571 | u64Key |= au8Data[8 + i]; 572 | } 573 | 574 | for (int i = 0; i < 4; i++) 575 | { 576 | u32Mic <<= 8; 577 | u32Mic |= au8Data[24 + i]; 578 | } 579 | 580 | for (int i = 0; i < 8; i++) 581 | { 582 | u64HostAddrData <<= 8; 583 | u64HostAddrData |= au8Data[28 + i]; 584 | } 585 | 586 | u16PANID = au8Data[38]; 587 | u16PANID <<= 8; 588 | u16PANID |= au8Data[39]; 589 | 590 | for (int i = 0; i < 8; i++) 591 | { 592 | u64ExtPANID <<= 8; 593 | u64ExtPANID |= au8Data[40 + i]; 594 | } 595 | 596 | u16ShortAddr = au8Data[48]; 597 | u16ShortAddr <<= 8; 598 | u16ShortAddr |= au8Data[49]; 599 | 600 | u16DeviceId = au8Data[50]; 601 | u16DeviceId <<= 8; 602 | u16DeviceId |= au8Data[51]; 603 | 604 | print_string += " (Encrypted Data)"; 605 | print_string += "\n"; 606 | print_string += " Status: 0x" + au8Data[52]; 607 | print_string += "\n"; 608 | print_string += " Device Extended Address: " + u64AddrData; 609 | print_string += "\n"; 610 | print_string += " Key: " + u64Key; 611 | print_string += "\n"; 612 | print_string += " Mic: " + u32Mic; 613 | print_string += "\n"; 614 | print_string += " Host Extended Address: " + u64HostAddrData; 615 | print_string += "\n"; 616 | print_string += " Active Key Sequence Number: " + au8Data[36]; 617 | print_string += "\n"; 618 | print_string += " Channel: " + au8Data[37]; 619 | print_string += "\n"; 620 | print_string += " PAN ID: " + u16PANID; 621 | print_string += "\n"; 622 | print_string += " Extended PAN ID: " + u64ExtPANID; 623 | print_string += "\n"; 624 | print_string += " Short Address: " + u16ShortAddr; 625 | print_string += "\n"; 626 | print_string += " Device ID: " + u16DeviceId; 627 | print_string += "\n"; 628 | 629 | } 630 | break; 631 | 632 | case 0x8030: 633 | { 634 | BindResponse = true; 635 | print_string += " (Bind Response)"; 636 | print_string += "\n"; 637 | print_string += " SQN: 0x" + String(au8Data[0], HEX); 638 | print_string += "\n"; 639 | print_string += " Status: 0x" + String(au8Data[1], HEX); 640 | print_string += "\n"; 641 | } 642 | break; 643 | 644 | case 0x8031: 645 | { 646 | print_string += " (UnBind Response)"; 647 | print_string += "\n"; 648 | print_string += " SQN: 0x" + au8Data[0]; 649 | print_string += "\n"; 650 | print_string += " Status: 0x" + au8Data[1]; 651 | print_string += "\n"; 652 | } 653 | break; 654 | 655 | case 0x8041: 656 | { 657 | uint64_t u64ExtAddr = 0; 658 | uint16_t u16ShortAddr = 0; 659 | 660 | for (int i = 0; i < 8; i++) 661 | { 662 | u64ExtAddr <<= 8; 663 | u64ExtAddr |= au8Data[2 + i]; 664 | } 665 | 666 | u16ShortAddr = au8Data[10]; 667 | u16ShortAddr <<= 8; 668 | u16ShortAddr |= au8Data[11]; 669 | 670 | print_string += " (IEEE Address Response)"; 671 | print_string += "\n"; 672 | print_string += " SQN: 0x" + au8Data[0]; 673 | print_string += "\n"; 674 | print_string += " Status: 0x" + au8Data[1]; 675 | print_string += "\n"; 676 | print_string += " Extended Address: 0x" + u64ExtAddr; 677 | print_string += "\n"; 678 | print_string += " Short Address: 0x" + u16ShortAddr; 679 | print_string += "\n"; 680 | 681 | if (u16Length > 14) 682 | { 683 | print_string += " Associated End Devices: " + au8Data[12]; 684 | print_string += "\n"; 685 | } 686 | } 687 | break; 688 | 689 | case 0x8042: 690 | { 691 | /* 692 | uint16_t u16ShortAddr = 0; 693 | uint16_t u16ManufacturerCode = 0; 694 | uint16_t u16RxSize = 0; 695 | uint16_t u16TxSize = 0; 696 | uint16_t u16ServerMask = 0; 697 | uint16_t u16BitFields = 0; 698 | byte u8DescriptorCapability = 0; 699 | byte u8MacCapability = 0; 700 | byte u8MaxBufferSize = 0; 701 | 702 | u16ShortAddr = au8Data[2]; 703 | u16ShortAddr <<= 8; 704 | u16ShortAddr |= au8Data[3]; 705 | 706 | u16ManufacturerCode = au8Data[4]; 707 | u16ManufacturerCode <<= 8; 708 | u16ManufacturerCode |= au8Data[5]; 709 | 710 | u16RxSize = au8Data[6]; 711 | u16RxSize <<= 8; 712 | u16RxSize |= au8Data[7]; 713 | 714 | u16TxSize = au8Data[8]; 715 | u16TxSize <<= 8; 716 | u16TxSize |= au8Data[9]; 717 | 718 | u16ServerMask = au8Data[10]; 719 | u16ServerMask <<= 8; 720 | u16ServerMask |= au8Data[11]; 721 | 722 | u8DescriptorCapability = au8Data[12]; 723 | u8MacCapability = au8Data[13]; 724 | u8MaxBufferSize = au8Data[14]; 725 | 726 | u16BitFields = au8Data[15]; 727 | u16BitFields <<= 8; 728 | u16BitFields |= au8Data[16]; 729 | 730 | print_string += " (Node Descriptor Response)"; 731 | print_string += "\n"; 732 | print_string += " SQN: 0x" + au8Data[0]; 733 | print_string += "\n"; 734 | print_string += " Status: 0x" + au8Data[1]; 735 | print_string += "\n"; 736 | print_string += " Short Address: 0x" + u16ShortAddr; 737 | print_string += "\n"; 738 | print_string += " Manufacturer Code: 0x" + u16ManufacturerCode; 739 | print_string += "\n"; 740 | print_string += " Max Rx Size: " + u16RxSize; 741 | print_string += "\n"; 742 | print_string += " Max Tx Size: " + u16TxSize; 743 | print_string += "\n"; 744 | print_string += " Server Mask: 0x" + u16ServerMask; 745 | print_string += "\n"; 746 | //displayDescriptorCapability(u8DescriptorCapability); 747 | //displayMACcapability(u8MacCapability); 748 | print_string += " Max Buffer Size: " + u8MaxBufferSize; 749 | print_string += "\n"; 750 | print_string += " Bit Fields: 0x" + u16BitFields; 751 | print_string += "\n"; 752 | */ 753 | } 754 | break; 755 | 756 | case 0x8043: 757 | { 758 | memcpy(ClDataNewDevice, &(au8Data[4]), 1000); 759 | /* 760 | byte u8Length = 0; 761 | uint16_t u16ShortAddr = 0; 762 | u16ShortAddr = au8Data[2]; 763 | u16ShortAddr <<= 8; 764 | u16ShortAddr |= au8Data[3]; 765 | u8Length = au8Data[4]; 766 | 767 | print_string += " (Simple Descriptor Response)"; 768 | print_string += "\n"; 769 | print_string += " SQN: 0x" + String(au8Data[0], HEX); 770 | print_string += "\n"; 771 | print_string += " Status: 0x" + String(au8Data[1], HEX); 772 | print_string += "\n"; 773 | print_string += " Short Address: 0x" + String(u16ShortAddr, HEX); 774 | print_string += "\n"; 775 | print_string += " Length: " + String(u8Length, HEX); 776 | print_string += "\n"; 777 | 778 | if (u8Length > 0) 779 | { 780 | byte u8InputClusterCount = 0; 781 | uint16_t u16ProfileId = 0; 782 | uint16_t u16DeviceId = 0; 783 | 784 | u16ProfileId = au8Data[6]; 785 | u16ProfileId <<= 8; 786 | u16ProfileId |= au8Data[7]; 787 | u16DeviceId = au8Data[8]; 788 | u16DeviceId <<= 8; 789 | u16DeviceId |= au8Data[9]; 790 | u8InputClusterCount = au8Data[11]; 791 | 792 | print_string += " EndPoint: 0x" + String(au8Data[5], HEX); 793 | print_string += "\n"; 794 | //displayProfileId(u16ProfileId); 795 | print_string += "\n"; 796 | //displayDeviceId(u16DeviceId); 797 | print_string += "\n"; 798 | print_string += " Input Cluster Count: " + String(u8InputClusterCount, HEX); 799 | print_string += "\n"; 800 | 801 | uint16_t u16Index = 12; 802 | for (int i = 0; i < u8InputClusterCount; i++) 803 | { 804 | uint16_t u16ClusterId = 0; 805 | 806 | u16ClusterId = au8Data[(i * 2) + 12]; 807 | u16ClusterId <<= 8; 808 | u16ClusterId |= au8Data[(i * 2) + 13]; 809 | 810 | print_string += " Cluster " + i; 811 | print_string += ":" + String(u16ClusterId, HEX); 812 | 813 | //displayClusterId(u16ClusterId); 814 | print_string += "\n"; 815 | u16Index += 2; 816 | } 817 | 818 | byte u8OutputClusterCount = au8Data[u16Index]; 819 | u16Index++; 820 | 821 | print_string += " Output Cluster Count: " + String(u8OutputClusterCount, HEX); 822 | print_string += "\n"; 823 | 824 | for (int i = 0; i < u8OutputClusterCount; i++) 825 | { 826 | uint16_t u16ClusterId = 0; 827 | 828 | u16ClusterId = au8Data[u16Index]; 829 | u16ClusterId <<= 8; 830 | u16ClusterId |= au8Data[u16Index + 1]; 831 | 832 | print_string += " Cluster " + i; 833 | print_string += ":"; 834 | print_string += ":" + String(u16ClusterId, HEX); 835 | //displayClusterId(u16ClusterId); 836 | print_string += "\n"; 837 | u16Index += 2; 838 | } 839 | } 840 | */ 841 | ClResponse = true; 842 | } 843 | break; 844 | /* 845 | case 0x8044: 846 | { 847 | print_string += " (Power Descriptor Response)"; 848 | print_string += "\n"; 849 | print_string += " SQN: 0x" + au8Data[0]; 850 | print_string += "\n"; 851 | print_string += " Status: 0x" + au8Data[1]; 852 | print_string += "\n"; 853 | } 854 | break; 855 | */ 856 | case 0x8045: 857 | { 858 | memcpy(rxMessageData_newDevice, &(au8Data[4]), 1000); 859 | /* 860 | uint16_t u16ShortAddr = 0; 861 | u16ShortAddr = au8Data[2]; 862 | u16ShortAddr <<= 8; 863 | u16ShortAddr |= au8Data[3]; 864 | 865 | print_string += " (Active Endpoints Response)"; 866 | print_string += "\n"; 867 | print_string += " SQN: 0x" + String(au8Data[0], HEX); 868 | print_string += "\n"; 869 | print_string += " Status: 0x" + String(au8Data[1], HEX); 870 | print_string += "\n"; 871 | print_string += " Short Address: 0x" + String(u16ShortAddr, HEX); 872 | print_string += "\n"; 873 | print_string += " Endpoint Count: " + String(au8Data[4], HEX); 874 | print_string += "\n"; 875 | print_string += " Endpoint List: "; 876 | print_string += "\n"; 877 | //rxMessageData_newDevice[0] = au8Data[4]; 878 | for (int i = 0; i < au8Data[4]; i++) 879 | { 880 | //rxMessageData_newDevice[1+i] = au8Data[i + 5]; 881 | print_string += " Endpoint " + i; 882 | print_string += ": "; 883 | print_string += "0x" + String(au8Data[i + 5], HEX); 884 | //simpleDescriptorRequest(u16ShortAddr, au8Data[i + 5]); 885 | print_string += "\n"; 886 | } 887 | */ 888 | EpResponse = true; 889 | } 890 | break; 891 | 892 | case 0x8047: 893 | { 894 | print_string += " (Leave Confirmation)"; 895 | print_string += "\n"; 896 | 897 | if (u16Length == 2) 898 | { 899 | print_string += " SQN: 0x" + au8Data[0]; 900 | print_string += "\n"; 901 | } 902 | 903 | print_string += " Status: 0x" + au8Data[1]; 904 | print_string += "\n"; 905 | 906 | if (u16Length == 9) 907 | { 908 | 909 | uint64_t u64ExtAddr = 0; 910 | for (int i = 0; i < 8; i++) 911 | { 912 | u64ExtAddr <<= 8; 913 | u64ExtAddr |= au8Data[1 + i]; 914 | } 915 | 916 | print_string += " Extended Address: 0x" + u64ExtAddr; 917 | print_string += "\n"; 918 | } 919 | } 920 | break; 921 | 922 | case 0x8048: 923 | { 924 | uint64_t u64ExtAddr = 0; 925 | 926 | for (int i = 0; i < 8; i++) 927 | { 928 | u64ExtAddr <<= 8; 929 | u64ExtAddr |= au8Data[i]; 930 | } 931 | DelCall = true; 932 | deletedDevLongAddr = u64ExtAddr; 933 | print_string += " (Leave Indication)"; 934 | print_string += "\n"; 935 | print_string += " Extended Address: " + u64toStr(u64ExtAddr); 936 | print_string += "\n"; 937 | print_string += " Rejoin Status: " + u8toStr(au8Data[8]); 938 | print_string += "\n"; 939 | } 940 | break; 941 | 942 | case 0x804A: 943 | { 944 | byte u8ScannedChannelsListCount; 945 | uint16_t u16TotalTx = 0; 946 | uint16_t u16TxFailures = 0; 947 | uint32_t u32ScannedChannels = 0; 948 | 949 | u16TotalTx = au8Data[2]; 950 | u16TotalTx <<= 8; 951 | u16TotalTx |= au8Data[3]; 952 | 953 | u16TxFailures = au8Data[4]; 954 | u16TxFailures <<= 8; 955 | u16TxFailures |= au8Data[5]; 956 | 957 | u32ScannedChannels = au8Data[6]; 958 | u32ScannedChannels <<= 8; 959 | u32ScannedChannels |= au8Data[7]; 960 | u32ScannedChannels <<= 8; 961 | u32ScannedChannels |= au8Data[8]; 962 | u32ScannedChannels <<= 8; 963 | u32ScannedChannels |= au8Data[9]; 964 | 965 | u8ScannedChannelsListCount = au8Data[10]; 966 | 967 | print_string += " (Mgmt Nwk Update Notify)"; 968 | print_string += "\n"; 969 | print_string += " SQN: 0x" + au8Data[0]; 970 | print_string += "\n"; 971 | print_string += " Status: 0x" + au8Data[1]; 972 | print_string += "\n"; 973 | print_string += " Total Tx: " + u16TotalTx; 974 | print_string += "\n"; 975 | print_string += " Tx Failures: " + u16TxFailures; 976 | print_string += "\n"; 977 | print_string += " Scanned Channels: 0x" + u32ScannedChannels; 978 | print_string += "\n"; 979 | print_string += " Scanned Channels List Count: " + u8ScannedChannelsListCount; 980 | print_string += "\n"; 981 | 982 | for (int x = 0; x < u8ScannedChannelsListCount; x++) 983 | { 984 | print_string += " Value " + x; 985 | print_string += ": 0x" + au8Data[11 + x]; 986 | print_string += "\n"; 987 | } 988 | } 989 | break; 990 | 991 | case 0x804E: 992 | { 993 | byte u8NbTableEntries = 0; 994 | byte u8StartIx = 0; 995 | byte u8NbTableListCount = 0; 996 | 997 | uint16_t au16NwkAddr[16]; 998 | 999 | u8NbTableEntries = au8Data[2]; 1000 | u8NbTableListCount = au8Data[3]; 1001 | u8StartIx = au8Data[4]; 1002 | 1003 | print_string += " (Mgmt LQI Response)"; 1004 | print_string += "\n"; 1005 | print_string += " SQN: " + u8toStr(au8Data[0]); 1006 | print_string += "\n"; 1007 | print_string += " Status: " + u8toStr(au8Data[1]); 1008 | print_string += "\n"; 1009 | print_string += " Nb Table Entries: " + u8toStr(u8NbTableEntries); 1010 | print_string += "\n"; 1011 | print_string += " Start Index: " + u8toStr(u8StartIx); 1012 | print_string += "\n"; 1013 | print_string += " Nb Table List Count: " + u8toStr(u8NbTableListCount); 1014 | print_string += "\n"; 1015 | 1016 | ////comboBoxAddressList.Items.Clear(); 1017 | 1018 | if (u8NbTableListCount > 0) 1019 | { 1020 | byte i; 1021 | uint64_t u64PanID = 0; 1022 | uint64_t u64ExtAddr = 0; 1023 | uint16_t u16NwkAddr = 0; 1024 | byte u8Lqi = 0; 1025 | byte u8Depth = 0; 1026 | byte u8Flags = 0; 1027 | byte u8PayloadIndex = 5; 1028 | 1029 | for (i = 0; i < u8NbTableListCount; i++) 1030 | { 1031 | u16NwkAddr = 0; 1032 | for (int x = 0; x < 2; x++, u8PayloadIndex++) 1033 | { 1034 | u16NwkAddr <<= 8; 1035 | u16NwkAddr |= au8Data[u8PayloadIndex]; 1036 | } 1037 | 1038 | u64PanID = 0; 1039 | for (int x = 0; x < 8; x++, u8PayloadIndex++) 1040 | { 1041 | u64PanID <<= 8; 1042 | u64PanID |= au8Data[u8PayloadIndex]; 1043 | } 1044 | 1045 | u64ExtAddr = 0; 1046 | for (int x = 0; x < 8; x++, u8PayloadIndex++) 1047 | { 1048 | u64ExtAddr <<= 8; 1049 | u64ExtAddr |= au8Data[u8PayloadIndex]; 1050 | } 1051 | 1052 | au16NwkAddr[i] = u16NwkAddr; 1053 | 1054 | au64ExtAddr[i] = u64ExtAddr; 1055 | 1056 | u8Depth = au8Data[u8PayloadIndex++]; 1057 | u8Lqi = au8Data[u8PayloadIndex++]; 1058 | u8Flags = au8Data[u8PayloadIndex++]; 1059 | 1060 | print_string += " Neighbor " + i; 1061 | print_string += ":"; 1062 | print_string += "\n"; 1063 | print_string += " Extended Pan ID: " + u64toStr(u64PanID); 1064 | print_string += "\n"; 1065 | print_string += " Extended Address: " + u64toStr(u64ExtAddr); 1066 | print_string += "\n"; 1067 | print_string += " Nwk Address: " + u16toStr(u16NwkAddr); 1068 | print_string += "\n"; 1069 | print_string += " LQI: " + String(u8Lqi, DEC); 1070 | print_string += "\n"; 1071 | print_string += " Depth: " + String(u8Depth, HEX); 1072 | print_string += "\n"; 1073 | print_string += " Flags: 0x" + String(u8Flags, HEX); 1074 | print_string += "\n"; 1075 | 1076 | byte u8DeviceType = (byte)(u8Flags & 0x03); 1077 | print_string += " Device Type: "; 1078 | 1079 | if (u8DeviceType == 0) 1080 | { 1081 | print_string += "Coordinator"; 1082 | } 1083 | else if (u8DeviceType == 1) 1084 | { 1085 | print_string += "Router"; 1086 | } 1087 | else if (u8DeviceType == 2) 1088 | { 1089 | print_string += "End Device"; 1090 | } 1091 | else 1092 | { 1093 | print_string += "Unknown"; 1094 | } 1095 | print_string += "\n"; 1096 | 1097 | byte u8PermitJoin = (byte)((u8Flags & 0x0C) >> 2); 1098 | print_string += " Permit Joining: "; 1099 | 1100 | if (u8PermitJoin == 0) 1101 | { 1102 | print_string += "Off"; 1103 | } 1104 | else if (u8PermitJoin == 1) 1105 | { 1106 | print_string += "On"; 1107 | } 1108 | else 1109 | { 1110 | print_string += "Unknown"; 1111 | } 1112 | print_string += "\n"; 1113 | 1114 | byte u8Relationship = (byte)((u8Flags & 0x30) >> 4); 1115 | print_string += " Relationship: "; 1116 | 1117 | if (u8Relationship == 0) 1118 | { 1119 | print_string += "Parent"; 1120 | } 1121 | else if (u8Relationship == 1) 1122 | { 1123 | print_string += "Child"; 1124 | } 1125 | else if (u8Relationship == 2) 1126 | { 1127 | print_string += "Sibling"; 1128 | } 1129 | else if (u8Relationship == 4) 1130 | { 1131 | print_string += "Previous Child"; 1132 | } 1133 | else 1134 | { 1135 | print_string += "Unknown"; 1136 | } 1137 | print_string += "\n"; 1138 | 1139 | byte u8RxOnWhenIdle = (byte)((u8Flags & 0xC0) >> 6); 1140 | print_string += " RxOnWhenIdle: "; 1141 | 1142 | if (u8RxOnWhenIdle == 0) 1143 | { 1144 | print_string += "No"; 1145 | } 1146 | else if (u8RxOnWhenIdle == 1) 1147 | { 1148 | print_string += "Yes"; 1149 | } 1150 | else 1151 | { 1152 | print_string += "Unknown"; 1153 | } 1154 | print_string += "\n"; 1155 | } 1156 | for (i = 0; i < u8NbTableListCount; i++) 1157 | { 1158 | //comboBoxAddressList.Items.Add(au16NwkAddr[i]); 1159 | } 1160 | } 1161 | } 1162 | break; 1163 | 1164 | case 0x8050: 1165 | { 1166 | uint16_t u16TableSize; 1167 | uint16_t u16TableEntries; 1168 | 1169 | u16TableSize = au8Data[1]; 1170 | u16TableSize <<= 8; 1171 | u16TableSize |= au8Data[2]; 1172 | 1173 | u16TableEntries = au8Data[3]; 1174 | u16TableEntries <<= 8; 1175 | u16TableEntries |= au8Data[4]; 1176 | 1177 | print_string += " (Addr Map Table Response)"; 1178 | print_string += "\n"; 1179 | print_string += " Status: 0x" + au8Data[0]; 1180 | print_string += "\n"; 1181 | print_string += " Table Size: " + u16TableSize; 1182 | print_string += "\n"; 1183 | print_string += " Entries: " + u16TableEntries; 1184 | print_string += "\n"; 1185 | 1186 | byte i; 1187 | for (i = 0; i < u16TableEntries; i++) 1188 | { 1189 | uint16_t u16Addr; 1190 | uint64_t u64Addr; 1191 | 1192 | u16Addr = au8Data[5 + (i * 8)]; 1193 | u16Addr <<= 8; 1194 | u16Addr |= au8Data[6 + (i * 8)]; 1195 | 1196 | u64Addr = au8Data[7 + (i * 8)]; 1197 | u64Addr <<= 8; 1198 | u64Addr |= au8Data[8 + (i * 8)]; 1199 | u64Addr <<= 8; 1200 | u64Addr |= au8Data[9 + (i * 8)]; 1201 | u64Addr <<= 8; 1202 | u64Addr |= au8Data[10 + (i * 8)]; 1203 | u64Addr <<= 8; 1204 | u64Addr |= au8Data[11 + (i * 8)]; 1205 | u64Addr <<= 8; 1206 | u64Addr |= au8Data[12 + (i * 8)]; 1207 | u64Addr <<= 8; 1208 | u64Addr |= au8Data[13 + (i * 8)]; 1209 | u64Addr <<= 8; 1210 | u64Addr |= au8Data[14 + (i * 8)]; 1211 | 1212 | print_string += " Entry " + i; 1213 | print_string += ": 0x" + u16Addr; 1214 | print_string += " 0x" + u64Addr; 1215 | 1216 | print_string += "\n"; 1217 | } 1218 | 1219 | } 1220 | break; 1221 | 1222 | case 0x8060: 1223 | { 1224 | uint16_t u16ClusterId = 0; 1225 | uint16_t u16GroupId = 0; 1226 | 1227 | u16ClusterId = au8Data[2]; 1228 | u16ClusterId <<= 8; 1229 | u16ClusterId |= au8Data[3]; 1230 | 1231 | u16GroupId = au8Data[5]; 1232 | u16GroupId <<= 8; 1233 | u16GroupId |= au8Data[6]; 1234 | 1235 | print_string += " (Add Group Response)"; 1236 | print_string += "\n"; 1237 | print_string += " SQN: 0x" + au8Data[0]; 1238 | print_string += "\n"; 1239 | print_string += " EndPoint: 0x" + au8Data[1]; 1240 | print_string += "\n"; 1241 | //displayClusterId(u16ClusterId); 1242 | print_string += "\n"; 1243 | print_string += " Status: 0x" + au8Data[4]; 1244 | print_string += "\n"; 1245 | print_string += " Group: 0x" + u16GroupId; 1246 | print_string += "\n"; 1247 | } 1248 | break; 1249 | 1250 | case 0x8061: 1251 | { 1252 | uint16_t u16ClusterId = 0; 1253 | uint16_t u16GroupId = 0; 1254 | 1255 | u16ClusterId = au8Data[2]; 1256 | u16ClusterId <<= 8; 1257 | u16ClusterId |= au8Data[3]; 1258 | 1259 | u16GroupId = au8Data[5]; 1260 | u16GroupId <<= 8; 1261 | u16GroupId |= au8Data[6]; 1262 | 1263 | print_string += " (View Group Response)"; 1264 | print_string += "\n"; 1265 | print_string += " SQN: 0x" + au8Data[0]; 1266 | print_string += "\n"; 1267 | print_string += " EndPoint: 0x" + au8Data[1]; 1268 | print_string += "\n"; 1269 | //displayClusterId(u16ClusterId); 1270 | print_string += "\n"; 1271 | print_string += " Status: 0x" + au8Data[4]; 1272 | print_string += "\n"; 1273 | print_string += " Group: 0x" + u16GroupId; 1274 | print_string += "\n"; 1275 | } 1276 | break; 1277 | 1278 | case 0x8062: 1279 | { 1280 | uint16_t u16ClusterId = 0; 1281 | u16ClusterId = au8Data[2]; 1282 | u16ClusterId <<= 8; 1283 | u16ClusterId |= au8Data[3]; 1284 | 1285 | print_string += " (Get Group Response)"; 1286 | print_string += "\n"; 1287 | print_string += " SQN: 0x" + au8Data[0]; 1288 | print_string += "\n"; 1289 | print_string += " EndPoint: 0x" + au8Data[1]; 1290 | print_string += "\n"; 1291 | //displayClusterId(u16ClusterId); 1292 | print_string += "\n"; 1293 | print_string += " Capacity: " + au8Data[4]; 1294 | print_string += "\n"; 1295 | print_string += " Count: " + au8Data[5]; 1296 | print_string += "\n"; 1297 | 1298 | byte i; 1299 | for (i = 0; i < au8Data[5]; i++) 1300 | { 1301 | uint16_t u16GroupId; 1302 | 1303 | u16GroupId = au8Data[6 + (i * 2)]; 1304 | u16GroupId <<= 8; 1305 | u16GroupId |= au8Data[7 + (i * 2)]; 1306 | 1307 | print_string += " Group " + i; 1308 | print_string += ": 0x" + u16GroupId; 1309 | print_string += "\n"; 1310 | } 1311 | } 1312 | break; 1313 | 1314 | case 0x8063: 1315 | { 1316 | uint16_t u16ClusterId = 0; 1317 | uint16_t u16GroupId = 0; 1318 | 1319 | u16ClusterId = au8Data[2]; 1320 | u16ClusterId <<= 8; 1321 | u16ClusterId |= au8Data[3]; 1322 | 1323 | u16GroupId = au8Data[5]; 1324 | u16GroupId <<= 8; 1325 | u16GroupId |= au8Data[6]; 1326 | 1327 | print_string += " (Remove Group Response)"; 1328 | print_string += "\n"; 1329 | print_string += " SQN: 0x" + au8Data[0]; 1330 | print_string += "\n"; 1331 | print_string += " EndPoint: 0x" + au8Data[1]; 1332 | print_string += "\n"; 1333 | //displayClusterId(u16ClusterId); 1334 | print_string += "\n"; 1335 | print_string += " Status: 0x" + au8Data[4]; 1336 | print_string += "\n"; 1337 | print_string += " Group: 0x" + u16GroupId; 1338 | print_string += "\n"; 1339 | } 1340 | break; 1341 | 1342 | case 0x807A: 1343 | { 1344 | print_string += " (Identify Local Active)"; 1345 | print_string += "\n"; 1346 | if (au8Data[0] == 1) 1347 | { 1348 | print_string += " Status: Start Identifying"; 1349 | print_string += "\n"; 1350 | } 1351 | else if (au8Data[0] != 1) 1352 | { 1353 | print_string += " Status: Stop Identifying"; 1354 | print_string += "\n"; 1355 | } 1356 | } 1357 | break; 1358 | 1359 | case 0x8095: 1360 | { 1361 | uint16_t u16ClusterId = 0; 1362 | 1363 | u16ClusterId = au8Data[2]; 1364 | u16ClusterId <<= 8; 1365 | u16ClusterId |= au8Data[3]; 1366 | 1367 | print_string += " (On/Off Update)"; 1368 | print_string += "\n"; 1369 | print_string += " SQN: 0x" + au8Data[0]; 1370 | print_string += "\n"; 1371 | print_string += " EndPoint: 0x" + au8Data[1]; 1372 | print_string += "\n"; 1373 | //displayClusterId(u16ClusterId); 1374 | print_string += "\n"; 1375 | print_string += " Src Addr Mode: 0x" + au8Data[4]; 1376 | print_string += "\n"; 1377 | 1378 | if (au8Data[4] == 0x03) 1379 | { 1380 | } 1381 | else 1382 | { 1383 | uint16_t u16Addr = 0; 1384 | 1385 | u16Addr = au8Data[5]; 1386 | u16Addr <<= 8; 1387 | u16Addr |= au8Data[6]; 1388 | 1389 | print_string += " Src Addr Mode: 0x" + u16Addr; 1390 | print_string += "\n"; 1391 | print_string += " Status: 0x" + au8Data[7]; 1392 | print_string += "\n"; 1393 | } 1394 | } 1395 | break; 1396 | 1397 | case 0x80A0: 1398 | { 1399 | uint16_t u16ClusterId = 0, u16GroupId = 0, u16TransTime = 0, u16SceneLength = 0; 1400 | byte u8Status; 1401 | 1402 | u16ClusterId = au8Data[2]; 1403 | u16ClusterId <<= 8; 1404 | u16ClusterId |= au8Data[3]; 1405 | 1406 | u8Status = au8Data[4]; 1407 | 1408 | u16GroupId = au8Data[5]; 1409 | u16GroupId <<= 8; 1410 | u16GroupId |= au8Data[6]; 1411 | 1412 | 1413 | print_string += " (View Scene)"; 1414 | print_string += "\n"; 1415 | print_string += " SQN: 0x" + au8Data[0]; 1416 | print_string += "\n"; 1417 | print_string += " EndPoint: 0x" + au8Data[1]; 1418 | print_string += "\n"; 1419 | print_string += " Cluster ID: 0x" + u16ClusterId; 1420 | print_string += "\n"; 1421 | print_string += " Status: 0x" + u8Status; 1422 | print_string += "\n"; 1423 | print_string += " Group ID: 0x" + u16GroupId; 1424 | print_string += "\n"; 1425 | print_string += " Scene Id: 0x" + au8Data[7]; 1426 | 1427 | if (0 == u8Status) 1428 | { 1429 | u16TransTime = au8Data[8]; 1430 | u16TransTime <<= 8; 1431 | u16TransTime |= au8Data[9]; 1432 | 1433 | print_string += "\n"; 1434 | print_string += " Transition Time: 0x" + u16TransTime; 1435 | print_string += "\n"; 1436 | print_string += " Scene Name Length: 0x" + au8Data[10]; 1437 | print_string += "\n"; 1438 | print_string += " Scene Name Max Length: 0x" + au8Data[11]; 1439 | print_string += "\n"; 1440 | 1441 | print_string += " Scene Name: "; 1442 | 1443 | byte i = 0; 1444 | for (i = 0; i < au8Data[10]; i++) 1445 | { 1446 | //print_string += Convert.ToChar(au8Data[12 + i]); 1447 | } 1448 | 1449 | u16SceneLength = au8Data[12 + i]; 1450 | u16SceneLength <<= 8; 1451 | u16SceneLength |= au8Data[13 + i]; 1452 | 1453 | print_string += "\n"; 1454 | print_string += " Ext Scene Length: 0x" + u16SceneLength; 1455 | print_string += "\n"; 1456 | print_string += " Ext Max Length: 0x" + au8Data[14 + i]; 1457 | print_string += "\n"; 1458 | print_string += " Scene Data: "; 1459 | print_string += "\n "; 1460 | 1461 | for (byte c = 0; i < u16SceneLength; i++) 1462 | { 1463 | //print_string += "0x" + au8Data[15 + i + c] + " "; 1464 | } 1465 | } 1466 | 1467 | } 1468 | break; 1469 | 1470 | case 0x80A3: 1471 | { 1472 | uint16_t u16ClusterId, u16GroupId; 1473 | 1474 | u16ClusterId = au8Data[2]; 1475 | u16ClusterId <<= 8; 1476 | u16ClusterId |= au8Data[3]; 1477 | 1478 | u16GroupId = au8Data[5]; 1479 | u16GroupId <<= 8; 1480 | u16GroupId |= au8Data[6]; 1481 | 1482 | print_string += " (Remove All Scenes)"; 1483 | print_string += "\n"; 1484 | print_string += " SQN: 0x" + au8Data[0]; 1485 | print_string += "\n"; 1486 | print_string += " EndPoint: 0x" + au8Data[1]; 1487 | print_string += "\n"; 1488 | print_string += " Cluster ID: 0x" + u16ClusterId; 1489 | print_string += "\n"; 1490 | print_string += " Status: 0x" + au8Data[4]; 1491 | print_string += "\n"; 1492 | print_string += " Group ID: 0x" + u16GroupId; 1493 | } 1494 | break; 1495 | 1496 | case 0x80A2: 1497 | { 1498 | uint16_t u16ClusterId, u16GroupId; 1499 | 1500 | u16ClusterId = au8Data[2]; 1501 | u16ClusterId <<= 8; 1502 | u16ClusterId |= au8Data[3]; 1503 | 1504 | u16GroupId = au8Data[5]; 1505 | u16GroupId <<= 8; 1506 | u16GroupId |= au8Data[6]; 1507 | 1508 | print_string += " (Remove Scene)"; 1509 | print_string += "\n"; 1510 | print_string += " SQN: 0x" + au8Data[0]; 1511 | print_string += "\n"; 1512 | print_string += " EndPoint: 0x" + au8Data[1]; 1513 | print_string += "\n"; 1514 | print_string += " Cluster ID: 0x" + u16ClusterId; 1515 | print_string += "\n"; 1516 | print_string += " Status: 0x" + au8Data[4]; 1517 | print_string += "\n"; 1518 | print_string += " Group ID: 0x" + u16GroupId; 1519 | print_string += "\n"; 1520 | print_string += " Scene ID: 0x" + au8Data[7]; 1521 | } 1522 | break; 1523 | 1524 | case 0x8100: // Read attribute response 1525 | { 1526 | uint16_t u16ClusterId = 0; 1527 | uint16_t u16AttribId = 0; 1528 | uint16_t u16SrcAddr = 0; 1529 | uint16_t u16AttributeSize = 0; 1530 | 1531 | u16SrcAddr = au8Data[1]; 1532 | u16SrcAddr <<= 8; 1533 | u16SrcAddr |= au8Data[2]; 1534 | 1535 | u16ClusterId = au8Data[4]; 1536 | u16ClusterId <<= 8; 1537 | u16ClusterId |= au8Data[5]; 1538 | 1539 | u16AttribId = au8Data[6]; 1540 | u16AttribId <<= 8; 1541 | u16AttribId |= au8Data[7]; 1542 | 1543 | u16AttributeSize = au8Data[10]; 1544 | u16AttributeSize <<= 8; 1545 | u16AttributeSize |= au8Data[11]; 1546 | 1547 | print_string += " (Read Attrib Response)"; 1548 | print_string += "\n"; 1549 | print_string += " SQN: 0x" + String(au8Data[0], HEX); 1550 | print_string += "\n"; 1551 | print_string += " Src Addr: 0x" + String(u16SrcAddr, HEX); 1552 | print_string += "\n"; 1553 | print_string += " EndPoint: 0x" + String(au8Data[3], HEX); 1554 | print_string += "\n"; 1555 | print_string += " Status: 0x" + String(au8Data[8], HEX); 1556 | print_string += "\n"; 1557 | //displayClusterId(u16ClusterId); 1558 | print_string += "\n"; 1559 | //displayAttribute(u16AttribId, au8Data[9], au8Data, 12, u16AttributeSize); 1560 | } 1561 | break; 1562 | 1563 | case 0x8101: 1564 | { 1565 | uint16_t u16ClusterId = 0; 1566 | uint16_t u16DstAddr = 0; 1567 | 1568 | u16ClusterId = au8Data[13]; 1569 | u16ClusterId <<= 8; 1570 | u16ClusterId |= au8Data[14]; 1571 | 1572 | u16DstAddr = au8Data[1]; 1573 | u16DstAddr <<= 8; 1574 | u16DstAddr |= au8Data[2]; 1575 | 1576 | print_string += " (Default Response)"; 1577 | print_string += "\n"; 1578 | print_string += " SQN: 0x" + au8Data[0]; 1579 | print_string += "\n"; 1580 | print_string += " Short Address: 0x" + u16DstAddr; 1581 | print_string += "\n"; 1582 | print_string += " Source EndPoint: 0x" + au8Data[11]; 1583 | print_string += "\n"; 1584 | print_string += " Destination EndPoint: 0x" + au8Data[12]; 1585 | print_string += "\n"; 1586 | //displayClusterId(u16ClusterId); 1587 | print_string += "\n"; 1588 | print_string += " Command: 0x" + au8Data[15]; 1589 | print_string += "\n"; 1590 | print_string += " Status: 0x" + au8Data[16]; 1591 | print_string += "\n"; 1592 | } 1593 | break; 1594 | 1595 | case 0x8120: 1596 | { 1597 | uint16_t u16ClusterId = 0; 1598 | uint16_t u16SrcAddr = 0; 1599 | 1600 | u16ClusterId = au8Data[4]; 1601 | u16ClusterId <<= 8; 1602 | u16ClusterId |= au8Data[5]; 1603 | 1604 | u16SrcAddr = au8Data[1]; 1605 | u16SrcAddr <<= 8; 1606 | u16SrcAddr |= au8Data[2]; 1607 | 1608 | print_string += " (Report Config Response)"; 1609 | print_string += "\n"; 1610 | print_string += " SQN: 0x" + au8Data[0]; 1611 | print_string += "\n"; 1612 | print_string += " Src Addr: 0x" + u16SrcAddr; 1613 | print_string += "\n"; 1614 | print_string += " EndPoint: 0x" + au8Data[3]; 1615 | print_string += "\n"; 1616 | //displayClusterId(u16ClusterId); 1617 | print_string += "\n"; 1618 | print_string += " Status: 0x" + au8Data[6]; 1619 | print_string += "\n"; 1620 | } 1621 | break; 1622 | 1623 | case 0x8102: 1624 | { 1625 | uint16_t u16SrcAddr = 0; 1626 | uint16_t u16ClusterId = 0; 1627 | uint16_t u16AttribId = 0; 1628 | uint16_t u16AttributeSize = 0; 1629 | 1630 | u16SrcAddr = au8Data[1]; 1631 | u16SrcAddr <<= 8; 1632 | u16SrcAddr |= au8Data[2]; 1633 | 1634 | u16ClusterId = au8Data[4]; 1635 | u16ClusterId <<= 8; 1636 | u16ClusterId |= au8Data[5]; 1637 | 1638 | u16AttribId = au8Data[6]; 1639 | u16AttribId <<= 8; 1640 | u16AttribId |= au8Data[7]; 1641 | 1642 | u16AttributeSize = au8Data[10]; 1643 | u16AttributeSize <<= 8; 1644 | u16AttributeSize |= au8Data[11]; 1645 | 1646 | print_string += " (Attribute Report)"; 1647 | print_string += "\n"; 1648 | //print_string += " SQN: 0x" + String(au8Data[0], HEX); 1649 | //print_string += "\n"; 1650 | //print_string += " Src Addr: 0x" + String(u16SrcAddr, HEX); 1651 | //print_string += "\n"; 1652 | //print_string += " Src Ep: 0x" + String(au8Data[3], DEC); 1653 | //print_string += "\n"; 1654 | //print_string += " Cluster: 0x" + String(u16ClusterId, HEX); 1655 | //displayClusterId(u16ClusterId); 1656 | //print_string += "\n"; 1657 | displayAttribute(au8Data[0], u16SrcAddr, u16ClusterId, u16AttribId, au8Data[9], au8Data, 12, u16AttributeSize); 1658 | } 1659 | break; 1660 | 1661 | case 0x8122: 1662 | { 1663 | uint16_t u16SrcAddr = 0; 1664 | uint16_t u16ClusterId = 0; 1665 | uint16_t u16AttribId = 0; 1666 | uint16_t u16MaxInterval = 0; 1667 | uint16_t u16MinInterval = 0; 1668 | 1669 | u16SrcAddr = au8Data[1]; 1670 | u16SrcAddr <<= 8; 1671 | u16SrcAddr |= au8Data[2]; 1672 | 1673 | u16ClusterId = au8Data[4]; 1674 | u16ClusterId <<= 8; 1675 | u16ClusterId |= au8Data[5]; 1676 | 1677 | u16AttribId = au8Data[8]; 1678 | u16AttribId <<= 8; 1679 | u16AttribId |= au8Data[9]; 1680 | 1681 | u16MaxInterval = au8Data[10]; 1682 | u16MaxInterval <<= 8; 1683 | u16MaxInterval |= au8Data[11]; 1684 | 1685 | u16MinInterval = au8Data[12]; 1686 | u16MinInterval <<= 8; 1687 | u16MinInterval |= au8Data[13]; 1688 | 1689 | print_string += " (Attribute Config Report)"; 1690 | print_string += "\n"; 1691 | print_string += " SQN: 0x" + au8Data[0]; 1692 | print_string += "\n"; 1693 | print_string += " Src Addr: 0x" + u16SrcAddr; 1694 | print_string += "\n"; 1695 | print_string += " Src Ep: 0x" + au8Data[3]; 1696 | print_string += "\n"; 1697 | //displayClusterId(u16ClusterId); 1698 | print_string += "\n"; 1699 | print_string += " Status: 0x" + au8Data[6]; 1700 | print_string += "\n"; 1701 | //displayAttribute(au8Data[7]); 1702 | print_string += "\n"; 1703 | print_string += " Attribute: 0x" + u16AttribId; 1704 | print_string += "\n"; 1705 | print_string += " Min Interval: " + u16MinInterval; 1706 | print_string += "\n"; 1707 | print_string += " Max Interval: " + u16MaxInterval; 1708 | print_string += "\n"; 1709 | } 1710 | break; 1711 | 1712 | case 0x8103: // Read local attribute response 1713 | { 1714 | uint16_t u16ClusterId = 0; 1715 | uint16_t u16AttribId = 0; 1716 | uint16_t u16SrcAddr = 0; 1717 | uint16_t u16AttributeSize = 0; 1718 | 1719 | u16SrcAddr = au8Data[1]; 1720 | u16SrcAddr <<= 8; 1721 | u16SrcAddr |= au8Data[2]; 1722 | 1723 | u16ClusterId = au8Data[4]; 1724 | u16ClusterId <<= 8; 1725 | u16ClusterId |= au8Data[5]; 1726 | 1727 | u16AttribId = au8Data[6]; 1728 | u16AttribId <<= 8; 1729 | u16AttribId |= au8Data[7]; 1730 | 1731 | u16AttributeSize = au8Data[10]; 1732 | u16AttributeSize <<= 8; 1733 | u16AttributeSize |= au8Data[11]; 1734 | 1735 | print_string += " (Read Local Attrib Response)"; 1736 | print_string += "\n"; 1737 | print_string += " SQN: 0x" + au8Data[0]; 1738 | print_string += "\n"; 1739 | //print_string += " Src Addr: 0x" + u16SrcAddr; 1740 | //print_string += "\n"; 1741 | print_string += " EndPoint: 0x" + au8Data[3]; 1742 | print_string += "\n"; 1743 | print_string += " Status: 0x" + au8Data[8]; 1744 | print_string += "\n"; 1745 | //displayClusterId(u16ClusterId); 1746 | print_string += "\n"; 1747 | ////displayAttribute(u16AttribId, au8Data[9], au8Data, 12, u16AttributeSize); 1748 | } 1749 | break; 1750 | 1751 | case 0x8140: // Discover attribute response 1752 | { 1753 | uint16_t u16AttribId = 0; 1754 | 1755 | u16AttribId = au8Data[2]; 1756 | u16AttribId <<= 8; 1757 | u16AttribId |= au8Data[3]; 1758 | 1759 | print_string += " (Discover Attrib Response)"; 1760 | print_string += "\n"; 1761 | print_string += " Complete: 0x" + au8Data[0]; 1762 | print_string += "\n"; 1763 | //displayAttribute(au8Data[1]); 1764 | print_string += "\n"; 1765 | print_string += " Attribute: 0x" + u16AttribId; 1766 | print_string += "\n"; 1767 | } 1768 | break; 1769 | 1770 | case 0x8141: // Discover extended attribute response 1771 | { 1772 | uint16_t u16AttribId = 0; 1773 | 1774 | u16AttribId = au8Data[2]; 1775 | u16AttribId <<= 8; 1776 | u16AttribId |= au8Data[3]; 1777 | 1778 | print_string += " (Discover Attrib Response)"; 1779 | print_string += "\n"; 1780 | print_string += " Complete: 0x" + au8Data[0]; 1781 | print_string += "\n"; 1782 | //displayDataType(au8Data[1]); 1783 | print_string += "\n"; 1784 | print_string += " Attribute: 0x" + u16AttribId; 1785 | print_string += "\n"; 1786 | print_string += " Flags: 0x" + au8Data[4]; 1787 | print_string += "\n"; 1788 | } 1789 | break; 1790 | 1791 | case 0x8150: // Discover command received individual response 1792 | { 1793 | print_string += " (Discover Command Received Individual Response)"; 1794 | print_string += "\n"; 1795 | print_string += " Command: 0x" + au8Data[0]; 1796 | print_string += "\n"; 1797 | print_string += " Index: 0x" + au8Data[1]; 1798 | print_string += "\n"; 1799 | } 1800 | break; 1801 | 1802 | case 0x8151: // Discover command received response 1803 | { 1804 | print_string += " (Discover Command Received Response)"; 1805 | print_string += "\n"; 1806 | print_string += " Complete: 0x" + au8Data[0]; 1807 | print_string += "\n"; 1808 | print_string += " Commands: " + au8Data[1]; 1809 | print_string += "\n"; 1810 | } 1811 | break; 1812 | 1813 | case 0x8160: // Discover command generated individual response 1814 | { 1815 | print_string += " (Discover Command Generated Individual Response)"; 1816 | print_string += "\n"; 1817 | print_string += " Command: 0x" + au8Data[0]; 1818 | print_string += "\n"; 1819 | print_string += " Index: 0x" + au8Data[1]; 1820 | print_string += "\n"; 1821 | } 1822 | break; 1823 | 1824 | case 0x8161: // Discover command generated response 1825 | { 1826 | print_string += " (Discover Command Generated Response)"; 1827 | print_string += "\n"; 1828 | print_string += " Complete: 0x" + au8Data[0]; 1829 | print_string += "\n"; 1830 | print_string += " Commands: " + au8Data[1]; 1831 | print_string += "\n"; 1832 | } 1833 | break; 1834 | 1835 | case 0x8401: 1836 | { 1837 | uint16_t u16ClusterId = 0; 1838 | uint16_t u16ZoneStatus = 0; 1839 | uint16_t u16Delay = 0; 1840 | 1841 | u16ClusterId = au8Data[2]; 1842 | u16ClusterId <<= 8; 1843 | u16ClusterId |= au8Data[3]; 1844 | 1845 | print_string += " (IAS Zone Status Change)"; 1846 | print_string += "\n"; 1847 | print_string += " SQN: 0x" + au8Data[0]; 1848 | print_string += "\n"; 1849 | print_string += " EndPoint: 0x" + au8Data[1]; 1850 | print_string += "\n"; 1851 | //displayClusterId(u16ClusterId); 1852 | print_string += "\n"; 1853 | print_string += " Src Addr Mode: 0x" + au8Data[4]; 1854 | print_string += "\n"; 1855 | 1856 | if (au8Data[4] == 0x03) 1857 | { 1858 | } 1859 | else 1860 | { 1861 | uint16_t u16Addr = 0; 1862 | 1863 | u16Addr = au8Data[5]; 1864 | u16Addr <<= 8; 1865 | u16Addr |= au8Data[6]; 1866 | 1867 | print_string += " Src Addr Mode: 0x" + u16Addr; 1868 | print_string += "\n"; 1869 | } 1870 | 1871 | u16ZoneStatus = au8Data[7]; 1872 | u16ZoneStatus <<= 8; 1873 | u16ZoneStatus |= au8Data[8]; 1874 | 1875 | print_string += " Zone Status: 0x" + u16ZoneStatus; 1876 | print_string += "\n"; 1877 | print_string += " Ext Status: 0x" + au8Data[9]; 1878 | print_string += "\n"; 1879 | print_string += " Zone ID: 0x" + au8Data[10]; 1880 | print_string += "\n"; 1881 | 1882 | u16Delay = au8Data[11]; 1883 | u16Delay <<= 8; 1884 | u16Delay |= au8Data[12]; 1885 | 1886 | print_string += " Delay: 0x" + u16Delay; 1887 | print_string += "\n"; 1888 | } 1889 | break; 1890 | 1891 | case 0x004D: 1892 | { 1893 | 1894 | uint16_t u16ShortAddr = 0; 1895 | uint64_t u64ExtAddr = 0; 1896 | 1897 | u16ShortAddr = au8Data[0]; 1898 | u16ShortAddr <<= 8; 1899 | u16ShortAddr |= au8Data[1]; 1900 | 1901 | for (int i = 0; i < 8; i++) 1902 | { 1903 | u64ExtAddr <<= 8; 1904 | u64ExtAddr |= au8Data[2 + i]; 1905 | } 1906 | /* 1907 | unsigned long u16ShortAddr_long = u16ShortAddr; 1908 | unsigned long u64ExtAddr_long = u64ExtAddr; 1909 | 1910 | print_string += " (End Device Announce)"; 1911 | print_string += "\n"; 1912 | print_string += " Short Address: 0x" + String(u16ShortAddr_long, HEX); 1913 | print_string += "\n"; 1914 | print_string += " Extended Address: 0x" + String(u64ExtAddr_long, HEX); 1915 | print_string += "\n"; 1916 | */ 1917 | new_device_LongAddr = u64ExtAddr; 1918 | new_device_ShortAddr = u16ShortAddr; 1919 | new_device_connected = true; 1920 | 1921 | //activeEndpointDescriptorRequest(u16ShortAddr); 1922 | } 1923 | break; 1924 | 1925 | case 0x8501: 1926 | { 1927 | 1928 | } 1929 | break; 1930 | case 0x8503: 1931 | { 1932 | 1933 | 1934 | } 1935 | break; 1936 | 1937 | case 0x8110: 1938 | { 1939 | uint16_t u16SrcAddr = 0; 1940 | uint16_t u16ClusterId = 0; 1941 | uint16_t u16AttribId = 0; 1942 | uint16_t u16AttributeSize = 0; 1943 | 1944 | u16SrcAddr = au8Data[1]; 1945 | u16SrcAddr <<= 8; 1946 | u16SrcAddr |= au8Data[2]; 1947 | 1948 | u16ClusterId = au8Data[4]; 1949 | u16ClusterId <<= 8; 1950 | u16ClusterId |= au8Data[5]; 1951 | 1952 | u16AttribId = au8Data[6]; 1953 | u16AttribId <<= 8; 1954 | u16AttribId |= au8Data[7]; 1955 | 1956 | u16AttributeSize = au8Data[10]; 1957 | u16AttributeSize <<= 8; 1958 | u16AttributeSize |= au8Data[11]; 1959 | 1960 | print_string += " (Write Attrib Response)"; 1961 | print_string += "\n"; 1962 | print_string += " SQN: 0x" + au8Data[0]; 1963 | print_string += "\n"; 1964 | print_string += " Src Addr: 0x" + u16SrcAddr; 1965 | print_string += "\n"; 1966 | print_string += " Src Ep: 0x" + au8Data[3]; 1967 | print_string += "\n"; 1968 | ////displayClusterId(u16ClusterId); 1969 | print_string += "\n"; 1970 | ////displayAttribute(u16AttribId, au8Data[9], au8Data, 12, u16AttributeSize); 1971 | print_string += " Status: 0x" + au8Data[8]; 1972 | print_string += "\n"; 1973 | } 1974 | break; 1975 | 1976 | case 0x8600: 1977 | { 1978 | //nwkRecovery.NetworkRecoveryParseBuffer(au8Data); 1979 | print_string += " (Retrieve Network Recovery Response)"; 1980 | print_string += "\n"; 1981 | //print_string += nwkRecovery; 1982 | print_string += "\n"; 1983 | } 1984 | break; 1985 | 1986 | case 0x8601: 1987 | { 1988 | print_string += " (Restore Network Recovery Response)"; 1989 | print_string += "\n"; 1990 | print_string += " Success = " + au8Data[0]; 1991 | print_string += "\n"; 1992 | } 1993 | break; 1994 | 1995 | case 0x80A4: 1996 | { 1997 | uint16_t u16GroupId; 1998 | uint16_t u16ClusterId; 1999 | 2000 | u16ClusterId = au8Data[2]; 2001 | u16ClusterId <<= 8; 2002 | u16ClusterId |= au8Data[3]; 2003 | 2004 | u16GroupId = au8Data[5]; 2005 | u16GroupId <<= 8; 2006 | u16GroupId |= au8Data[6]; 2007 | 2008 | print_string += " (Store Scene Response)"; 2009 | print_string += "\n"; 2010 | print_string += " Tx Num: 0x" + au8Data[0]; 2011 | print_string += "\n"; 2012 | print_string += " Source Endpoint: 0x" + au8Data[1]; 2013 | print_string += "\n"; 2014 | print_string += " Cluster ID: 0x" + u16ClusterId; 2015 | print_string += "\n"; 2016 | print_string += " Status: 0x" + au8Data[4]; 2017 | print_string += "\n"; 2018 | print_string += " Group ID: 0x" + u16GroupId; 2019 | print_string += "\n"; 2020 | print_string += " Scene ID: 0x" + au8Data[7]; 2021 | print_string += "\n"; 2022 | } 2023 | break; 2024 | 2025 | case 0x80A1: 2026 | { 2027 | uint16_t u16GroupId; 2028 | uint16_t u16ClusterId; 2029 | 2030 | u16ClusterId = au8Data[2]; 2031 | u16ClusterId <<= 8; 2032 | u16ClusterId |= au8Data[3]; 2033 | 2034 | u16GroupId = au8Data[5]; 2035 | u16GroupId <<= 8; 2036 | u16GroupId |= au8Data[6]; 2037 | 2038 | print_string += " (Add Scene Response)"; 2039 | print_string += "\n"; 2040 | print_string += " Tx Num: 0x" + au8Data[0]; 2041 | print_string += "\n"; 2042 | print_string += " Source Endpoint: 0x" + au8Data[1]; 2043 | print_string += "\n"; 2044 | print_string += " Cluster ID: 0x" + u16ClusterId; 2045 | print_string += "\n"; 2046 | print_string += " Status: 0x" + au8Data[4]; 2047 | print_string += "\n"; 2048 | print_string += " Group ID: 0x" + u16GroupId; 2049 | print_string += "\n"; 2050 | print_string += " Scene ID: 0x" + au8Data[7]; 2051 | print_string += "\n"; 2052 | } 2053 | break; 2054 | 2055 | case 0x80A6: 2056 | { 2057 | uint16_t u16GroupId; 2058 | uint16_t u16ClusterId; 2059 | 2060 | u16ClusterId = au8Data[2]; 2061 | u16ClusterId <<= 8; 2062 | u16ClusterId |= au8Data[3]; 2063 | 2064 | u16GroupId = au8Data[6]; 2065 | u16GroupId <<= 8; 2066 | u16GroupId |= au8Data[7]; 2067 | 2068 | print_string += " (Get Scene Membership Response)"; 2069 | print_string += "\n"; 2070 | print_string += " Tx Num: 0x" + au8Data[0]; 2071 | print_string += "\n"; 2072 | print_string += " Source Endpoint: 0x" + au8Data[1]; 2073 | print_string += "\n"; 2074 | print_string += " Cluster ID: 0x" + u16ClusterId; 2075 | print_string += "\n"; 2076 | print_string += " Status: 0x" + au8Data[4]; 2077 | print_string += "\n"; 2078 | print_string += " Capacity: 0x" + au8Data[5]; 2079 | print_string += "\n"; 2080 | print_string += " Group ID: 0x" + u16GroupId; 2081 | print_string += "\n"; 2082 | print_string += " Scene Count: 0x" + au8Data[8]; 2083 | 2084 | if (au8Data[8] != 0) 2085 | { 2086 | print_string += "\n"; 2087 | print_string += " Scene List: "; 2088 | } 2089 | 2090 | byte i; 2091 | 2092 | for (i = 0; i < au8Data[8]; i++) 2093 | { 2094 | 2095 | print_string += "\n"; 2096 | print_string += " Scene: 0x" + au8Data[i + 9]; 2097 | } 2098 | print_string += "\n"; 2099 | } 2100 | break; 2101 | case 0x8046: 2102 | { 2103 | uint16_t u16AddrOfInterest; 2104 | 2105 | u16AddrOfInterest = au8Data[2]; 2106 | u16AddrOfInterest <<= 8; 2107 | u16AddrOfInterest |= au8Data[3]; 2108 | 2109 | print_string += " (Match Descriptor Response)"; 2110 | print_string += "\n"; 2111 | print_string += " SQN: 0x" + au8Data[0]; 2112 | print_string += "\n"; 2113 | print_string += " Status: 0x" + au8Data[1]; 2114 | print_string += "\n"; 2115 | print_string += " Address Of Interest: 0x" + u16AddrOfInterest; 2116 | print_string += "\n"; 2117 | print_string += " Match Length: " + au8Data[4]; 2118 | 2119 | if (au8Data[4] != 0) 2120 | { 2121 | print_string += " Matched Endpoints: "; 2122 | } 2123 | 2124 | byte i; 2125 | for (i = 0; i < au8Data[4]; i++) 2126 | { 2127 | print_string += "\n"; 2128 | print_string += " Endpoint " + au8Data[5 + i]; 2129 | print_string += "\n"; 2130 | } 2131 | } 2132 | break; 2133 | case 0x8044: 2134 | { 2135 | print_string += " (Power Descriptor Response)"; 2136 | print_string += "\n"; 2137 | print_string += " SQN: 0x" + au8Data[0]; 2138 | print_string += "\n"; 2139 | print_string += " Status: 0x" + au8Data[1]; 2140 | print_string += "\n"; 2141 | print_string += " Power Source Level: "; // + Convert.ToString(au8Data[2] & 0x7, 2).PadLeft(4, '0'); 2142 | print_string += "\n"; 2143 | print_string += " Current Power Source: "; // + Convert.ToString((au8Data[2] >> 4) & 0x7, 2).PadLeft(4, '0'); 2144 | print_string += "\n"; 2145 | print_string += " Available Power Source: "; // + Convert.ToString((au8Data[3]) & 0x7, 2).PadLeft(4, '0'); 2146 | print_string += "\n"; 2147 | print_string += " Current Power Mode: "; // + Convert.ToString((au8Data[3] >> 4) & 0x7, 2).PadLeft(4, '0'); 2148 | print_string += "\n"; 2149 | } 2150 | break; 2151 | 2152 | case 0x8701: 2153 | { 2154 | print_string += " (Route Discovery Confirm)"; 2155 | print_string += "\n"; 2156 | print_string += " SQN: 0x" + String(au8Data[0], HEX); 2157 | print_string += "\n"; 2158 | print_string += " Status: 0x" + String(au8Data[1], HEX); 2159 | print_string += "\n"; 2160 | print_string += " Network Status: 0x" + String(au8Data[2], HEX); 2161 | print_string += "\n"; 2162 | } 2163 | break; 2164 | 2165 | case 0x8702: 2166 | { 2167 | uint16_t u16DestAddr; 2168 | 2169 | u16DestAddr = au8Data[4]; 2170 | u16DestAddr <<= 8; 2171 | u16DestAddr |= au8Data[5]; 2172 | 2173 | print_string += " (APS Data Confirm Fail)"; 2174 | print_string += "\n"; 2175 | print_string += " Status: 0x" + String(au8Data[0], HEX); 2176 | print_string += "\n"; 2177 | print_string += " Source Endpoint: 0x" + String(au8Data[1], HEX); 2178 | print_string += "\n"; 2179 | print_string += " Destination Endpoint: 0x" + String(au8Data[2], HEX); 2180 | print_string += "\n"; 2181 | print_string += " Destination Mode: 0x" + String(au8Data[3], HEX); 2182 | print_string += "\n"; 2183 | print_string += " Destination Address: 0x" + String(u16DestAddr, HEX); 2184 | print_string += "\n"; 2185 | print_string += " SQN: 0x" + String(au8Data[6], HEX); 2186 | print_string += "\n"; 2187 | } 2188 | break; 2189 | 2190 | case 0x8531: 2191 | { 2192 | uint16_t u16AddressOfInterest; 2193 | 2194 | u16AddressOfInterest = au8Data[2]; 2195 | u16AddressOfInterest <<= 8; 2196 | u16AddressOfInterest |= au8Data[3]; 2197 | 2198 | print_string += " (Complex Descriptor Response)"; 2199 | print_string += "\n"; 2200 | print_string += " SQN: 0x" + String(au8Data[0], HEX); 2201 | print_string += "\n"; 2202 | print_string += " Status: 0x" + String(au8Data[1], HEX); 2203 | print_string += "\n"; 2204 | print_string += " Address of Interest: 0x" + String(u16AddressOfInterest, HEX); 2205 | print_string += "\n"; 2206 | print_string += " Length: " + String(au8Data[4], HEX); 2207 | print_string += "\n"; 2208 | 2209 | if (au8Data[1] == 0) 2210 | { 2211 | print_string += " XML Tag: " + au8Data[5]; 2212 | print_string += "\n"; 2213 | print_string += " Field Count: " + au8Data[6]; 2214 | print_string += "\n"; 2215 | print_string += " Complex Description: "; 2216 | for (int i = 0; i < au8Data[6]; i++) 2217 | { 2218 | char c = (char)au8Data[6 + i + 1]; 2219 | print_string += c; 2220 | } 2221 | print_string += "\n"; 2222 | } 2223 | } 2224 | break; 2225 | 2226 | case 0x8532: 2227 | { 2228 | byte u8StrLen; 2229 | uint16_t u16NwkAddr = 0; 2230 | 2231 | u16NwkAddr = au8Data[2]; 2232 | u16NwkAddr <<= 8; 2233 | u16NwkAddr |= au8Data[3]; 2234 | u8StrLen = au8Data[4]; 2235 | 2236 | print_string += " (User Descriptor Request Response)"; 2237 | print_string += "\n"; 2238 | print_string += " SQN: 0x" + au8Data[0]; 2239 | print_string += "\n"; 2240 | print_string += " Status: 0x" + au8Data[1]; 2241 | print_string += "\n"; 2242 | print_string += " Nwk Address: 0x" + u16NwkAddr; 2243 | print_string += "\n"; 2244 | 2245 | if (au8Data[1] == 0) 2246 | { 2247 | print_string += " Length: " + u8StrLen; 2248 | print_string += "\n"; 2249 | print_string += " Descriptor: "; 2250 | 2251 | for (int i = 0; i < u8StrLen; i++) 2252 | { 2253 | char c = (char)au8Data[5 + i]; 2254 | print_string += c; 2255 | } 2256 | print_string += "\n"; 2257 | } 2258 | } 2259 | break; 2260 | 2261 | case 0x8533: 2262 | { 2263 | byte u8StrLen; 2264 | uint16_t u16NwkAddr = 0; 2265 | 2266 | u16NwkAddr = au8Data[2]; 2267 | u16NwkAddr <<= 8; 2268 | u16NwkAddr |= au8Data[3]; 2269 | u8StrLen = au8Data[4]; 2270 | 2271 | print_string += " (User Descriptor Set Confirm)"; 2272 | print_string += "\n"; 2273 | print_string += " SQN: 0x"; 2274 | print_string += au8Data[0]; 2275 | print_string += "\n"; 2276 | print_string += " Status: 0x"; 2277 | print_string += au8Data[1]; 2278 | print_string += "\n"; 2279 | print_string += " Nwk Address: 0x"; 2280 | print_string += u16NwkAddr; 2281 | print_string += "\n"; 2282 | } 2283 | break; 2284 | 2285 | 2286 | default: 2287 | { 2288 | print_string += " (Unrecognized)"; 2289 | print_string += "\n"; 2290 | } 2291 | break; 2292 | } 2293 | Serial.print(print_string); 2294 | print_string = ""; 2295 | } 2296 | -------------------------------------------------------------------------------- /sqlite.ino: -------------------------------------------------------------------------------- 1 | int db_open(const char *filename, sqlite3 **db) { 2 | int rc = sqlite3_open(filename, db); 3 | if (rc) { 4 | Serial.printf("Can't open database: %s\n", sqlite3_errmsg(*db)); 5 | return rc; 6 | } else { 7 | Serial.printf("Opened database successfully\n"); 8 | } 9 | return rc; 10 | } 11 | 12 | const char* data = "Callback function called"; 13 | static int callback(void *data, int argc, char **argv, char **azColName) { 14 | int i; 15 | Serial.printf("%s: ", (const char*)data); 16 | for (i = 0; i 1) { 50 | Serial.println("wsetConfig"); 51 | } 52 | if (spayload == "initDevice") { 53 | Serial.println("INIT Zigbee"); 54 | } 55 | break; 56 | 57 | 58 | 59 | case WStype_BIN: 60 | Serial.printf("[WSc] get binary lenght: %u\n", length); // hexdump(payload,length); 61 | if (payload[0] == 0xfe) { 62 | Serial.println("send_raw_data"); // отправка рав даты в юарт 63 | } 64 | if (payload[0] == 0x01) { 65 | Serial.println("send_cmd_OnOf"); // отправка on_off 66 | sendClusterOnOff(3, 0xdb91, 1, 1, 2); 67 | // send_on_off(BUILD_UINT16(payload[2], payload[1]), payload[3], payload[4]); 68 | } 69 | break; 70 | case WStype_ERROR: break; 71 | case WStype_FRAGMENT_TEXT_START: break; 72 | case WStype_FRAGMENT_BIN_START: break; 73 | case WStype_FRAGMENT: break; 74 | case WStype_FRAGMENT_FIN: break; 75 | default: 76 | break; 77 | 78 | } 79 | } 80 | 81 | 82 | //Generated page 83 | void devicesWebpage(AsyncWebServerRequest * request) { 84 | String sql = "select * from devices"; 85 | rc = sqlite3_prepare_v2(db, sql.c_str(), 1000, &res, &tail); 86 | if (rc != SQLITE_OK) { 87 | String resp = "Failed to fetch data: "; 88 | resp += sqlite3_errmsg(db); 89 | resp += "

back"; 90 | request->send(200, "text/html", resp); 91 | Serial.println(resp.c_str()); 92 | return; 93 | } 94 | rec_count = 0; 95 | String resp = "

List of connected devices:

"; 96 | resp += sql; 97 | resp += "

"; 98 | bool first = true; 99 | while (sqlite3_step(res) == SQLITE_ROW) { 100 | //resp = ""; 101 | if (first) { 102 | int count = sqlite3_column_count(res); 103 | if (count == 0) { 104 | resp += ""; 105 | rec_count = sqlite3_changes(db); 106 | break; 107 | } 108 | resp += ""; 109 | for (int i = 0; i < count; i++) { 110 | resp += ""; 113 | } 114 | resp += ""; 115 | first = false; 116 | } 117 | int count = sqlite3_column_count(res); 118 | resp += ""; 119 | for (int i = 0; i < count; i++) { 120 | resp += ""; 123 | } 124 | resp += ""; 125 | rec_count++; 126 | } 127 | resp += "
Statement executed successfully
"; 111 | resp += sqlite3_column_name(res, i); 112 | resp += "
"; 121 | resp += (const char *) sqlite3_column_text(res, i); 122 | resp += "


Number of records: "; 128 | resp += rec_count; 129 | resp += ".

"; 130 | request->send(200, "text/html", resp); 131 | sqlite3_finalize(res); 132 | } 133 | --------------------------------------------------------------------------------