How to Monitor Your Campbell Cellular Modem Data Usage: Part 1

by Nathanael Wright | Updated: 01/16/2019 | Comments: 2

Search the Blog


Subscribe to the Blog

Set up your preferences for receiving email notifications when new blog articles are posted that match your areas of interest.


Area / Application

Product Category

Activity

Corporate / News

Enter your email address:



Suggest an Article

Is there a topic you would like to learn more about? Let us know. Please be as specific as possible.

Leave this field empty

CR310-CELL210 datalogger with CRBasic code

Did you know you can monitor your data usage using CRBasic program code on our new data loggers with integrated cellular modems and our external Campbell Scientific brand of cellular modules? In this two-part series, I’ll first show you how to do this in the CRBasic code of a CR310-CELL210. This code will work for any model of the CR300-series dataloggers with an integrated cellular modem. It will also work for our external cellular CELL2XX modules when you use them with the CR300, CR310, CR6, or CR1000X dataloggers. Note the data logger operating system compatibility requirements below:

Looking Ahead: In the second article of this series, I’ll show you how to monitor your data usage using serial commands with our external CELL2XX series of cellular modules using the CR800, CR850, CR1000, or CR3000 dataloggers.

Background

The CR300, CR310, CR1000X, and CR6 dataloggers record cellular data usage that can be used in your data logger programs to turn off interfaces and perform a variety of functions. These values are already stored in the hidden Settings table under some of the following field names:

Settings.CellUsageToday
Settings.CellUsageYesterday
Settings.CellUsageMonth
Settings.CellUsageLastMonth

Recording this data is as easy as adding the values to a CRBasic DataTable, as shown below:

DataTable(CELL_DIAGNOSTICS, True, -1)
	Sample(1, Settings.CellUsageToday, FP2)
	Sample(1, Settings.CellUsageYesterday, FP2)
	Sample(1, Settings.CellUsageMonth, FP2)
	Sample(1, Settings.CellUsageLastMonth, FP2)
EndTable

Steps for Control and Display of Variables

For more options to control the variables and how they are displayed, follow the four-step process outlined below.

#1 - Declare variables and set units

To start monitoring your data usage with CRBasic code, first declare your variable(s) and assign units to the variable(s). In my example below, I am using “cell_todays_usage,” “cell_yesterdays_usage,” “cell_this_months_usage,” and “cell_last_months_usage.”

Public cell_todays_usage
Public cell_yesterdays_usage
Public cell_this_months_usage
Public cell_last_months_usage

Units cell_todays_usage = KB
Units cell_yesterdays_usage = KB
Units cell_this_months_usage = KB
Units cell_last_months_usage = KB

#2 - Create a DataTable

If you want to store the usage information in a DataTable, create a new DataTable or add the values to an existing DataTable. Below, the example is included with additional options for yesterday’s usage, this month’s usage, and last month’s usage:

DataTable(CELL_DIAGNOSTICS, True, -1)
	Sample(1, cell_todays_usage, FP2)
	Sample(1, cell_yesterdays_usage, FP2)
	Sample(1, cell_this_months_usage, FP2)
	Sample(1, cell_last_months_usage, FP2)
EndTable

#3 - Set your declared variable(s)

Within your Scan() sequence set the variable(s) you have declared equal to Settings.CellUsageToday or the other data usage values shown below. Using your variable(s) you can run it against conditional statements to program your logger’s behavior.

cell_todays_usage = Settings.CellUsageToday
cell_yesterdays_usage = Settings.CellUsageYesterday
cell_this_months_usage = Settings.CellUsageMonth
cell_last_months_usage = Settings.CellUsageLastMonth

#4 - Write your values to a table

If you are recording your data to a table, ensure you are writing your values using the CallTable() instruction. To avoid interrupting the reading of our other sensors during normal program operation, I placed my CallTable() instruction in a SlowSequence. (This is more relevant if you are using a larger number of commands than what we are using in this example and may not be necessary for your situation.) Be sure to use the CallTable() instruction if you are recording the values.

SlowSequence
	Scan (10, Min, 0, 0)
		cell_todays_usage = Settings.CellUsageToday
		cell_yesterdays_usage = Settings.CellUsageYesterday
		cell_this_months_usage = Settings.CellUsageMonth
		cell_last_months_usage = Settings.CellUsageLastMonth
      		CallTable CELL_DIAGNOSTICS
	NextScan

Final Program Example

When you have completed the steps, your program should look similar to this:

'Declare Public Variables
Public battery_voltage
Public panel_temperature_c

'cell modem diagnostics information
Public cell_todays_usage      : Units cell_todays_usage = KB
Public cell_yesterdays_usage  : Units cell_yesterdays_usage = KB
Public cell_this_months_usage : Units cell_this_months_usage = KB
Public cell_last_months_usage : Units cell_last_months_usage = KB

