Go to the documentation of this file.
34 #if not defined(ARDUINO_ARCH_SAMD) && not defined(ARDUINO_ARCH_ESP32)
35 #include <SoftwareSerial.h>
43 #define MODEM_DEFAULT_BAUDRATE BAUDRATE_19200
44 #define GPIO_NONE 0x99
45 #define RX_BUFFER_SIZE 255
46 #define DEFAULT_TIMEOUT 100
47 #define HARDWARE_SERIAL_PORT 1
48 #define DEFAULT_MBUS_MODE MBUS_MODE_N1
50 #ifndef USE_MEMORY_CACHE
51 #define USE_MEMORY_CACHE 1
79 #if defined(ALLWIZE_DEBUG_PORT)
80 #define ALLWIZE_DEBUG_PRINT(...) ALLWIZE_DEBUG_PORT.print(__VA_ARGS__)
81 #define ALLWIZE_DEBUG_PRINTLN(...) ALLWIZE_DEBUG_PORT.println(__VA_ARGS__)
83 #define ALLWIZE_DEBUG_PRINT(...)
84 #define ALLWIZE_DEBUG_PRINTLN(...)
96 #if not defined(ARDUINO_ARCH_SAMD) && not defined(ARDUINO_ARCH_ESP32)
109 void dump(Stream & debug);
112 bool send(uint8_t * buffer, uint8_t len);
113 bool send(
const char * buffer);
127 void setChannel(uint8_t channel,
bool persist =
false);
128 void setPower(uint8_t power,
bool persist =
false);
130 void setMode(uint8_t mode,
bool persist =
false);
143 void setKey(uint8_t reg,
const uint8_t * key);
172 bool setMID(uint16_t mid);
174 bool setUID(uint32_t uid);
202 int8_t
_sendCommand(uint8_t command, uint8_t * data, uint8_t len);
208 uint8_t
_getMemory(uint8_t address, uint8_t *buffer, uint8_t len);
209 bool _setMemory(uint8_t address, uint8_t data);
210 bool _setMemory(uint8_t address, uint8_t * data, uint8_t len);
212 bool _setSlot(uint8_t slot, uint8_t data);
213 bool _setSlot(uint8_t slot, uint8_t * data, uint8_t len);
215 uint8_t
_getSlot(uint8_t slot, uint8_t * buffer, uint8_t len);
224 uint8_t
_send(uint8_t * buffer, uint8_t len);
225 uint8_t
_send(uint8_t ch);
233 void _hex2bin(
char * hex, uint8_t * bin, uint8_t len);
234 void _bin2hex(uint8_t * bin,
char * hex, uint8_t len);
249 #if defined(ARDUINO_ARCH_SAMD)
251 #elif defined(ARDUINO_ARCH_ESP32)
uint8_t getMode()
Gets the MBus mode stored in non-volatile memory.
bool _setMemory(uint8_t address, uint8_t data)
Sets non-volatile memory contents starting from given address.
uint8_t getVersion()
Returns the device version from non-volatile memory.
void setDevice(uint8_t type)
Sets the device type.
void setWizeApplication(uint8_t wize_application)
Sets the wize applicaton field in the transpoprt layer.
void slave()
Sets the module in slave mode.
bool waitForReady(uint32_t timeout=DEFAULT_TIMEOUT)
Waits for timeout millis for the module to be ready.
void setAccessNumber(uint8_t value)
Sets new/specific access number.
SoftwareSerial * _sw_serial
void setMAC2CheckOnlyFlag(uint8_t flag)
Sets the MAC 2 Check Only flag setting.
void dump(Stream &debug)
Dumps the current memory configuration to the given stream.
bool _setSlot(uint8_t slot, uint8_t data)
Sets non-volatile memory contents starting from given address.
String getSerialNumber()
Returns the module serial number.
#define MODEM_DEFAULT_BAUDRATE
void getDefaultKey(uint8_t *key)
Gets the default encryption key.
bool ready()
Test whether the radio module is ready or not.
void setSleepMode(uint8_t mode)
Sets the sleep mode.
uint8_t getNetworkRole()
Gets the current network role.
uint8_t getEncryptFlag()
Gets the encrypt flag setting.
void setDataInterface(uint8_t value)
Sets the data interface for receiving packets.
uint16_t _wize_network_id
String _getSlotAsString(uint8_t slot, uint8_t len)
Returns the contents of the memory from a certain address as a String object.
void _resetSerial()
Resets the serial object.
#define CI_APP_RESPONSE_UP_SHORT
void sleep()
Sets the radio module in sleep mode.
void setPreamble(uint8_t preamble)
Sets the preamble length frame format.
int _readBytes(char *buffer, uint16_t len)
Reads the stream buffer up to a number of bytes.
void _bin2hex(uint8_t *bin, char *hex, uint8_t len)
Converts a binary buffer to an hex c-string.
uint8_t getDecryptFlag()
Gets the decrypt flag setting.
HardwareSerial * _hw_serial
String getRequiredHardwareVersion()
Returns the minimum required hardware version to run the current firmware.
uint8_t getPreamble()
Gets the preamble length frame format.
void setWizeNetworkId(uint8_t wize_network_id)
Sets the wize network ID field in the transpoprt layer.
int8_t _receive()
Listens to incoming data from the module until timeout or END_OF_RESPONSE.
int8_t _sendCommand(uint8_t command, uint8_t *data, uint8_t len)
Sends a command with the given data.
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.
void setControlField(uint8_t value, bool persist=false)
Sets the control field value.
void _hex2bin(char *hex, uint8_t *bin, uint8_t len)
Converts a hex c-string to a binary buffer.
void setLEDControl(uint8_t value)
Sets the LED control.
void setCounter(uint16_t counter)
Sets the wize couonter field in the transpoprt layer.
void setPower(uint8_t power, bool persist=false)
Sets the RF power.
void _flush()
Flushes the serial line to the module.
void setWizeOperatorId(uint8_t wize_network_id)
Use AllWize::setWizeNetworkId instead.
void setBaudRate(uint8_t baudrate)
Sets the UART baud rate, requires reset to take effect.
uint8_t getDataInterface()
Gets the data interface for receiving packets.
void _readModel()
Searches for the module model.
uint8_t getModuleType()
Returns the module type.
allwize_message_t read()
Returns latest received message.
String _getSlotAsHexString(uint8_t slot, uint8_t len)
Returns the contents of the memory from a certain address as an HEX String.
uint8_t getInstallMode()
Gets the install modevalue stored in non-volatile memory.
void setControlInformation(uint8_t ci)
Sets the control information byte.
uint8_t * getBuffer()
Returns pointer to the last message raw data buffer Should be copied right away since any new incommi...
void setDecryptFlag(uint8_t flag)
Sets the decrypt flag setting.
String getPartNumber()
Returns the module part number.
double getFrequency(uint8_t channel)
Returns the frequency for the given channel.
void master()
Sets the module in master mode.
uint8_t getControlField()
Gets the control field value stored in non-volatile memory.
String getFirmwareVersion()
Returns the module firmware revision.
bool _cacheMemory(uint8_t *buffer)
Reads and caches the module memory.
bool setUID(uint32_t uid)
Saved the UID into the module memory.
uint8_t getControlInformation()
Gets the control information byte.
void softReset()
Cleans the RX/TX line.
allwize_message_t _message
void setKey(uint8_t reg, const uint8_t *key)
Sets the default encryption key.
bool setWizeControl(uint8_t wize_control)
Sets the wize control field in the transport layer.
uint8_t getTemperature()
Returns the internal temperature of the module.
uint16_t getCounter()
Gets the current wize counter.
void setVersion(uint8_t version)
Sets the device version.
void setTimeout(uint16_t ms)
Sets the buffer timeout (also used for auto sleep modes)
String getUID()
Returns the Unique ID string.
AllWize(HardwareSerial *serial, uint8_t reset_gpio=GPIO_NONE, uint8_t config_gpio=GPIO_NONE)
AllWize object constructor.
bool available()
Returns true if a new message has been received and decoded This method has to be called in the main ...
void setNetworkRole(uint8_t role)
Sets the network role.
uint8_t getDevice()
Returns the device type from non-volatile memory.
uint8_t _getAddress(uint8_t slot)
Return the physical memory address for the given slot.
String getMID()
Returns the Manufacturer ID.
uint32_t getBaudRateSpeed(uint8_t value)
Gets the UART baud rate speed in bps.
void begin(uint8_t baudrate=MODEM_DEFAULT_BAUDRATE)
Inits the module communications.
bool send(uint8_t *buffer, uint8_t len)
Sends a byte array.
uint8_t getLength()
Returns the length of the last message raw data buffer.
uint8_t getDataRate()
Gets the data rate 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 ...
bool factoryReset()
Resets the module to factory settings.
uint8_t _wize_application
void repeater()
Sets the module in repeater mode.
bool getAppendRSSI()
Gets the current RSSI mode value.
int _timedRead()
Reads a byte from the stream with a timeout.
uint8_t _buffer[RX_BUFFER_SIZE]
uint8_t _getSlot(uint8_t slot)
Returns the contents of single-byte memory slot.
bool reset()
Resets the radio module.
bool _setConfig(bool value)
Sets or unsets config mode.
void setEncryptFlag(uint8_t flag)
Sets the encrypt flag setting.
uint8_t getMAC2CheckOnlyFlag()
Gets the MAC 2 Check Only flag setting.
uint16_t getDataRateSpeed(uint8_t dr)
Returns the speed for te given datarate.
uint8_t getLEDControl()
Gets the current LED control.
void _niceDelay(uint32_t ms)
Does a non-blocking delay.
uint16_t getVoltage()
Returns the internal voltage of the module.
String getModuleTypeName()
Returns the module type.
bool setMID(uint16_t mid)
Sets the Manufacturer ID.
float getRSSI()
Returns the RSSI of the last valid packet received TODO: values do not seem right and are not the sam...
bool _decode()
Decodes the current RX buffer contents.
int _readBytesUntil(char terminator, char *buffer, uint16_t len)
Reads the stream buffer up to a certain char or times out.
uint8_t _getMemory(uint8_t address)
Returns the contents of memory address.
void wakeup()
Wakes up the radio from sleep mode.
uint8_t getBaudRate()
Gets the UART baud rate.
void setDefaultKey(const uint8_t *key)
Sets the default encryption key.
uint16_t getTimeout()
Gets the current buffer timeout (also used for auto sleep modes)
void setChannel(uint8_t channel, bool persist=false)
Sets the communications channel (for MBUS_MODE_R2 only)
void setAppendRSSI(bool value)
Sets the RSSI mode value.
uint8_t getChannel()
Gets the channel stored in non-volatile memory.
uint8_t getSleepMode()
Gets the sleep mode stored in non-volatile memory.
uint8_t getPower()
Gets the RF power stored in non-volatile memory.
void setInstallMode(uint8_t mode, bool persist=false)
Sets the module in one of the available operations modes.
bool enableRX(bool enable)
Enables or disables RF recever.
void setDataRate(uint8_t dr)
Sets the data rate.