AllWize Library
Public Member Functions
AllWize_LoRaWAN Class Reference

#include <AllWize_LoRaWAN.h>

Inheritance diagram for AllWize_LoRaWAN:
Inheritance graph
[legend]
Collaboration diagram for AllWize_LoRaWAN:
Collaboration graph
[legend]

Public Member Functions

 AllWize_LoRaWAN (HardwareSerial *serial, uint8_t reset_gpio=GPIO_NONE)
 
 AllWize_LoRaWAN (uint8_t rx, uint8_t tx, uint8_t reset_gpio=GPIO_NONE)
 
bool joinABP (uint8_t *DevAddr, uint8_t *AppSKey, uint8_t *NwkSKey)
 Stores the application and network keys for ABP activation. More...
 
bool send (uint8_t *Data, uint8_t Data_Length, uint8_t Frame_Port=0x01)
 Function to assemble and send a LoRaWAN package. More...
 
uint16_t getFrameCounter ()
 Returns current frame counter. More...
 
void setFrameCounter (uint16_t value)
 Sets new frame counter. More...
 
- Public Member Functions inherited from AllWize
 AllWize (HardwareSerial *serial, uint8_t reset_gpio=GPIO_NONE, uint8_t config_gpio=GPIO_NONE)
 AllWize object constructor. More...
 
 AllWize (uint8_t rx, uint8_t tx, uint8_t reset_gpio=GPIO_NONE, uint8_t config_gpio=GPIO_NONE)
 AllWize object constructor. More...
 
void begin (uint8_t baudrate=MODEM_DEFAULT_BAUDRATE)
 Inits the module communications. More...
 
bool reset ()
 Resets the radio module. More...
 
void softReset ()
 Cleans the RX/TX line. More...
 
bool factoryReset ()
 Resets the module to factory settings. More...
 
void sleep ()
 Sets the radio module in sleep mode. More...
 
void wakeup ()
 Wakes up the radio from sleep mode. More...
 
bool ready ()
 Test whether the radio module is ready or not. More...
 
bool waitForReady (uint32_t timeout=DEFAULT_TIMEOUT)
 Waits for timeout millis for the module to be ready. More...
 
void dump (Stream &debug)
 Dumps the current memory configuration to the given stream. More...
 
bool ack ()
 Sends an ACK. More...
 
bool send (uint8_t *buffer, uint8_t len)
 Sends a byte array. More...
 
bool send (const char *buffer)
 Sends c-string. More...
 
bool available ()
 Returns true if a new message has been received and decoded This method has to be called in the main loop to monitor for incoming messages. More...
 
bool enableRX (bool enable)
 Enables or disables RF recever. More...
 
allwize_message_t read ()
 Returns latest received message. More...
 
void setControlInformation (uint8_t ci)
 Sets the control information byte. More...
 
uint8_t getControlInformation ()
 Gets the control information byte. More...
 
void master ()
 Sets the module in master mode. More...
 
void slave ()
 Sets the module in slave mode. More...
 
void repeater ()
 Sets the module in repeater mode. More...
 
void setChannel (uint8_t channel, bool persist=false)
 Sets the communications channel (for MBUS_MODE_R2 only) More...
 
void setPower (uint8_t power, bool persist=false)
 Sets the RF power. More...
 
void setDataRate (uint8_t dr)
 Sets the data rate. More...
 
void setMode (uint8_t mode, bool persist=false)
 Sets the module in one of the available MBus modes. More...
 
void setSleepMode (uint8_t mode)
 Sets the sleep mode. More...
 
void setAppendRSSI (bool value)
 Sets the RSSI mode value. More...
 
void setPreamble (uint8_t preamble)
 Sets the preamble length frame format. More...
 
void setTimeout (uint16_t ms)
 Sets the buffer timeout (also used for auto sleep modes) More...
 
void setNetworkRole (uint8_t role)
 Sets the network role. More...
 
void setLEDControl (uint8_t value)
 Sets the LED control. More...
 
void setDataInterface (uint8_t value)
 Sets the data interface for receiving packets. More...
 
void setControlField (uint8_t value, bool persist=false)
 Sets the control field value. More...
 
void setInstallMode (uint8_t mode, bool persist=false)
 Sets the module in one of the available operations modes. More...
 
void setEncryptFlag (uint8_t flag)
 Sets the encrypt flag setting. More...
 
void setDecryptFlag (uint8_t flag)
 Sets the decrypt flag setting. More...
 
void setKey (uint8_t reg, const uint8_t *key)
 Sets the default encryption key. More...
 
void setDefaultKey (const uint8_t *key)
 Sets the default encryption key. More...
 
void setAccessNumber (uint8_t value)
 Sets new/specific access number. More...
 
void setBaudRate (uint8_t baudrate)
 Sets the UART baud rate, requires reset to take effect. More...
 
uint8_t getChannel ()
 Gets the channel stored in non-volatile memory. More...
 
uint8_t getPower ()
 Gets the RF power stored in non-volatile memory. More...
 
uint8_t getDataRate ()
 Gets the data rate stored in non-volatile memory. More...
 