DataTable(CELL_DIAGNOSTICS, True, -1)
	Sample(1, Settings.CellUsageToday, FP2)
	Sample(1, Settings.CellUsageYesterday, FP2)
	Sample(1, Settings.CellUsageMonth, FP2)
	Sample(1, Settings.CellUsageLastMonth, FP2)
EndTable

DataTable(TEST_DATA, True, -1)
	DataInterval(0, 5, Min, 10)
	Minimum(1, battery_voltage, FP2, True, False)
	Sample(1, panel_temperature_c, FP2)
EndTable

'Main Program
BeginProg
		Scan (1,Sec,0,0)
			PanelTemp (panel_temperature_c,60)
			Battery (battery_voltage)
			CallTable TEST_DATA
		NextScan
	
	SlowSequence
 		Scan (10, Min, 0, 0)
			cell_todays_usage = Settings.CellUsageToday          'reported in KB
			cell_yesterdays_usage = Settings.CellUsageYesterday  'reported in KB
			cell_this_months_usage = Settings.CellUsageMonth     'reported in KB
			cell_last_months_usage = Settings.CellUsageLastMonth 'reported in KB
      
				CallTable CELL_DIAGNOSTICS
		NextScan
	EndSequence
EndProg

More Values You Can Use

Additional integrated cellular modem values are available that you can use. A short list is below:

Settings.CellRSSI 'read RSSI (signal strength) from tower
Settings.CellUsageToday		'usage reported in KB
Settings.CellUsageYesterday	'usage reported in KB
Settings.CellUsageMonth		'usage reported in KB
Settings.CellUsageLastMonth	'usage reported in KB
Settings.CellInfo	'Cell Info. The information that shows in DevConfig's Cellular Network Status field.
Settings.CellStatus	'Status of the cellular modem.
Settings.CellRSRP	'Reference signal received power for LTE in dbm.
Settings.CellECIO	'Reference signal received quality for 3G.
Settings.CellRSRQ	'Reference signal received quality for 4G.
Settings.CellState	'State that the modem is in. "Network ready." Lets me know my modem is good to go. 
CellState can be the following (but not limited to):
				'"Power off.",
				'"Powering up.",
				'"Powered up.",
				'"SIM authorized.",
				'"Setting baud rate.",
				'"Waiting for baud rate.",
				'"Baud rate set.",
				'"Baud rate failure.",
				'"Power off. Waiting for retry.",
				'"Powered up. SIM auth failure.",
				'"Querying modem.",
				'"Waiting for network registration.",
				'"Configuring modem.",
				'"Dialing.",
				'"Dialing (retry).",
				'"Dialed.",
				'"PPP negotiation.",
				'"Network ready.",
				'"PPP closing.",
				'"PPP paused.",
				'"PPP dropped.",
				'"Terminal AT command mode.",
				'"Firmware update mode.",
				'"Shutting down."

You can download the CR3XX Settings example program that uses these values.

Conclusion

You can monitor and program control functions into your data logger based upon data usage and other values associated with Campbell Scientific's internal and external cellular modems. Options available include: Settings.CellUsageToday, Settings.CellUsageYesterday, Settings.CellUsageMonth, and Settings.CellUsageLastMonth.

Credits: All my code examples are derived from code created by Gary Roberts, Product Manager over communications and software products at Campbell Scientific, Inc.

I hope you found this program example helpful. Try using the code to monitor your data usage, and post a comment below about your experience. Also, post any questions you may have.

Remember: In the next article, we'll explore using serial commands with our external CELL2XX-series modules using the CR800, CR850, CR1000, and CR3000 dataloggers.


Share This Article



About the Author

nathanael wright Nathanael Wright is a Technical Support Engineer at Campbell Scientific, Inc. He provides technical support for data loggers, instruments, and communications equipment. Nathanael has a bachelor's degrees in Computer Information Science and Business Administration, and an MBA. In addition, Nathanael has more than 15 years of experience working in IP communications. Away from work, he enjoys breakdancing, hiking, writing, publishing books, and fiddling with computer equipment.

View all articles by this author.


Comments

PILO | 01/04/2021 at 03:25 PM

Hi, we would want to know of much data is stored per device/sensor??? In order to get a suitable data plan. We will use a cellular modem CELL215 with CR1000X.  Thanks

Nathanael | 01/05/2021 at 04:48 PM

To make a good guess we'll need to know more information. What sensors do you have? How often are you taking readings from each sensor? How often are you downloading files? If you think the 25MB plan might work for you my recommendation is to go with the 250MB plan because the cost difference is so minor and the amount of data available in 10x. Contact us at our support line and we can probably get you an answer a lot quicker. 435.227.9100

Please log in or register to comment.

We're active on social media!
Stay informed with our latest updates by following us on these platforms: