DigiXBeeWifi class

The class for the Digi XBee S6B wifi module operating in Digi's "transparent" mode.

Base classes

class DigiXBee
The parent class for all Digi XBee and XBee3 wifi and cellular modules.

Constructors, destructors, conversion operators

DigiXBeeWifi(Stream* modemStream, int8_t powerPin, int8_t statusPin, bool useCTSStatus, int8_t modemResetPin, int8_t modemSleepRqPin, const char* ssid, const char* pwd, bool maintainAssociation = false)
Construct a new Digi XBee Wifi object.
~DigiXBeeWifi()
Destroy the Digi XBee Wifi object - no action taken.

Public functions

bool modemWake(void) -> bool override
Wake up the modem.
bool connectInternet(uint32_t maxConnectionTime = 50000L) -> bool override
Wait for the modem to successfully register on the cellular network and then request that it establish either EPS or GPRS data connection.
void disconnectInternet(void) override
Detatch from EPS or GPRS data connection and then deregister from the cellular network.
uint32_t getNISTTime(void) -> uint32_t override
Get the time from NIST via TIME protocol (rfc868).
bool getModemSignalQuality(int16_t& rssi, int16_t& percent) -> bool override
Query the modem for the current signal quality and write the results to the supplied non-constant references.
bool getModemBatteryStats(int8_t& chargeState, int8_t& percent, int16_t& milliVolts) -> bool override
Query the modem for battery information and write the values to the supplied non-constant references.
float getModemChipTemperature(void) -> float override
Get the current temperature provided by the modem module.
bool updateModemMetadata(void) -> bool override
Query the modem for signal quality, battery, and temperature information and store the values to the static internal variables.

Public variables

TinyGsm gsmModem
Public reference to the TinyGSM modem.
TinyGsmClient gsmClient
Public reference to the TinyGSM Client.

Protected functions

bool isInternetAvailable(void) -> bool override
Check whether there is an active internet connection available.
bool extraModemSetup(void) -> bool override
Perform the parts of the modem set up process that are unique to a specific module, as opposed to the parts of setup that are common to all modem modules.
bool isModemAwake(void) -> bool override
Check if the modem was awake using all possible means.

Function documentation

DigiXBeeWifi::DigiXBeeWifi(Stream* modemStream, int8_t powerPin, int8_t statusPin, bool useCTSStatus, int8_t modemResetPin, int8_t modemSleepRqPin, const char* ssid, const char* pwd, bool maintainAssociation = false)

Construct a new Digi XBee Wifi object.

Parameters
modemStream The Arduino stream instance for serial communication.
powerPin The digital pin number of the mcu pin controlling power to the modem (active HIGH).
statusPin The digital pin number of the mcu pin connected to the modem status output pin.
useCTSStatus True to use the CTS_N/DIO7 pin of the XBee as a status indicator rather than the true status (ON/SLEEP_N/DIO9) pin. This inverts the loggerModem::_statusLevel.
modemResetPin The digital pin number of the pin on the mcu attached the the hard or panic reset pin of the modem.
modemSleepRqPin The digital pin number of a pin on the mcu used to request the modem enter its lowest possible power state.
ssid The wifi network ID.
pwd The wifi network password, assuming WPA2.
maintainAssociation Whether to maintain association with the access point during sleep. Maitaining the association during sleep draws more current (+10mA?), but also allows a faster reconnection on the next wake.

The constuctor initializes all of the provided member variables, constructs a loggerModem parent class with the appropriate timing for the module, calls the constructor for a TinyGSM modem on the provided modemStream, and creates a TinyGSM Client linked to the modem.

Should be set to a negative number if the modem should be continuously powered or the power cannot be controlled by the MCU. Should be set to a negative number if the modem status pin cannot be read. This can be either the pin named ON/SLEEP_N/DIO9 or CTS_N/DIO7 pin in Digi's hardware reference. Should be set to a negative number if the modem reset pin is not connected to the MCU. This shold be the pin called RESET_N in Digi's hardware reference. Should be set to a negative number if there is no pin usable for deep sleep modes or it is not accessible to the MCU. This shold be the pin called DTR_N/SLEEP_RQ/DIO8 in Digi's hardware reference.


bool DigiXBeeWifi::modemWake(void) override

Wake up the modem.

Returns bool True if the modem is responsive and ready for action.

This sets pin modes, powers up the modem if necessary, sets time stamps, runs the specific modem's wake function, tests for responsiveness to AT commands, and then re-runs the TinyGSM init() if necessary. If the modem fails to respond, this attempts a "hard" pin reset if possible.

For most modules, this function is created by the MS_MODEM_WAKE macro.

Set-up pin modes. Because the modem calls wake BEFORE the first setup, we must set the pin modes in the wake function.

Run the specific modemWakeFxn().

Check that the modem is responding to AT commands.

Hard reset is there's no AT response.

Exit if we can't hard reset.

Clean any junk out of the modem buffer.

Re-run the modem init, or setup if necessary. This will turn off echo, which often turns itself back on after a reset/power loss. This also checks the SIM card state.

If we run setup, take success value entirely from that.


