Allwize Library
Allwize.cpp
1 /*
2 
3 Allwize 0.0.1
4 
5 Copyright (C) 2018 by Allwize <github@allwize.io>
6 
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 
20 */
21 
22 #include "Allwize.h"
23 
24 // -----------------------------------------------------------------------------
25 // Init
26 // -----------------------------------------------------------------------------
27 
33 Allwize::Allwize(Stream& stream, uint8_t reset_gpio) : _stream(stream), _reset_gpio(reset_gpio) {
34  if (0xFF != _reset_gpio) {
35  pinMode(_reset_gpio, OUTPUT);
36  digitalWrite(_reset_gpio, HIGH);
37  }
38 }
39 
44  _stream.flush();
45  delay(200);
46 }
47 
57  if (0xFF == _reset_gpio) {
58  _setMemory(MEM_CONFIG_INTERFACE, 1);
59  if (_setConfig(true)) {
60  _send('@');
61  _send('R');
62  _send('R');
63  _flush();
64  delay(100);
65  _config = false;
66  return true;
67  }
68  } else {
69  digitalWrite(_reset_gpio, LOW);
70  delay(1);
71  digitalWrite(_reset_gpio, HIGH);
72  delay(100);
73  _config = false;
74  return true;
75  }
76  return false;
77 }
78 
88  _setMemory(MEM_CONFIG_INTERFACE, 1);
89  if (_setConfig(true)) {
90  _send('@');
91  _send('R');
92  _send('C');
93  _flush();
94  delay(100);
95  _config = false;
96  return true;
97  }
98  return false;
99 }
100 
105  setMode(MBUS_MODE_OSP, true);
106  setNetworkRole(NETWORK_ROLE_MASTER);
107  setInstallMode(INSTALL_MODE_HOST);
108  setSleepMode(SLEEP_MODE_DISABLE);
109  _setMemory(MEM_RSSI_MODE, 1);
110  _setMemory(MEM_DATA_INTERFACE, DATA_INTERFACE_START_STOP);
111 }
112 
117  setMode(MBUS_MODE_OSP, true);
118  setNetworkRole(NETWORK_ROLE_SLAVE);
119 }
120 
125  setMode(MBUS_MODE_OSP, true);
126  setNetworkRole(NETWORK_ROLE_REPEATER);
127 }
128 
133  _sendCommand(CMD_SLEEP);
134 }
135 
140  _sendAndReceive(CMD_EXIT_CONFIG);
141 }
142 
147  //uint8_t channel = getChannel();
148  //return (0 < channel && channel < 42);
149  bool response = _setConfig(true);
150  if (response) _setConfig(false);
151  return response;
152 }
153 
158 void Allwize::dump(Stream & debug) {
159 
160  _setConfig(true);
161  _send('0');
162 
163  char buffer[256];
164  if (256 == _readBytes(buffer, 256)) {
165 
166  char ch[10];
167  char ascii[17] = {0};
168  ascii[16] = 0;
169 
170  debug.println();
171  debug.print(" ");
172  for (uint16_t address = 0; address <= 0x0F; address++) {
173  snprintf(ch, sizeof(ch), "%02X ", address);
174  debug.print(ch);
175  }
176  debug.println();
177  debug.print("------------------------------------------------------");
178 
179  for (uint16_t address = 0; address <= 255; address++) {
180  if ((address % 16) == 0) {
181  if (address > 0) debug.print(ascii);
182  snprintf(ch, sizeof(ch), "\n0x%02X: ", address);
183  debug.print(ch);
184  }
185  if (31 < buffer[address] && buffer[address] < 127) {
186  ascii[address % 16] = (char) buffer[address];
187  } else {
188  ascii[address % 16] = ' ';
189  }
190  snprintf(ch, sizeof(ch), "%02X ", (uint8_t) buffer[address]);
191  debug.print(ch);
192  }
193 
194  debug.println();
195  debug.println();
196 
197  } else {
198  debug.println("Error doing memory dump...");
199  }
200 
201  _setConfig(false);
202 
203 }
204 
211 bool Allwize::send(uint8_t * buffer, uint8_t len) {
212  if (_config) return false;
213  if (0 == len) return (1 == _send(0xFE));
214  if (1 != _send(len+1)) return false;
215  if (1 != _send(_ci)) return false;
216  if (len != _send(buffer, len)) return false;
217  return true;
218 }
219 
225 bool Allwize::send(const char * buffer) {
226  return send((uint8_t *) buffer, strlen(buffer));
227 }
228 
235 
236  bool response = false;
237 
238  if (!_config) {
239 
240  static uint32_t when = millis();
241 
242  while (_stream.available()) {
243  uint8_t ch = _stream.read();
244  _buffer[_pointer++] = ch;
245  when = millis();
246  #if defined(ARDUINO_ARCH_ESP8266)
247  yield();
248  #endif
249  }
250 
251  // Check if message finished and decode it
252  if ((_pointer > 0) && (millis() - when > 100)) {
253  response = _decode();
254  _pointer = 0;
255  }
256 
257  }
258 
259  return response;
260 
261 }
262 
268  return _message;
269 }
270 
271 // -----------------------------------------------------------------------------
272 // Configuration
273 // -----------------------------------------------------------------------------
274 
280  _ci = ci;
281 }
282 
288  return _ci;
289 }
290 
296 void Allwize::setChannel(uint8_t channel, bool persist) {
297  if (persist) _setMemory(MEM_CHANNEL, channel);
298  _sendCommand(CMD_CHANNEL, channel);
299 }
300 
306  return _getMemory(MEM_CHANNEL);
307 }
308 
314 void Allwize::setPower(uint8_t power, bool persist) {
315  if (0 < power && power < 6) {
316  if (persist) _setMemory(MEM_RF_POWER, power);
317  _sendCommand(CMD_RF_POWER, power);
318  }
319 }
320 
325 uint8_t Allwize::getPower() {
326  return _getMemory(MEM_RF_POWER);
327 }
328 
333 void Allwize::setDataRate(uint8_t dr) {
334  if (0 < dr && dr < 6 && dr != 3) {
335  _setMemory(MEM_DATA_RATE, dr);
336  }
337 }
338 
344  return _getMemory(MEM_DATA_RATE);
345 }
346 
352 void Allwize::setMode(uint8_t mode, bool persist) {
353  if (persist) _setMemory(MEM_MBUS_MODE, mode);
354  _sendCommand(CMD_MBUS_MODE, mode);
355 }
356 
361 uint8_t Allwize::getMode() {
362  return _getMemory(MEM_MBUS_MODE);
363 }
364 
369 void Allwize::setSleepMode(uint8_t mode) {
370  _setMemory(MEM_SLEEP_MODE, mode);
371 }
372 
378  return _getMemory(MEM_SLEEP_MODE);
379 }
380 
385 //void Allwize::setAppendRSSI(bool value) {
386 // _setMemory(MEM_RSSI_MODE, value ? 1 : 0);
387 //}
388 
393 //bool Allwize::getAppendRSSI() {
394 // return (_getMemory(MEM_RSSI_MODE) == 0x01);
395 //}
396 
401 void Allwize::setPreamble(uint8_t preamble) {
402  if (PREAMBLE_FORMAT_A == preamble || PREAMBLE_FORMAT_B == preamble) {
403  _setMemory(MEM_PREAMBLE_LENGTH, preamble);
404  }
405 }
406 
412  return _getMemory(MEM_PREAMBLE_LENGTH);
413 }
414 
419 void Allwize::setTimeout(uint8_t timeout) {
420  _setMemory(MEM_TIMEOUT, timeout);
421 }
422 
428  return _getMemory(MEM_TIMEOUT);
429 }
430 
435 void Allwize::setNetworkRole(uint8_t role) {
436  _setMemory(MEM_NETWORK_ROLE, role);
437 }
438 
444  return _getMemory(MEM_NETWORK_ROLE);
445 }
446 
451 void Allwize::setLEDControl(uint8_t value) {
452  _setMemory(MEM_LED_CONTROL, value);
453 }
454 
460  return _getMemory(MEM_LED_CONTROL);
461 }
462 
467 //void Allwize::setDataInterface(uint8_t value) {
468 // if (0 <= value && value <= 0x0C) {
469 // _setMemory(MEM_DATA_INTERFACE, value);
470 // }
471 //}
472 
477 //uint8_t Allwize::getDataInterface() {
478 // return _getMemory(MEM_DATA_INTERFACE);
479 //}
480 
486 void Allwize::setControlField(uint8_t value, bool persist) {
487  if (persist) _setMemory(MEM_CONTROL_FIELD, value);
488  _sendCommand(CMD_CONTROL_FIELD, value);
489 }
490 
496  return _getMemory(MEM_CONTROL_FIELD);
497 }
498 
504 void Allwize::setInstallMode(uint8_t mode, bool persist) {
505  if (persist) _setMemory(MEM_INSTALL_MODE, mode);
506  _sendCommand(CMD_INSTALL_MODE, mode);
507 }
508 
514  return _getMemory(MEM_INSTALL_MODE);
515 }
516 
521 void Allwize::setEncryptFlag(uint8_t flag) {
522  _setMemory(MEM_ENCRYPT_FLAG, flag);
523 }
524 
530  return _getMemory(MEM_ENCRYPT_FLAG);
531 }
532 
537 void Allwize::setDecryptFlag(uint8_t flag) {
538  _setMemory(MEM_DECRYPT_FLAG, flag);
539 }
540 
546  return _getMemory(MEM_DECRYPT_FLAG);
547 }
548 
553 void Allwize::setDefaultKey(uint8_t * key) {
554  _setMemory(MEM_DEFAULT_KEY, key, 16);
555 }
556 
561 void Allwize::getDefaultKey(uint8_t * key) {
562  _getMemory(MEM_DEFAULT_KEY, key, 16);
563 }
564 
565 // -----------------------------------------------------------------------------
566 
572 /*
573 float Allwize::getRSSI() {
574  uint8_t response = _sendCommand(CMD_RSSI);
575  if (response > 0) return -0.5 * _buffer[0];
576  return 0;
577 }
578 */
579 
585  uint8_t response = _sendCommand(CMD_TEMPERATURE);
586  if (response > 0) return (_buffer[0] - 128);
587  return 0;
588 }
589 
595  uint8_t response = _sendCommand(CMD_VOLTAGE);
596  if (response > 0) return 30 * _buffer[0];
597  return 0;
598 }
599 
604 String Allwize::getMID() {
605  return _getMemoryAsHexString(MEM_MANUFACTURER_ID, 2);
606 }
607 
612 String Allwize::getUID() {
613  return _getMemoryAsHexString(MEM_UNIQUE_ID, 4);
614 }
615 
621  return _getMemory(MEM_VERSION);
622 }
623 
629  return _getMemory(MEM_DEVICE);
630 }
631 
637  _readModel();
638  return _model;
639 }
640 
646  _readModel();
647  return _hw;
648 }
649 
655  _readModel();
656  return _fw;
657 }
658 
664  return _getMemoryAsHexString(MEM_SERIAL_NUMBER_NEW, 8);
665 }
666 
667 // -----------------------------------------------------------------------------
668 // Protected
669 // -----------------------------------------------------------------------------
670 
677 bool Allwize::_setConfig(bool value) {
678  if (value != _config) {
679  _flush();
680  if (value) {
681  if (_sendAndReceive(CMD_ENTER_CONFIG) == 0) {
682  _config = true;
683  delay(2);
684  }
685  } else {
686  _send(CMD_EXIT_CONFIG);
687  _config = false;
688  delay(10);
689  }
690  }
691  return _config;
692 }
693 
701 int8_t Allwize::_sendCommand(uint8_t command, uint8_t * data, uint8_t len) {
702  int8_t response = -1;
703  if (!_setConfig(true)) return response;
704  if (_sendAndReceive(command) != -1) {
705  response = _sendAndReceive(data, len);
706  }
707  _setConfig(false);
708  return response;
709 }
710 
718 int8_t Allwize::_sendCommand(uint8_t command, uint8_t data) {
719  int8_t response = -1;
720  if (!_setConfig(true)) return response;
721  if (_sendAndReceive(command) != -1) {
722  response = _sendAndReceive(data);
723  }
724  _setConfig(false);
725  return response;
726 }
727 
734 int8_t Allwize::_sendCommand(uint8_t command) {
735  int8_t response = -1;
736  if (!_setConfig(true)) return response;
737  response = _sendAndReceive(command);
738  _setConfig(false);
739  return response;
740 }
741 
750 bool Allwize::_setMemory(uint8_t address, uint8_t * data, uint8_t len) {
751  uint8_t buffer[len*2+1];
752  for (uint8_t i=0; i<len; i++) {
753  buffer[i*2] = address + i;
754  buffer[i*2+1] = data[i];
755  }
756  buffer[len*2] = CMD_EXIT_MEMORY;
757  return (_sendCommand(CMD_WRITE_MEMORY, buffer, len*2+1) != -1);
758 }
759 
767 bool Allwize::_setMemory(uint8_t address, uint8_t value) {
768  uint8_t buffer[3] = {address, value, CMD_EXIT_MEMORY};
769  return (_sendCommand(CMD_WRITE_MEMORY, buffer, 3) != -1);
770 }
771 
780 uint8_t Allwize::_getMemory(uint8_t address, uint8_t * buffer, uint8_t len) {
781  uint8_t count = 0;
782  if (_setConfig(true)) {
783  for (uint8_t i=0; i<len; i++) {
784  if (_sendAndReceive(CMD_READ_MEMORY) == -1) break;
785  if (_sendAndReceive(address + i) != 1) break;
786  count++;
787  buffer[i] = _buffer[0];
788  }
789  _setConfig(false);
790  }
791  return count;
792 }
793 
800 uint8_t Allwize::_getMemory(uint8_t address) {
801  uint8_t response = _sendCommand(CMD_READ_MEMORY, address);
802  if (response > 0) return _buffer[0];
803  return 0;
804 }
805 
813 String Allwize::_getMemoryAsHexString(uint8_t address, uint8_t len) {
814  uint8_t bin[len];
815  char hex[2*len+1];
816  hex[0] = 0;
817  if (len == _getMemory(address, bin, len)) {
818  _bin2hex(bin, hex, len);
819  }
820  return String(hex);
821 }
822 
830 String Allwize::_getMemoryAsString(uint8_t address, uint8_t len) {
831  uint8_t bin[len];
832  char hex[len+1];
833  hex[0] = 0;
834  if (len == _getMemory(address, bin, len)) {
835  memcpy(hex, bin, len);
836  hex[len-1] = 0;
837  }
838  return String(hex);
839 }
840 
845 
846  if (_model.length() > 0) return;
847  String line = _getMemoryAsString(MEM_PART_NUMBER_NEW, 32);
848  if (line.indexOf("RC") != 0) String line = _getMemoryAsString(MEM_PART_NUMBER_OLD, 32);
849 
850  if (line.indexOf("RC") != 0) {
851  _model = String("Unknown");
852 
853  } else {
854 
855  uint8_t start = 0;
856  uint8_t end = line.indexOf(",", start);
857  _model = line.substring(start, end);
858 
859  start = end + 1;
860  end = line.indexOf(",", start);
861  _hw = line.substring(start, end);
862 
863  start = end + 1;
864  end = line.indexOf(",", start);
865  _fw = line.substring(start, end);
866  _fw.trim();
867 
868  }
869 
870 }
871 
893 
894  // Get and check buffer length
895  uint8_t len = _buffer[1];
896  if (_pointer != len+3) return false;
897 
898  // C-field
899  _message.c = 0xFF;
900 
901  // Control information
902  _message.ci = _buffer[2];
903 
904  // Application data
905  _message.len = len - 2;
906  if (_message.data) delete[] _message.data;
907  _message.data = new uint8_t[_message.len + 1];
908  memcpy(_message.data, &_buffer[3], _message.len);
909  _message.data[_message.len] = 0;
910 
911  // RSSI
912  _message.rssi = _buffer[_pointer-2];
913 
914  return true;
915 
916 }
917 
918 // -----------------------------------------------------------------------------
919 
925  _stream.flush();
926 }
927 
934 uint8_t Allwize::_send(uint8_t ch) {
935  return _stream.write(ch);
936 }
937 
945 uint8_t Allwize::_send(uint8_t * buffer, uint8_t len) {
946  uint8_t n = 0;
947  for (uint8_t i=0; i<len; i++) {
948  if (_send(buffer[i])) n++;
949  }
950  return n;
951 }
952 
959  return _readBytesUntil(END_OF_RESPONSE, (char*) _buffer, RX_BUFFER_SIZE);
960 }
961 
969 int8_t Allwize::_sendAndReceive(uint8_t * buffer, uint8_t len) {
970  if (_send(buffer, len) != len) return -1;
971  return _receive();
972 }
973 
980 int8_t Allwize::_sendAndReceive(uint8_t ch) {
981  if (_send(ch) != 1) return -1;
982  return _receive();
983 }
984 
985 // -----------------------------------------------------------------------------
986 // Utils
987 // -----------------------------------------------------------------------------
988 
995  uint32_t _start = millis();
996  while (millis() - _start < _timeout) {
997  int ch = _stream.read();
998  if (ch >= 0) return ch;
999  #if defined(ARDUINO_ARCH_ESP8266)
1000  yield();
1001  #endif
1002  };
1003  return -1;
1004 }
1005 
1013 int Allwize::_readBytes(char * buffer, uint16_t len) {
1014  if (len < 1) return 0;
1015  uint16_t index = 0;
1016  while (index < len) {
1017  int ch = _timedRead();
1018  if (ch < 0) break;
1019  *buffer++ = (char) ch;
1020  index++;
1021  }
1022  return index;
1023 }
1024 
1033 int Allwize::_readBytesUntil(char terminator, char * buffer, uint16_t len) {
1034  if (len < 1) return 0;
1035  uint16_t index = 0;
1036  while (index < len) {
1037  int ch = _timedRead();
1038  if (ch < 0) break;
1039  if (ch == terminator) break;
1040  *buffer++ = (char) ch;
1041  index++;
1042  }
1043  return index;
1044 }
1045 
1053 void Allwize::_hex2bin(char * hex, uint8_t * bin, uint8_t len) {
1054  for (uint8_t i=0; i<len; i+=2) {
1055  bin[i/2] = ((hex[i] - '0') * 16 + (hex[i+1] - '0')) & 0xFF;
1056  }
1057 }
1058 
1066 void Allwize::_bin2hex(uint8_t * bin, char * hex, uint8_t len) {
1067  for (uint8_t i=0; i<len; i++) {
1068  sprintf(&hex[i*2], "%02X", bin[i]);
1069  }
1070 }
String getFirmwareVersion()
Returns the module firmware revision.
Definition: Allwize.cpp:654
void _flush()
Flushes the serial line to the module.
Definition: Allwize.cpp:924
uint8_t getControlInformation()
Gets the control information byte.
Definition: Allwize.cpp:287
int8_t _sendCommand(uint8_t command, uint8_t *data, uint8_t len)
Sends a command with the given data.
Definition: Allwize.cpp:701
uint8_t _getMemory(uint8_t address, uint8_t *buffer, uint8_t len)
Returns the contents of consecutive memory addresses.
Definition: Allwize.cpp:780
void setChannel(uint8_t channel, bool persist=false)
Sets the communications channel (for MBUS_MODE_R2 only)
Definition: Allwize.cpp:296
void setDataRate(uint8_t dr)
Sets the data rate.
Definition: Allwize.cpp:333
void setSleepMode(uint8_t mode)
Sets the sleep mode.
Definition: Allwize.cpp:369
void slave()
Sets the module in slave mode.
Definition: Allwize.cpp:116
void setEncryptFlag(uint8_t flag)
Sets the encrypt flag setting.
Definition: Allwize.cpp:521
bool factoryReset()
Resets the module to factory settings You must reset the serial connection after the factoryReset: Se...
Definition: Allwize.cpp:87
uint8_t getPreamble()
Gets the preamble length frame format.
Definition: Allwize.cpp:411
void _readModel()
Reads and caches the module model & version.
Definition: Allwize.cpp:844
void setInstallMode(uint8_t mode, bool persist=false)
Sets the module in one of the available operations modes.
Definition: Allwize.cpp:504
int _readBytes(char *buffer, uint16_t len)
Reads the stream buffer up to a number of bytes.
Definition: Allwize.cpp:1013
String getMID()
Returns the Manufacturer ID string.
Definition: Allwize.cpp:604
String getUID()
Returns the Unique ID string.
Definition: Allwize.cpp:612
void repeater()
Sets the module in repeater mode.
Definition: Allwize.cpp:124
void master()
Sets the module in master mode.
Definition: Allwize.cpp:104
allwize_message_t read()
Returns latest received message.
Definition: Allwize.cpp:267
void setDecryptFlag(uint8_t flag)
Sets the decrypt flag setting.
Definition: Allwize.cpp:537
int _readBytesUntil(char terminator, char *buffer, uint16_t len)
Reads the stream buffer up to a certain char or times out.
Definition: Allwize.cpp:1033
void dump(Stream &debug)
Dumps the current memory configuration to the given stream.
Definition: Allwize.cpp:158
String _getMemoryAsString(uint8_t address, uint8_t len)
Returns the contents of the memory from a certain address as a String object.
Definition: Allwize.cpp:830
bool available()
Returns true if a new message has been received and decoded This method has to be called in the main ...
Definition: Allwize.cpp:234
void _bin2hex(uint8_t *bin, char *hex, uint8_t len)
Converts a binary buffer to an hex c-string.
Definition: Allwize.cpp:1066
void getDefaultKey(uint8_t *key)
Gets the default encryption key.
Definition: Allwize.cpp:561
void setControlInformation(uint8_t ci)
Sets the control information byte.
Definition: Allwize.cpp:279
void setTimeout(uint8_t timeout)
Sets the timeout for auto sleep modes.
Definition: Allwize.cpp:419
bool ready()
Test whether the radio module is ready or not.
Definition: Allwize.cpp:146
bool _decode()
Decodes the current RX buffer contents.
Definition: Allwize.cpp:892
int _timedRead()
Reads a byte from the stream with a timeout.
Definition: Allwize.cpp:994
uint8_t getInstallMode()
Gets the install modevalue stored in non-volatile memory.
Definition: Allwize.cpp:513
uint8_t getNetworkRole()
Gets the current network role.
Definition: Allwize.cpp:443
uint8_t getSleepMode()
Gets the sleep mode stored in non-volatile memory.
Definition: Allwize.cpp:377
void setControlField(uint8_t value, bool persist=false)
Sets the data interface for receiving packets.
Definition: Allwize.cpp:486
uint8_t getDataRate()
Gets the data rate stored in non-volatile memory.
Definition: Allwize.cpp:343
uint8_t getTemperature()
Returns the RSSI of the last valid packet received TODO: values do not seem right and are not the sam...
Definition: Allwize.cpp:584
uint8_t getChannel()
Gets the channel stored in non-volatile memory.
Definition: Allwize.cpp:305
int8_t _sendAndReceive(uint8_t *buffer, uint8_t len)
Sends a binary buffer and waits for response. Returns the number of bytes received and stored in the ...
Definition: Allwize.cpp:969
void setPower(uint8_t power, bool persist=false)
Sets the RF power.
Definition: Allwize.cpp:314
uint8_t getLEDControl()
Gets the current LED control.
Definition: Allwize.cpp:459
void setMode(uint8_t mode, bool persist=false)
Sets the module in one of the available MBus modes.
Definition: Allwize.cpp:352
uint8_t _send(uint8_t *buffer, uint8_t len)
Sends a binary buffer to the module UART. Returns the number of bytes actually sent.
Definition: Allwize.cpp:945
bool reset()
Resets the radio module. You must reset the serial connection after the reset: Serial1.end(); Serial1.begin(19200); delay(200);.
Definition: Allwize.cpp:56
uint8_t getDevice()
Returns the device version from non-volatile memory.
Definition: Allwize.cpp:628
uint8_t getEncryptFlag()
Gets the encrypt flag setting.
Definition: Allwize.cpp:529
bool send(uint8_t *buffer, uint8_t len)
Sends a byte array.
Definition: Allwize.cpp:211
void begin()
Inits the module communications.
Definition: Allwize.cpp:43
uint8_t getMode()
Gets the MBus mode stored in non-volatile memory.
Definition: Allwize.cpp:361
uint8_t getVersion()
Returns the module version from non-volatile memory.
Definition: Allwize.cpp:620
String getPartNumber()
Returns the module part number.
Definition: Allwize.cpp:636
void setDefaultKey(uint8_t *key)
Sets the default encryption key.
Definition: Allwize.cpp:553
void wakeup()
Wakes up the radio from sleep mode.
Definition: Allwize.cpp:139
void _hex2bin(char *hex, uint8_t *bin, uint8_t len)
Converts a hex c-string to a binary buffer.
Definition: Allwize.cpp:1053
void setPreamble(uint8_t preamble)
Sets the RSSI mode value.
Definition: Allwize.cpp:401
void sleep()
Sets the radio module in sleep mode.
Definition: Allwize.cpp:132
bool _setConfig(bool value)
Sets or unsets config mode.
Definition: Allwize.cpp:677
uint16_t getVoltage()
Returns the internal voltage of the module.
Definition: Allwize.cpp:594
uint8_t getTimeout()
Gets the current timeout for auto sleep modes.
Definition: Allwize.cpp:427
void setNetworkRole(uint8_t role)
Sets the network role.
Definition: Allwize.cpp:435
int8_t _receive()
Listens to incomming data from the module until timeout or END_OF_RESPONSE. Returns the number of byt...
Definition: Allwize.cpp:958
String _getMemoryAsHexString(uint8_t address, uint8_t len)
Returns the contents of the memory from a certain address as an HEX String.
Definition: Allwize.cpp:813
uint8_t getDecryptFlag()
Gets the decrypt flag setting.
Definition: Allwize.cpp:545
Allwize(Stream &stream, uint8_t reset_gpio=0xFF)
Allwize object constructor.
Definition: Allwize.cpp:33
String getSerialNumber()
Returns the module serial number.
Definition: Allwize.cpp:663
void setLEDControl(uint8_t value)
Sets the LED control.
Definition: Allwize.cpp:451
bool _setMemory(uint8_t address, uint8_t *data, uint8_t len)
Sets non-volatile memory contents starting from given address.
Definition: Allwize.cpp:750
uint8_t getPower()
Gets the RF power stored in non-volatile memory.
Definition: Allwize.cpp:325
uint8_t getControlField()
Gets the control field value stored in non-volatile memory.
Definition: Allwize.cpp:495
String getRequiredHardwareVersion()
Returns the module hardware revision.
Definition: Allwize.cpp:645