uint8_t getMode ()
 Gets the MBus mode stored in non-volatile memory. More...
 
uint8_t getSleepMode ()
 Gets the sleep mode stored in non-volatile memory. More...
 
uint8_t getPreamble ()
 Gets the preamble length frame format. More...
 
uint8_t getDataInterface ()
 Gets the data interface for receiving packets. More...
 
uint8_t getControlField ()
 Gets the control field value stored in non-volatile memory. More...
 
bool getAppendRSSI ()
 Gets the current RSSI mode value. More...
 
uint16_t getTimeout ()
 Gets the current buffer timeout (also used for auto sleep modes) More...
 
uint8_t getNetworkRole ()
 Gets the current network role. More...
 
uint8_t getLEDControl ()
 Gets the current LED control. More...
 
uint8_t getInstallMode ()
 Gets the install modevalue stored in non-volatile memory. More...
 
uint8_t getEncryptFlag ()
 Gets the encrypt flag setting. More...
 
uint8_t getDecryptFlag ()
 Gets the decrypt flag setting. More...
 
void getDefaultKey (uint8_t *key)
 Gets the default encryption key. More...
 
uint8_t getBaudRate ()
 Gets the UART baud rate. More...
 
uint32_t getBaudRateSpeed (uint8_t value)
 Gets the UART baud rate speed in bps. More...
 
float getRSSI ()
 Returns the RSSI of the last valid packet received TODO: values do not seem right and are not the same as in the packet. More...
 
uint8_t getTemperature ()
 Returns the internal temperature of the module. More...
 
uint16_t getVoltage ()
 Returns the internal voltage of the module. More...
 
String getMID ()
 Returns the Manufacturer ID. More...
 
bool setMID (uint16_t mid)
 Sets the Manufacturer ID. More...
 
String getUID ()
 Returns the Unique ID string. More...
 
bool setUID (uint32_t uid)
 Saved the UID into the module memory. More...
 
uint8_t getVersion ()
 Returns the device version from non-volatile memory. More...
 
void setVersion (uint8_t version)
 Sets the device version. More...
 
uint8_t getDevice ()
 Returns the device type from non-volatile memory. More...
 
void setDevice (uint8_t type)
 Sets the device type. More...
 
String getPartNumber ()
 Returns the module part number. More...
 
String getRequiredHardwareVersion ()
 Returns the minimum required hardware version to run the current firmware. More...
 
String getFirmwareVersion ()
 Returns the module firmware revision. More...
 
String getSerialNumber ()
 Returns the module serial number. More...
 
double getFrequency (uint8_t channel)
 Returns the frequency for the given channel. More...
 
uint16_t getDataRateSpeed (uint8_t dr)
 Returns the speed for te given datarate. More...
 
uint8_t getModuleType ()
 Returns the module type. More...
 
String getModuleTypeName ()
 Returns the module type. More...
 
bool setWizeControl (uint8_t wize_control)
 Sets the wize control field in the transpoprt layer. More...
 
void setWizeOperatorId (uint16_t wize_operator_id)
 Sets the wize operator ID field in the transpoprt layer. More...
 
void setWizeApplication (uint8_t wize_application)
 Sets the wize applicaton field in the transpoprt layer. More...
 
void setCounter (uint16_t counter)
 Sets the wize couonter field in the transpoprt layer. More...
 
uint16_t getCounter ()
 Gets the current wize counter. More...
 

Additional Inherited Members

- Protected Member Functions inherited from AllWize
void _init ()
 
uint8_t _getAddress (uint8_t slot)
 Return the physical memory address for the given slot. More...
 
bool _setConfig (bool value)
 Sets or unsets config mode. More...
 
int8_t _sendCommand (uint8_t command, uint8_t *data, uint8_t len)
 Sends a command with the given data. More...
 
int8_t _sendCommand (uint8_t command, uint8_t data)
 Sends a command with the given data. More...
 
int8_t _sendCommand (uint8_t command)
 Sends a command with no data. More...
 
bool _cacheMemory (uint8_t *buffer)
 Reads and caches the module memory. More...
 
uint8_t _getMemory (uint8_t address)
 Returns the contents of memory address. More...
 
uint8_t _getMemory (uint8_t address, uint8_t *buffer, uint8_t len)
 Returns the contents of consecutive memory addresses. More...
 
bool _setMemory (uint8_t address, uint8_t data)
 Sets non-volatile memory contents starting from given address. More...
 
bool _setMemory (uint8_t address, uint8_t *data, uint8_t len)
 Sets non-volatile memory contents starting from given address. More...
 
bool _setSlot (uint8_t slot, uint8_t data)
 Sets non-volatile memory contents starting from given address. More...
 
bool _setSlot (uint8_t slot, uint8_t *data, uint8_t len)
 Sets non-volatile memory contents starting from given address. More...
 
uint8_t _getSlot (uint8_t slot)
 Returns the contents of single-byte memory slot. More...
 
uint8_t _getSlot (uint8_t slot, uint8_t *buffer, uint8_t len)
 Returns the contents of consecutive memory addresses. More...
 
