37 #define MODEM_BAUDRATE 19200 38 #define CONTROL_INFORMATION 0x7A 39 #define END_OF_RESPONSE '>' 40 #define CMD_ENTER_CONFIG (char) 0x00 41 #define CMD_EXIT_CONFIG (char) 0x58 42 #define CMD_EXIT_MEMORY (char) 0xFF 43 #define RX_BUFFER_SIZE 255 44 #define DEFAULT_TIMEOUT 1000 47 #define CMD_CHANNEL 'C' 48 #define CMD_CONTROL_FIELD 'F' 49 #define CMD_MBUS_MODE 'G' 50 #define CMD_INSTALL_MODE 'I' 51 #define CMD_WRITE_MEMORY 'M' 52 #define CMD_RF_POWER 'P' 53 #define CMD_QUALITY 'Q' 55 #define CMD_TEMPERATURE 'U' 56 #define CMD_VOLTAGE 'V' 57 #define CMD_READ_MEMORY 'Y' 61 #define MEM_CHANNEL 0x00 62 #define MEM_RF_POWER 0x01 63 #define MEM_DATA_RATE 0x02 64 #define MEM_MBUS_MODE 0x03 65 #define MEM_SLEEP_MODE 0x04 66 #define MEM_RSSI_MODE 0x05 67 #define MEM_PREAMBLE_LENGTH 0x0A 68 #define MEM_TIMEOUT 0x10 69 #define MEM_NETWORK_ROLE 0x12 70 #define MEM_MAILBOX 0x16 71 #define MEM_MANUFACTURER_ID 0x19 72 #define MEM_UNIQUE_ID 0x1B 73 #define MEM_VERSION 0x1F 74 #define MEM_DEVICE 0x20 75 #define MEM_UART_BAUD_RATE 0x30 76 #define MEM_UART_FLOW_CTRL 0x35 77 #define MEM_DATA_INTERFACE 0x36 78 #define MEM_CONFIG_INTERFACE 0x37 79 #define MEM_FREQ_CAL 0x39 80 #define MEM_LED_CONTROL 0x3A 81 #define MEM_CONTROL_FIELD 0x3B 82 #define MEM_RX_TIMEOUT 0x3C 83 #define MEM_INSTALL_MODE 0x3D 84 #define MEM_ENCRYPT_FLAG 0x3E 85 #define MEM_DECRYPT_FLAG 0x3F 86 #define MEM_DEFAULT_KEY 0x40 87 #define MEM_PART_NUMBER_OLD 0x61 88 #define MEM_SERIAL_NUMBER_OLD 0x71 89 #define MEM_PART_NUMBER_NEW 0x89 90 #define MEM_SERIAL_NUMBER_NEW 0xA9 93 #define MBUS_MODE_S2 0x00 94 #define MBUS_MODE_T1 0x01 95 #define MBUS_MODE_T2 0x02 96 #define MBUS_MODE_S1 0x03 97 #define MBUS_MODE_R 0x04 98 #define MBUS_MODE_T1_C 0x0A 99 #define MBUS_MODE_T2_C 0x0B 100 #define MBUS_MODE_N2 0x10 101 #define MBUS_MODE_N1 0x11 102 #define MBUS_MODE_OSP 0x12 105 #define INSTALL_MODE_NORMAL 0x00 106 #define INSTALL_MODE_INSTALL 0x01 107 #define INSTALL_MODE_HOST 0x02 110 #define SLEEP_MODE_DISABLE 0x00 111 #define SLEEP_MODE_AFTER_TX 0x01 112 #define SLEEP_MODE_AFTER_TX_RX 0x03 113 #define SLEEP_MODE_AFTER_TX_TIMEOUT 0x05 114 #define SLEEP_MODE_AFTER_TX_RX_TIMEOUT 0x07 117 #define NETWORK_ROLE_SLAVE 0x00 118 #define NETWORK_ROLE_MASTER 0x01 119 #define NETWORK_ROLE_REPEATER 0x02 122 #define TIMEOUT_32MS 0x01 123 #define TIMEOUT_48MS 0x02 124 #define TIMEOUT_64MS 0x03 125 #define TIMEOUT_2S 0x7C 126 #define TIMEOUT_4S 0xF9 129 #define LED_CONTROL_DISABLED 0x00 130 #define LED_CONTROL_RX_TX 0x01 131 #define LED_CONTROL_UART_RF_IDLE 0x02 134 #define ENCRYPT_DISABLED 0x00 135 #define ENCRYPT_ENABLED 0x01 136 #define ENCRYPT_ENABLED_CRC 0x03 139 #define DATA_INTERFACE_ID_ADDR 0x00 140 #define DATA_INTERFACE_APP_ONLY 0x01 141 #define DATA_INTERFACE_APP_ACK 0x03 142 #define DATA_INTERFACE_START_STOP 0x04 143 #define DATA_INTERFACE_CRC 0x08 144 #define DATA_INTERFACE_CRC_START_STOP 0x0C 148 #define PREAMBLE_FORMAT_A 0x00 149 #define PREAMBLE_FORMAT_B 0x02 167 Allwize(Stream & stream, uint8_t reset_gpio = 0xFF);
175 void dump(Stream & debug);
177 bool send(uint8_t * buffer, uint8_t len);
178 bool send(
const char * buffer);
189 void setChannel(uint8_t channel,
bool persist =
false);
190 void setPower(uint8_t power,
bool persist =
false);
192 void setMode(uint8_t mode,
bool persist =
false);
238 int8_t
_sendCommand(uint8_t command, uint8_t * data, uint8_t len);
241 bool _setMemory(uint8_t address, uint8_t * data, uint8_t len);
242 bool _setMemory(uint8_t address, uint8_t data);
243 uint8_t
_getMemory(uint8_t address, uint8_t * buffer, uint8_t len);
252 uint8_t
_send(uint8_t * buffer, uint8_t len);
253 uint8_t
_send(uint8_t ch);
261 void _hex2bin(
char * hex, uint8_t * bin, uint8_t len);
262 void _bin2hex(uint8_t * bin,
char * hex, uint8_t len);
272 uint8_t _reset_gpio = 0xFF;
273 bool _config =
false;
274 uint32_t _timeout = DEFAULT_TIMEOUT;
275 uint8_t _ci = CONTROL_INFORMATION;
283 uint8_t _buffer[RX_BUFFER_SIZE];
String getFirmwareVersion()
Returns the module firmware revision.
void _flush()
Flushes the serial line to the module.
uint8_t getControlInformation()
Gets the control information byte.
int8_t _sendCommand(uint8_t command, uint8_t *data, uint8_t len)
Sends a command with the given data.
uint8_t _getMemory(uint8_t address, uint8_t *buffer, uint8_t len)
Returns the contents of consecutive memory addresses.
void setChannel(uint8_t channel, bool persist=false)
Sets the communications channel (for MBUS_MODE_R2 only)
void setDataRate(uint8_t dr)
Sets the data rate.
void setSleepMode(uint8_t mode)
Sets the sleep mode.
void slave()
Sets the module in slave mode.
void setEncryptFlag(uint8_t flag)
Sets the encrypt flag setting.
bool factoryReset()
Resets the module to factory settings You must reset the serial connection after the factoryReset: Se...
uint8_t getPreamble()
Gets the preamble length frame format.
void _readModel()
Reads and caches the module model & version.
void setInstallMode(uint8_t mode, bool persist=false)
Sets the module in one of the available operations modes.
int _readBytes(char *buffer, uint16_t len)
Reads the stream buffer up to a number of bytes.
String getMID()
Returns the Manufacturer ID string.
String getUID()
Returns the Unique ID string.
void repeater()
Sets the module in repeater mode.
void master()
Sets the module in master mode.
allwize_message_t read()
Returns latest received message.
void setDecryptFlag(uint8_t flag)
Sets the decrypt flag setting.
int _readBytesUntil(char terminator, char *buffer, uint16_t len)
Reads the stream buffer up to a certain char or times out.
void dump(Stream &debug)
Dumps the current memory configuration to the given stream.
String _getMemoryAsString(uint8_t address, uint8_t len)
Returns the contents of the memory from a certain address as a String object.
bool available()
Returns true if a new message has been received and decoded This method has to be called in the main ...
void _bin2hex(uint8_t *bin, char *hex, uint8_t len)
Converts a binary buffer to an hex c-string.
void getDefaultKey(uint8_t *key)
Gets the default encryption key.
void setControlInformation(uint8_t ci)
Sets the control information byte.
void setTimeout(uint8_t timeout)
Sets the timeout for auto sleep modes.
bool ready()
Test whether the radio module is ready or not.
bool _decode()
Decodes the current RX buffer contents.
int _timedRead()
Reads a byte from the stream with a timeout.
uint8_t getInstallMode()
Gets the install modevalue stored in non-volatile memory.
uint8_t getNetworkRole()
Gets the current network role.
uint8_t getSleepMode()
Gets the sleep mode stored in non-volatile memory.
void setControlField(uint8_t value, bool persist=false)
Sets the data interface for receiving packets.
uint8_t getDataRate()
Gets the data rate stored in non-volatile memory.
uint8_t getTemperature()
Returns the RSSI of the last valid packet received TODO: values do not seem right and are not the sam...
uint8_t getChannel()
Gets the channel stored in non-volatile memory.
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 ...
void setPower(uint8_t power, bool persist=false)
Sets the RF power.
uint8_t getLEDControl()
Gets the current LED control.
void setMode(uint8_t mode, bool persist=false)
Sets the module in one of the available MBus modes.
uint8_t _send(uint8_t *buffer, uint8_t len)
Sends a binary buffer to the module UART. Returns the number of bytes actually sent.
bool reset()
Resets the radio module. You must reset the serial connection after the reset: Serial1.end(); Serial1.begin(19200); delay(200);.
uint8_t getDevice()
Returns the device version from non-volatile memory.
uint8_t getEncryptFlag()
Gets the encrypt flag setting.
bool send(uint8_t *buffer, uint8_t len)
Sends a byte array.
void begin()
Inits the module communications.
uint8_t getMode()
Gets the MBus mode stored in non-volatile memory.
uint8_t getVersion()
Returns the module version from non-volatile memory.
String getPartNumber()
Returns the module part number.
void setDefaultKey(uint8_t *key)
Sets the default encryption key.
void wakeup()
Wakes up the radio from sleep mode.
void _hex2bin(char *hex, uint8_t *bin, uint8_t len)
Converts a hex c-string to a binary buffer.
void setPreamble(uint8_t preamble)
Sets the RSSI mode value.
void sleep()
Sets the radio module in sleep mode.
bool _setConfig(bool value)
Sets or unsets config mode.
uint16_t getVoltage()
Returns the internal voltage of the module.
uint8_t getTimeout()
Gets the current timeout for auto sleep modes.
void setNetworkRole(uint8_t role)
Sets the network role.
int8_t _receive()
Listens to incomming data from the module until timeout or END_OF_RESPONSE. Returns the number of byt...
String _getMemoryAsHexString(uint8_t address, uint8_t len)
Returns the contents of the memory from a certain address as an HEX String.
uint8_t getDecryptFlag()
Gets the decrypt flag setting.
Allwize(Stream &stream, uint8_t reset_gpio=0xFF)
Allwize object constructor.
String getSerialNumber()
Returns the module serial number.
void setLEDControl(uint8_t value)
Sets the LED control.
bool _setMemory(uint8_t address, uint8_t *data, uint8_t len)
Sets non-volatile memory contents starting from given address.
uint8_t getPower()
Gets the RF power stored in non-volatile memory.
uint8_t getControlField()
Gets the control field value stored in non-volatile memory.
String getRequiredHardwareVersion()
Returns the module hardware revision.