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);
125 void setChannel(uint8_t channel,
bool persist =
false);
126 void setPower(uint8_t power,
bool persist =
false);
128 void setMode(uint8_t mode,
bool persist =
false);
140 void setKey(uint8_t reg,
const uint8_t * key);
168 bool setMID(uint16_t mid);
170 bool setUID(uint32_t uid);
198 int8_t
_sendCommand(uint8_t command, uint8_t * data, uint8_t len);
204 uint8_t
_getMemory(uint8_t address, uint8_t *buffer, uint8_t len);
205 bool _setMemory(uint8_t address, uint8_t data);
206 bool _setMemory(uint8_t address, uint8_t * data, uint8_t len);
208 bool _setSlot(uint8_t slot, uint8_t data);
209 bool _setSlot(uint8_t slot, uint8_t * data, uint8_t len);
211 uint8_t
_getSlot(uint8_t slot, uint8_t * buffer, uint8_t len);
220 uint8_t
_send(uint8_t * buffer, uint8_t len);
221 uint8_t
_send(uint8_t ch);
229 void _hex2bin(
char * hex, uint8_t * bin, uint8_t len);
230 void _bin2hex(uint8_t * bin,
char * hex, uint8_t len);
245 #if defined(ARDUINO_ARCH_SAMD) 247 #elif defined(ARDUINO_ARCH_ESP32)
String getModuleTypeName()
Returns the module type.
uint8_t getChannel()
Gets the channel stored in non-volatile memory.
#define MODEM_DEFAULT_BAUDRATE
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.
bool setUID(uint32_t uid)
Saved the UID into the module memory.
void setEncryptFlag(uint8_t flag)
Sets the encrypt flag setting.
uint8_t getSleepMode()
Gets the sleep mode stored in non-volatile memory.
uint8_t getLEDControl()
Gets the current LED control.
uint8_t getPower()
Gets the RF power stored in non-volatile memory.
int _readBytes(char *buffer, uint16_t len)
Reads the stream buffer up to a number of bytes.
void setWizeApplication(uint8_t wize_application)
Sets the wize applicaton field in the transpoprt layer.
uint8_t getEncryptFlag()
Gets the encrypt flag setting.
void setVersion(uint8_t version)
Sets the device version.
void slave()
Sets the module in slave mode.
allwize_message_t _message
void setPower(uint8_t power, bool persist=false)
Sets the RF power.
void setNetworkRole(uint8_t role)
Sets the network role.
uint8_t _wize_application
uint32_t getBaudRateSpeed(uint8_t value)
Gets the UART baud rate speed in bps.
bool getAppendRSSI()
Gets the current RSSI mode value.
bool _decode()
Decodes the current RX buffer contents.
uint8_t getVersion()
Returns the device version from non-volatile memory.
uint16_t _wize_network_id
void setControlField(uint8_t value, bool persist=false)
Sets the control field value.
void begin(uint8_t baudrate=MODEM_DEFAULT_BAUDRATE)
Inits the module communications.
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.
void _resetSerial()
Resets the serial object.
void dump(Stream &debug)
Dumps the current memory configuration to the given stream.
String getRequiredHardwareVersion()
Returns the minimum required hardware version to run the current firmware.
void setPreamble(uint8_t preamble)
Sets the preamble length frame format.
uint8_t getControlField()
Gets the control field value stored in non-volatile memory.
uint8_t getPreamble()
Gets the preamble length frame format.
int8_t _receive()
Listens to incoming data from the module until timeout or END_OF_RESPONSE.
bool send(uint8_t *buffer, uint8_t len)
Sends a byte array.
void setCounter(uint16_t counter)
Sets the wize couonter field in the transpoprt layer.
void softReset()
Cleans the RX/TX line.
uint8_t _getSlot(uint8_t slot)
Returns the contents of single-byte memory slot.
uint8_t _buffer[RX_BUFFER_SIZE]
String getUID()
Returns the Unique ID string.
uint8_t getTemperature()
Returns the internal temperature of the module.
void setWizeOperatorId(uint16_t wize_network_id)
Use AllWize::setWizeNetworkId instead.
bool ready()
Test whether the radio module is ready or not.
void setSleepMode(uint8_t mode)
Sets the sleep mode.
uint8_t getDecryptFlag()
Gets the decrypt flag setting.
void setControlInformation(uint8_t ci)
Sets the control information byte.
void wakeup()
Wakes up the radio from sleep mode.
void master()
Sets the module in master mode.
bool available()
Returns true if a new message has been received and decoded This method has to be called in the main ...
String _getSlotAsHexString(uint8_t slot, uint8_t len)
Returns the contents of the memory from a certain address as an HEX String.
uint8_t getDevice()
Returns the device type from non-volatile memory.
void setLEDControl(uint8_t value)
Sets the LED control.
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 setDecryptFlag(uint8_t flag)
Sets the decrypt flag setting.
String getPartNumber()
Returns the module part number.
uint8_t getModuleType()
Returns the module type.
void repeater()
Sets the module in repeater mode.
bool waitForReady(uint32_t timeout=DEFAULT_TIMEOUT)
Waits for timeout millis for the module to be ready.
void setTimeout(uint16_t ms)
Sets the buffer timeout (also used for auto sleep modes)
uint8_t getNetworkRole()
Gets the current network role.
bool setWizeControl(uint8_t wize_control)
Sets the wize control field in the transpoprt layer.
String _getSlotAsString(uint8_t slot, uint8_t len)
Returns the contents of the memory from a certain address as a String object.
uint16_t getCounter()
Gets the current wize counter.
AllWize(HardwareSerial *serial, uint8_t reset_gpio=GPIO_NONE, uint8_t config_gpio=GPIO_NONE)
AllWize object constructor.
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 sleep()
Sets the radio module in sleep mode.
String getFirmwareVersion()
Returns the module firmware revision.
bool _cacheMemory(uint8_t *buffer)
Reads and caches the module memory.
void _niceDelay(uint32_t ms)
Does a non-blocking delay.
bool _setConfig(bool value)
Sets or unsets config mode.
double getFrequency(uint8_t channel)
Returns the frequency for the given channel.
String getMID()
Returns the Manufacturer ID.
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.
String getSerialNumber()
Returns the module serial number.
void getDefaultKey(uint8_t *key)
Gets the default encryption key.
void _readModel()
Searches for the module model.
uint8_t getMode()
Gets the MBus mode stored in non-volatile memory.
uint8_t getControlInformation()
Gets the control information byte.
void setDataInterface(uint8_t value)
Sets the data interface for receiving packets.
int _timedRead()
Reads a byte from the stream with a timeout.
void setKey(uint8_t reg, const uint8_t *key)
Sets the default encryption key.
void setDefaultKey(const uint8_t *key)
Sets the default encryption key.
uint8_t getInstallMode()
Gets the install modevalue stored in non-volatile memory.
void setAccessNumber(uint8_t value)
Sets new/specific access number.
SoftwareSerial * _sw_serial
#define CI_APP_RESPONSE_UP_SHORT
bool reset()
Resets the radio module.
bool _setSlot(uint8_t slot, uint8_t data)
Sets non-volatile memory contents starting from given address.
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...
void _bin2hex(uint8_t *bin, char *hex, uint8_t len)
Converts a binary buffer to an hex c-string.
uint8_t _getAddress(uint8_t slot)
Return the physical memory address for the given slot.
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 _setMemory(uint8_t address, uint8_t data)
Sets non-volatile memory contents starting from given address.
uint16_t getTimeout()
Gets the current buffer timeout (also used for auto sleep modes)
void _hex2bin(char *hex, uint8_t *bin, uint8_t len)
Converts a hex c-string to a binary buffer.
uint16_t getDataRateSpeed(uint8_t dr)
Returns the speed for te given datarate.
void _flush()
Flushes the serial line to the module.
void setWizeNetworkId(uint16_t wize_network_id)
Sets the wize network ID field in the transpoprt layer.
uint8_t getDataInterface()
Gets the data interface for receiving packets.
void setDataRate(uint8_t dr)
Sets the data rate.
void setBaudRate(uint8_t baudrate)
Sets the UART baud rate, requires reset to take effect.
HardwareSerial * _hw_serial
uint8_t getDataRate()
Gets the data rate stored in non-volatile memory.
allwize_message_t read()
Returns latest received message.
void setDevice(uint8_t type)
Sets the device type.
uint8_t getBaudRate()
Gets the UART baud rate.
uint16_t getVoltage()
Returns the internal voltage of the module.
bool factoryReset()
Resets the module to factory settings.