bool DigiXBeeWifi::connectInternet(uint32_t maxConnectionTime = 50000L) override

Wait for the modem to successfully register on the cellular network and then request that it establish either EPS or GPRS data connection.

Parameters
maxConnectionTime The maximum length of time in milliseconds to wait for network registration and data sconnection. Defaults to 50,000ms (50s).
Returns bool True if EPS or GPRS data connection has been established. False if the modem wasunresponsive, unable to register with the cellular network, or unable to establish a EPS or GPRS connection.

Power up, if necessary

Check if the modem was awake, wake it if not

wait


uint32_t DigiXBeeWifi::getNISTTime(void) override

Get the time from NIST via TIME protocol (rfc868).

Returns uint32_t The number of seconds since Jan 1, 1970 IN UTC

This would be much more efficient if done over UDP, but I'm doing it over TCP because I don't have a UDP library for all the modems.


bool DigiXBeeWifi::getModemSignalQuality(int16_t& rssi, int16_t& percent) override

Query the modem for the current signal quality and write the results to the supplied non-constant references.

Parameters
rssi A reference to an int16_t which will be set with the received signal strength indicator
percent A reference to an int16_t which will be set with the "percent" signal strength
Returns bool True indicates that the communication with the modem was successful and the values referenced by the pointers should be valid.

bool DigiXBeeWifi::getModemBatteryStats(int8_t& chargeState, int8_t& percent, int16_t& milliVolts) override

Query the modem for battery information and write the values to the supplied non-constant references.

Parameters
chargeState A reference to an uint8_t which will be set with the current charge state (significance of value varies)
percent A reference to an int8_t which will be set with the current charge percent - this may or may not be a valid value depending on the module and breakout.
milliVolts A reference to an uint16_t which will be set with the current battery voltage in mV - this may or may not be a valid value depending on the module and breakout.
Returns bool True indicates that the communication with the modem was successful and the values referenced by the pointers should be valid.

float DigiXBeeWifi::getModemChipTemperature(void) override

Get the current temperature provided by the modem module.

Returns float The temperature in degrees Celsius

bool DigiXBeeWifi::updateModemMetadata(void) override

Query the modem for signal quality, battery, and temperature information and store the values to the static internal variables.

Returns bool True indicates that the communication with the modem was successful and the values of the internal static variables should be valid.

bool DigiXBeeWifi::isInternetAvailable(void) override protected

Check whether there is an active internet connection available.

Returns bool True if there is an active data connection to the internet.

bool DigiXBeeWifi::extraModemSetup(void) override protected

Perform the parts of the modem set up process that are unique to a specific module, as opposed to the parts of setup that are common to all modem modules.

Returns bool True if the extra setup succeeded.

For XBees, this sets the appropriate operating mode (transparent or bypass), enables pin sleep, sets the DIO pins to the expected functions, and reboots the modem to ensure all settings are applied.

First run the TinyGSM init() function for the XBee.

Then enter command mode to set pin outputs.

Enable pin sleep functionality on DIO8 if a pin is assigned. NOTE: Only the DTR_N/SLEEP_RQ/DIO8 pin (9 on the bee socket) can be used for this pin sleep/wake.

Enable status indication on DIO9 if a pin is assigned - it will be HIGH when the XBee is awake. NOTE: Only the ON/SLEEP_N/DIO9 pin (13 on the bee socket) can be used for direct status indication.

Enable CTS on DIO7 if a pin is assigned - it will be LOW when it is clear to send data to the XBee. This can be used as proxy for status indication if that pin is not readable. NOTE: Only the CTS_N/DIO7 pin (12 on the bee socket) can be used for CTS.

Enable association indication on DIO5 - this is should be directly attached to an LED if possible.

  • Solid light indicates no connection
  • Single blink indicates connection
  • double blink indicates connection but failed TCP link on last attempt

NOTE: Only the Associate/DIO5 pin (15 on the bee socket) can be used for this function.

Enable RSSI PWM output on DIO10 - this should be directly attached to an LED if possible. A higher PWM duty cycle (and thus brighter LED) indicates better signal quality. NOTE: Only the DIO10/PWM0 pin (6 on the bee socket) can be used for this function.

Put the XBee in pin sleep mode in conjuction with D8=1

Write pin and sleep options to flash and apply them, if needed.

Set the socket timeout to 10s (this is default).

Set the destination IP to 0 (this is default).

Write all changes to flash and apply them.


bool DigiXBeeWifi::isModemAwake(void) override protected

Check if the modem was awake using all possible means.

Returns bool True if the modem is already awake.

If possible, we always want to check if the modem was awake before attempting to wake it up. Most cellular modules are woken and put to sleep by identical pulses on a sleep or "power" pin. We don't want to accidently pulse an already on modem to off.

For most modules, this function is created by the MS_IS_MODEM_AWAKE macro.

If the wake up is one where a pin is held (0 wake time) and * that pin is defined, then we're going to check the level of the * held pin as the indication of whether attempts were made to * wake the modem before entering the setup function.

If there's a status pin, use that to determine if the modem is * awake.

If we can't determine status by pin level, try checking if the * modem responds to AT commands.