String _getSlotAsHexString (uint8_t slot, uint8_t len)
 Returns the contents of the memory from a certain address as an HEX String. More...
 
String _getSlotAsString (uint8_t slot, uint8_t len)
 Returns the contents of the memory from a certain address as a String object. More...
 
void _readModel ()
 Searches for the module model. More...
 
bool _decode ()
 Decodes the current RX buffer contents. More...
 
void _flush ()
 Flushes the serial line to the module. More...
 
void _reset_serial ()
 Resets the serial object. More...
 
uint8_t _send (uint8_t *buffer, uint8_t len)
 Sends a binary buffer to the module UART. Returns the number of bytes actually sent. More...
 
uint8_t _send (uint8_t ch)
 Sends a single byte to the module UART. Returns the number of bytes actually sent. More...
 
int8_t _receive ()
 Listens to incoming data from the module until timeout or END_OF_RESPONSE. More...
 
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 internal _buffer. More...
 
int8_t _sendAndReceive (uint8_t ch)
 Sends a byte and waits for response. Returns the number of bytes received and stored in the internal _buffer. More...
 
int _timedRead ()
 Reads a byte from the stream with a timeout. More...
 
int _readBytes (char *buffer, uint16_t len)
 Reads the stream buffer up to a number of bytes. More...
 
int _readBytesUntil (char terminator, char *buffer, uint16_t len)
 Reads the stream buffer up to a certain char or times out. More...
 
void _hex2bin (char *hex, uint8_t *bin, uint8_t len)
 Converts a hex c-string to a binary buffer. More...
 
void _bin2hex (uint8_t *bin, char *hex, uint8_t len)
 Converts a binary buffer to an hex c-string. More...
 
- Protected Attributes inherited from AllWize
int8_t _rx = -1
 
int8_t _tx = -1
 
Stream * _stream = NULL
 
HardwareSerial * _hw_serial = NULL
 
SoftwareSerial * _sw_serial = NULL
 
uint8_t _reset_gpio = GPIO_NONE
 
uint8_t _config_gpio = GPIO_NONE
 
bool _config = false
 
uint32_t _timeout = DEFAULT_TIMEOUT
 
uint32_t _baudrate = 19200
 
uint8_t _ci = CI_APP_RESPONSE_UP_SHORT
 
uint8_t _mbus_mode = 0xFF
 
uint8_t _data_interface = 0xFF
 
bool _append_rssi = false
 
uint8_t _access_number = 0
 
uint8_t _module = MODULE_UNKNOWN
 
bool _ready = false
 
uint8_t _memory [0x100] = {0xFF}
 
String _model
 
String _hw
 
String _fw
 
uint8_t _wize_control = 0x00
 
uint16_t _wize_operator_id = 0
 
uint8_t _wize_application = 0
 
uint16_t _counter = 0
 
allwize_message_t _message
 
uint8_t _buffer [RX_BUFFER_SIZE]
 
uint8_t _pointer = 0
 

Detailed Description

Definition at line 36 of file AllWize_LoRaWAN.h.

Constructor & Destructor Documentation

◆ AllWize_LoRaWAN() [1/2]

AllWize_LoRaWAN::AllWize_LoRaWAN ( HardwareSerial *  serial,
uint8_t  reset_gpio = GPIO_NONE 
)
inline

Definition at line 40 of file AllWize_LoRaWAN.h.

◆ AllWize_LoRaWAN() [2/2]

AllWize_LoRaWAN::AllWize_LoRaWAN ( uint8_t  rx,
uint8_t  tx,
uint8_t  reset_gpio = GPIO_NONE 
)
inline

Definition at line 44 of file AllWize_LoRaWAN.h.

Member Function Documentation

◆ getFrameCounter()

uint16_t AllWize_LoRaWAN::getFrameCounter ( )

Returns current frame counter.

Returns
Frame counter

Definition at line 133 of file AllWize_LoRaWAN.cpp.

◆ joinABP()

bool AllWize_LoRaWAN::joinABP ( uint8_t *  DevAddr,
uint8_t *  AppSKey,
uint8_t *  NwkSKey 
)

Stores the application and network keys for ABP activation.

Parameters
DevAddrDevice addres
AppSKeyApplication Session Key
NwkSKeyNetwork Session Key
Returns
Allways true since ABP joins never fail

Definition at line 40 of file AllWize_LoRaWAN.cpp.

◆ send()

bool AllWize_LoRaWAN::send ( uint8_t *  Data,
uint8_t  Data_Length,
uint8_t  Frame_Port = 0x01 
)

Function to assemble and send a LoRaWAN package.

Parameters
DataPointer to the array of data to be transmitted.
Data_LengthLength of data to be sent.
Frame_PortFrame Port (defaults to 0x01)
Returns
True if message was sent successfully, false otherwise

Definition at line 54 of file AllWize_LoRaWAN.cpp.

Here is the call graph for this function:

◆ setFrameCounter()

void AllWize_LoRaWAN::setFrameCounter ( uint16_t  value)

Sets new frame counter.

Parameters
value2-bytes long new frame counter

Definition at line 141 of file AllWize_LoRaWAN.cpp.


The documentation for this class was generated from the following files: