ModularSensors > Classes > loggerModem > SIMComSIM800
ModularSensors > Modules > SIMCom SIM800 > SIMComSIM800


SIMComSIM800 class

The loggerModem subclass for the Adafruit Fona 2G, the Sodaq GPRSBeeR4 and almost any other module based on the SIMCOM SIM800 or SIM900 modules andthier variants".

Base classes

class loggerModem
The loggerModem class provides an internet connection for the logger and supplies an Arduino Client instance to use to publish data.

Derived classes

class Sodaq2GBeeR6
The loggerModem subclass for the Sodaq 2GBee revisions 6 and higher based on the SIMCOM SIM800H.

Constructors, destructors, conversion operators

SIMComSIM800(Stream* modemStream, int8_t powerPin, int8_t statusPin, int8_t modemResetPin, int8_t modemSleepRqPin, const char* apn)
Construct a new SIMComSIM800 object 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.
~SIMComSIM800()
Destroy the SIMComSIM800 object - no action taken.

Public functions

bool modemWake(void ) override
Wake up the modem.
bool 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.
void disconnectInternet(void ) override
Detatch from EPS or GPRS data connection and then deregister from the cellular network.
uint32_t getNISTTime(void ) override
Get the time from NIST via TIME protocol (rfc868).
bool 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.
bool getModemBatteryStats(uint8_t& chargeState, int8_t& percent, uint16_t& milliVolts) override
Query the modem for battery information and write the values to the supplied non-constant references.
float getModemChipTemperature(void ) override
Get the current temperature provided by the modem module.

Public variables

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

Protected functions

bool isInternetAvailable(void ) override
Check whether there is an active internet connection available.
bool modemSleepFxn(void ) override
Perform the parts of the modem sleep process that are unique to a specific module, as opposed to the parts of setup that are common to all modem modules.
bool modemWakeFxn(void ) override
Perform the parts of the modem wake up process that are unique to a specific module, as opposed to the parts of setup that are common to all modem modules.
bool extraModemSetup(void ) 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 ) override
Check if the modem was awake using all possible means.

Function documentation

SIMComSIM800(Stream* modemStream, int8_t powerPin, int8_t statusPin, int8_t modemResetPin, int8_t modemSleepRqPin, const char* apn)

Construct a new SIMComSIM800 object 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.

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). Should be set to a negative number if the modem should be continuously powered or the power cannot be controlled by the MCU.
statusPin The digital pin number of the mcu pin connected to the modem status output pin. Should be set to a negative number if the modem status pin cannot be read. This is the pin labeled STATUS in SIMCom's integration guide.
modemResetPin The digital pin number of the pin on the mcu attached the the hard or panic reset pin of the modem. Should be set to a negative number if the modem reset pin is not connected to the MCU. This is the pin labeled RESET in SIMCom's integration guide.
modemSleepRqPin The digital pin number of a pin on the mcu used to request the modem enter its lowest possible power state. 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 is the pin labeled PWRKEY in SIMCom's integration guide.
apn The Access Point Name (APN) for the SIM card.

boolmodemWake(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.


boolconnectInternet(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


uint32_tgetNISTTime(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.

Check for and bail if not connected to the internet.

Try up to 12 times to get a timestamp from NIST.

Make TCP connection.

Wait up to 5 seconds for a response.


boolgetModemSignalQuality(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.

boolgetModemBatteryStats(uint8_t& chargeState, int8_t& percent, uint16_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.

floatgetModemChipTemperature(void ) override

Get the current temperature provided by the modem module.

Returns float The temperature in degrees Celsius

boolisInternetAvailable(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.

boolmodemSleepFxn(void ) override protected

Perform the parts of the modem sleep 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 unique part of the sleep function ran sucessfully.

boolmodemWakeFxn(void ) override protected

Perform the parts of the modem wake 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 unique part of the wake function ran sucessfully - does NOT indicate that the modem is now responsive.

boolextraModemSetup(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 most modules, this function is created by the MS_MODEM_EXTRA_SETUP macro which runs the TinyGSM modem init() and client init() functions.


boolisModemAwake(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 there's a pulse wake up (ie, non-zero wake time) and there's a status pin, use that to determine if the modem was awake before setup began.

If the wake up is one where a pin is held (0 wake time) 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 no status pin, but still a pulsed wake up, try checking if the modem responds to AT commands.